eneter.messaging.messagingsystems.composites
Class BufferedMonitoredMessagingFactory

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

public class BufferedMonitoredMessagingFactory
extends java.lang.Object
implements IMessagingSystemFactory

This messaging combines buffered and monitored messaging. Monitored messaging constantly monitors the connection and if the disconnection is detected the buffered messaging is notified. Buffered messaging then tries to reconnect and meanwhile stores all sent messages into a buffer. Once the connection is recovered the messages stored in the buffer are sent.

The buffered monitored messaging is composed from following messagings:

The following example shows how to create BufferedMonitoredMessaging:
 // Create TCP messaging system.
 IMessagingSystemFactory anUnderlyingMessaging = new TcpMessagingSystemFactory();
 
 // Create buffered monitored messaging which takes TCP as underlying messaging.
 IMessagingSystemFactory aMessaging = new BufferedMonitoredMessagingFactory(anUnderlyingMessaging);
 
 // Then creating channels which can be then attached to communication components.
 IDuplexInputChannel anInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:8095/");
 IDuplexInputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:8095/");
 
 


Constructor Summary
BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging)
          Constructs the factory with default settings.
BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging, long maxOfflineTime, long pingFrequency, long pingResponseTimeout)
          Constructs the factory with the specified parameters.
 
Method Summary
 IDuplexInputChannel createDuplexInputChannel(java.lang.String channelId)
          Creates the input channel which can receive and send messages.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
          Creates the output channel which can send and receive messages.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId, java.lang.String responseReceiverId)
          Creates the output channel which can send and receive messages.
 BufferedMessagingFactory getBufferedMessaging()
          Returns underlying buffered messaging.
 MonitoredMessagingFactory getMonitoredMessaging()
          Returns underlying monitored messaging.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedMonitoredMessagingFactory

public BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging)
Constructs the factory with default settings. The maximum offline time for buffered messaging is set to 10 seconds. The ping frequency for monitored messaging is set to 1 second and the receive timeout for monitored messaging is set to 2 seconds.

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

BufferedMonitoredMessagingFactory

public BufferedMonitoredMessagingFactory(IMessagingSystemFactory underlyingMessaging,
                                         long maxOfflineTime,
                                         long pingFrequency,
                                         long pingResponseTimeout)
Constructs the factory with the specified parameters.

Parameters:
underlyingMessaging - underlying messaging system e.g. TCP, ...
maxOfflineTime - the maximum time, the messaging can work offline. When the messaging works offline, the sent messages are buffered and the connection is being reopened. If the connection is not reopen within maxOfflineTime, the connection is closed.
pingFrequency - how often the connection is checked with the 'ping' requests.
pingResponseTimeout - the maximum time, the response for the 'ping' is expected.
Method Detail

createDuplexOutputChannel

public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
                                               throws java.lang.Exception
Creates the output channel which can send and receive messages. This duplex output channel provides the buffered messaging and the connection monitoring. It regularly checks if the connection is available. It sends 'ping' requests and expects 'ping' responses within the specified time. If the 'ping' response does not come the disconnection is notified to the buffered messaging. The buffered messaging then tries to reconnect and meanwhile stores the sent messages to the buffer. Once the connection is recovered the messages stored in the buffer are sent. If the connection recovery was not possible the event IDuplexOutputChannel.connectionClosed() is raised the message buffer is deleted.

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 and receive messages. This duplex output channel provides the buffered messaging and the connection monitoring. It regularly checks if the connection is available. It sends 'ping' requests and expects 'ping' responses within the specified time. If the 'ping' response does not come the disconnection is notified to the buffered messaging. The buffered messaging then tries to reconnect and meanwhile stores the sent messages to the buffer. Once the connection is recovered the messages stored in the buffer are sent. If the connection recovery was not possible the event IDuplexOutputChannel.connectionClosed() is raised the message buffer is deleted.

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 and send messages. This duplex input channel provides the buffered messaging and the connection monitoring. It regularly checks if the duplex output channel is still connected. It expect, that every connected duplex output channel sends regularly 'ping' messages. If the 'ping' message from the duplex output channel is not received within the specified time the duplex output channel is disconnected and the buffered messaging is notified about the disconnection. The buffered messaging then puts all sent response messages to the buffer and waits whether the duplex output channel reconnects. If the duplex output channel reopens the connection the messages stored in the buffer are sent. If the duplex output channel does not reconnect the event IDuplexInputChannel.responseReceiverDisconnected() is raised 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

getBufferedMessaging

public BufferedMessagingFactory getBufferedMessaging()
Returns underlying buffered messaging.

Returns:
buffered messaging

getMonitoredMessaging

public MonitoredMessagingFactory getMonitoredMessaging()
Returns underlying monitored messaging.

Returns:
monitored messaging