eneter.messaging.messagingsystems.tcpmessagingsystem
Class TcpMessagingSystemFactory

java.lang.Object
  extended by eneter.messaging.messagingsystems.tcpmessagingsystem.TcpMessagingSystemFactory
All Implemented Interfaces:
IMessagingSystemFactory

public class TcpMessagingSystemFactory
extends java.lang.Object
implements IMessagingSystemFactory

Messaging system delivering messages via TCP. It creates the communication channels which use TCP for sending and receiving messages. The channel id must be a valid URI address. E.g.: tcp://127.0.0.1:6080/.

Creating input channel for TCP messaging.

 
 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 
 // Create duplex input channel which can receive messages on the address 127.0.0.1 and the port 9043
 // and which can send response messages to connected output channels.
 IDuplexInputChannel anInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:9043/");
 
 // Subscribe to handle messages.
 anInputChannel.messageReceived().subscribe(myOnMessageReceived);
 
 // Start listening and be able to receive messages.
 anInputChannel.startListening();
 
 ...
 
 // Stop listening.
 anInputChannel.stopListeing();
 
 
Creating output channel for TCP messaging.
 
 // Create duplex output channel which can send messages to 127.0.0.1 on the port 9043 and
 // receive response messages.
 IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:9043/");
 
 // Subscribe to handle messages.
 anOutputChannel.responseMessageReceived().subscribe(myOnMessageReceived);
 
 // Open connection to the input channel which listens to tcp://127.0.0.1:9043/.
 anOutputChannel.openConnection();
 
 ...
 
 // Close connection.
 anOutputChannel.closeConnection();
 
 


Constructor Summary
TcpMessagingSystemFactory()
          Constructs the TCP messaging factory.
TcpMessagingSystemFactory(IProtocolFormatter protocolFormatter)
          Constructs the TCP messaging factory.
 
Method Summary
 IDuplexInputChannel createDuplexInputChannel(java.lang.String channelId)
          Creates the duplex input channel which can receive and send messages to the duplex output channel using TCP.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
          Creates duplex output channel which can send and receive messages from the duplex input channel using TCP.
 IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId, java.lang.String responseReceiverId)
          Creates duplex output channel which can send and receive messages from the duplex input channel using TCP.
static java.lang.String[] getAvailableIpAddresses()
          Returns IP addresses assigned to the device which can be used for the listening.
 IClientSecurityFactory getClientSecurity()
          Gets the factory that is used for creation of client sockets.
 IThreadDispatcherProvider getInputChannelThreading()
          Gets threading mode used for input channels.
 IThreadDispatcherProvider getOutputChannelThreading()
          Gets threading mode used for output channels.
 IServerSecurityFactory getServerSecurity()
          Gets the factory that is used for creation of server sockets.
 TcpMessagingSystemFactory setClientSecurity(IClientSecurityFactory clientSecurityFactory)
          Sets the factory that will be used for creation of secured client socket.
 TcpMessagingSystemFactory setInputChannelThreading(IThreadDispatcherProvider inputChannelThreading)
          Sets threading mode for input channels.
 TcpMessagingSystemFactory setOutputChannelThreading(IThreadDispatcherProvider outputChannelThreading)
          Sets threading mode for output channels.
 TcpMessagingSystemFactory setServerSecurity(IServerSecurityFactory serverSecurityFactory)
          Sets the factory that will be used for creation of server sockets.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpMessagingSystemFactory

public TcpMessagingSystemFactory()
Constructs the TCP messaging factory.


TcpMessagingSystemFactory

public TcpMessagingSystemFactory(IProtocolFormatter protocolFormatter)
Constructs the TCP messaging factory.

Parameters:
protocolFormatter - formats OpenConnection, CloseConnection and Message messages between channels.
Method Detail

createDuplexOutputChannel

public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId)
                                               throws java.lang.Exception
Creates duplex output channel which can send and receive messages from the duplex input channel using TCP. Creating the duplex output channel.

 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:8765/");
 

Specified by:
createDuplexOutputChannel in interface IMessagingSystemFactory
Parameters:
channelId - Identifies the receiving duplex input channel. The channel id must be a valid URI address e.g. tcp://127.0.0.1:8090/
Returns:
output channel
Throws:
java.lang.Exception

createDuplexOutputChannel

public IDuplexOutputChannel createDuplexOutputChannel(java.lang.String channelId,
                                                      java.lang.String responseReceiverId)
                                               throws java.lang.Exception
Creates duplex output channel which can send and receive messages from the duplex input channel using TCP.
Creating the duplex output channel with specified client id.
 
 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 IDuplexOutputChannel anOutputChannel = aMessaging.createDuplexOutputChannel("tcp://127.0.0.1:8765/", "MyUniqueClientId_1");
 
 

Specified by:
createDuplexOutputChannel in interface IMessagingSystemFactory
Parameters:
channelId - Identifies the input channel which shall be connected. The channel id must be a valid URI address e.g. tcp://127.0.0.1:8090/
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 duplex input channel which can receive and send messages to the duplex output channel using TCP.
Creating duplex input channel.
 
 IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
 IDuplexInputChannel anInputChannel = aMessaging.createDuplexInputChannel("tcp://127.0.0.1:9876/");
 
 

Specified by:
createDuplexInputChannel in interface IMessagingSystemFactory
Parameters:
channelId - The IP address and port which shall be used for listening. The channel id must be a valid URI address (e.g. tcp://127.0.0.1:8090/).
If the IP address is 0.0.0.0 then it will listen to all available IP addresses. E.g. if the address is tcp://0.0.0.0:8033/ then it will listen to all available IP addresses on the port 8033.
Returns:
input channel
Throws:
java.lang.Exception

getAvailableIpAddresses

public static java.lang.String[] getAvailableIpAddresses()
                                                  throws java.net.SocketException
Returns IP addresses assigned to the device which can be used for the listening.

Returns:
IP addresses which can be used for the listening.
Throws:
java.net.SocketException

setServerSecurity

public TcpMessagingSystemFactory setServerSecurity(IServerSecurityFactory serverSecurityFactory)
Sets the factory that will be used for creation of server sockets. Except security (e.g. using encrypted SSL communication) the factory also allows to specify other communication parameters e.g. timeouts, buffers, etc.

Parameters:
serverSecurityFactory -

getServerSecurity

public IServerSecurityFactory getServerSecurity()
Gets the factory that is used for creation of server sockets. Except security (e.g. using encrypted SSL communication) the factory also allows to specify other communication parameters e.g. timeouts, buffers, etc.

Returns:

setClientSecurity

public TcpMessagingSystemFactory setClientSecurity(IClientSecurityFactory clientSecurityFactory)
Sets the factory that will be used for creation of secured client socket. Except security (e.g. using encrypted SSL communication) the factory also allows to specify other communication parameters e.g. timeouts, buffers, etc.

Parameters:
clientSecurityFactory -

getClientSecurity

public IClientSecurityFactory getClientSecurity()
Gets the factory that is used for creation of client sockets. Except security (e.g. using encrypted SSL communication) the factory also allows to specify other communication parameters e.g. timeouts, buffers, etc.

Returns:
client socket factory

setInputChannelThreading

public TcpMessagingSystemFactory setInputChannelThreading(IThreadDispatcherProvider inputChannelThreading)
Sets threading mode for input channels.

Parameters:
inputChannelThreading - threading model
Returns:
this TcpMessagingSystemFactory

getInputChannelThreading

public IThreadDispatcherProvider getInputChannelThreading()
Gets threading mode used for input channels.

Returns:
thread dispatcher

setOutputChannelThreading

public TcpMessagingSystemFactory setOutputChannelThreading(IThreadDispatcherProvider outputChannelThreading)
Sets threading mode for output channels.

Parameters:
outputChannelThreading -
Returns:
this TcpMessagingSystemFactory

getOutputChannelThreading

public IThreadDispatcherProvider getOutputChannelThreading()
Gets threading mode used for output channels.

Returns:
thread dispatcher