Message Exchange

package ''org.objectweb.petals.jbi.messaging''

The MessageExchange represents the life cycle of a message exchange between a consumer and a provider. It is created and initialized by a MessageExchangeFactory.

It manages the state of the exchange during it's whole life (status, owner of the exchange,...).

The MessageExchange is shared by the consumer and the provider component. Each component send it to the other one throught the DeliveryChannel.

Implementation

The MessageExchange concept is implemented by two classes:

  • MessageExchangeImpl, which contains the state and properties of the message exchange,
  • MessageEchangeDecorator, which is the view of the exchange for a component, and which encapsulate the MsgExchImpl object. It checks the validity of the role of the component in the exchange and the "owner" of the component.
So, the components interact with MessageExchangeDecorator objects, and the container interacts directly with the MessageExchangeImpl object.

Notes that the MessageExchangeImpl knows its consumer-decorator and its provider-decorator.

messageExchange.png

Exchange

Initiates a message

When a consumer initiates a message exchange, it asks the MessageExchangeFactory to create a MessageExchange. This factory creates a MessageExchangeImpl set to 'consumer owner', and a MessageExchangeDecorator that encapsulates it and which is set to 'consumer'. The factory return the MessageExchangeDecorator to the consumer.

Consumer point of view

When the consuler manipulates the 'MessageExchange', it calls methods on the decorator. The decorator, parametrized as a 'consumer view' check that the exchange is in a 'consumer owner' Role. If it is asserted, it calls the real method on the MessageExchangeImpl object. Otherwise, an illegalState exception is thrown.

The consumer sends a message

When a message exchange is sent to a provider the consumer's deliveryChannel send the real MessageExchangeImpl to the provider's deliveryChannel.

It set the 'owner' role to 'provider'.

Asynchronous send (normal way)

No other actions are perfomed for a standard send.

Synchronous send

We are in the case where the consumer wants to wait for a response for the exchange. So, the sendSync() method blocks (wait) on the consumer's decoratorExchMsg.

When the method is unblocked, the consumer can read the response directly on the decoratorexchMsg

The Provider receives a message

When the object is pushed to the provider's deliveryChannel, the deliveryChannel checks that the messageExchangeImpl has already a provider-decoratorExchMsg that is set and which is blocked on a 'sendSync()'.

Asynchronous send (normal way)

The deliveryChannel creates a decoratorExchMsg and affects it to the MessageExchangeImpl.

Then, it pushes this decoratorExchMsg object into the provider's messages queue.

Synchronous send

We are in the case where the provider previously made a 'sendSync()' call, and is now waiting for a response on its decoratorExchMsg.

So, the messageExchangeImpl has already a provider-decoratorExchMsg that is set and which is blocked on a 'sendSync()'

The deliveryChannel just unblocks the 'sendSync()', and the provider can directly read the response on its decoratorExchMsg that it previously sent.

Provider point of view

When the consuler manipulates the 'MessageExchange', it calls methods on the decorator. The decorator, parametrized as a 'provider view' check that the exchange is in a 'provider owner' Role. If it is asserted, it calls the real method on the MessageExchangeImpl object. Otherwise, an illegalState exception is thrown.

The provider sends a the response

When the provider answers, it set its response on the decoratorExchMsg MessageExchangea message exchange is sent to a provider the consumer's deliveryChannel sethat it recevied, and send this one to its deliveryChannel.

The deliveryChannel set the 'owner' role to 'consumer'.

Asynchronous send (normal way)

No other actions are perfomed for a standard send.

Synchronous send

We are in the case where the provider wants to wait for a response for its response (an acknowlegement, typically).

So, the sendSync() method blocks (wait) on the provider's decoratorExchMsg.

Ameliorations

The management of the synchronous send is okay for a centralized container. in a distributed approach, the link between a MsgExchangeImpl (the object which is send), and its decorators can not be an object reference.