eneter.messaging.messagingsystems.composites.bufferedmessagingcomposit
Class BufferedMessagingFactory

java.lang.Object
  extended by eneter.messaging.messagingsystems.composites.bufferedmessagingcomposit.BufferedMessagingFactory
All Implemented Interfaces:
IMessagingSystemFactory

public class BufferedMessagingFactory
extends java.lang.Object
implements IMessagingSystemFactory

Extension allowing to work offline until the connection is available. The buffered messaging is intended to overcome relatively short time intervals when the connection is not available. It means the buffered messaging is able to hide unavailable connection and work offline while trying to reconnect.
If the connection is not available, the buffered messaging stores sent messages (and sent response messages) in the buffer and sends them when the connection is established.
Note:
The buffered messaging does not require that both communicating parts create channels with buffered messaging factory. It means, e.g. the duplex output channel created with buffered messaging with underlying TCP, can send messages directly to the duplex input channel created with just TCP messaging factory.

The following example shows how to use buffered messaging e.g. if the connection can get temporarily lost:

 // Create TCP messaging.
 IMessagingSystemFactory anUnderlyingMessaging = new TcpMessagingSystemFactory();
 
// Create buffered messaging that internally uses TCP. IMessagingSystemFactory aMessaging = new BufferedMessagingSystemFactory(anUnderlyingMessaging);
// Create the duplex output channel. IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:8045/");
// Create message sender to send simple string messages. IDuplexStringMessagesFactory aSenderFactory = new DuplexStringMessagesFactory(); IDuplexStringMessageSender aSender = aSenderFactory.CreateDuplexStringMessageSender();
// Subscribe to receive responses. aSender.responseReceived().subscribe(myOnResponseReceived);
// Attach output channel an be able to send messages and receive responses. aSender.attachDuplexOutputChannel(anOutputChannel);
...
// Send a message. // If the connection is broken the message will be stored in the buffer. // Note: The buffered messaging will try to reconnect automatically. aSender.SendMessage("Hello.");


Constructor Summary
BufferedMessagingFactory(IMessagingSystemFactory underlyingMessaging)
          Constructs the factory with default parameters.
BufferedMessagingFactory(IMessagingSystemFactory underlyingMessaging, long maxOfflineTime)
          Constructs the factory from the specified parameters.
 
Method Summary
 IDuplexInputChannel createDuplexInputChannel(java.lang.String channelId)
          Creates the input channel which can receive messages from the output channel and send response messages.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
          Creates the output channel which can send messages to the input channel and receive response messages.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId, java.lang.String responseReceiverId)
          Creates the output channel which can send messages to the input channel and receive response messages.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedMessagingFactory

public BufferedMessagingFactory(IMessagingSystemFactory underlyingMessaging)
Constructs the factory with default parameters. The maximum offline time will be set to 10 seconds.

Parameters:
underlyingMessaging - underlying messaging system e.g. Websocket, TCP, ...

BufferedMessagingFactory

public BufferedMessagingFactory(IMessagingSystemFactory underlyingMessaging,
                                long maxOfflineTime)
Constructs the factory from the specified parameters.

Parameters:
underlyingMessaging - underlying messaging system e.g. Websocket, TCP, ...
maxOfflineTime - the max time (in milliseconds), the communicating applications can be disconnected.
Method Detail

createDuplexOutputChannel

public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
                                               throws java.lang.Exception
Creates the output channel which can send messages to the input channel and receive response messages. If the connection is not available it puts sent messages to the buffer while trying to reconnect. Then when the connection is established the messages are sent from the buffer. If the reconnect is not successful within the maximum offline time it notifies IDuplexOutputChannel.connectionClosed() and messages are deleted from the buffer.

Specified by:
createDuplexOutputChannel in interface IMessagingSystemFactory
Parameters:
channelId - address of the input channel.
Returns:
output channel
Throws:
java.lang.Exception

createDuplexOutputChannel

public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId,
                                                      java.lang.String responseReceiverId)
                                               throws java.lang.Exception
Creates the output channel which can send messages to the input channel and receive response messages. If the connection is not available it puts sent messages to the buffer while trying to reconnect. Then when the connection is established the messages are sent from the buffer. If the reconnect is not successful within the maximum offline time it notifies IDuplexOutputChannel.connectionClosed() and messages are deleted from the buffer.

Specified by:
createDuplexOutputChannel in interface IMessagingSystemFactory
Parameters:
channelId - address of the input channel.
responseReceiverId - unique identifier of the output channel. If the value is null then the identifier is genearated automatically
Returns:
duplex output channel
Throws:
java.lang.Exception

createDuplexInputChannel

public IDuplexInputChannel createDuplexInputChannel(java.lang.String channelId)
                                             throws java.lang.Exception
Creates the input channel which can receive messages from the output channel and send response messages. If the connection with the duplex output channel is not established, it puts sent response messages to the buffer. Then, when the duplex input channel is connected, the response messages are sent. If the duplex output channel does not connect within the specified maximum offline time, the event IDuplexInputChannel.responseReceiverDisconnected() is invoked and response messages are deleted from the buffer.

Specified by:
createDuplexInputChannel in interface IMessagingSystemFactory
Parameters:
channelId - address of the input channel.
Returns:
input channel
Throws:
java.lang.Exception