fulmine.distribution.connection.tcp
Class TcpConnectionBroker

java.lang.Object
  extended by fulmine.AbstractLifeCycle
      extended by fulmine.distribution.connection.tcp.TcpConnectionBroker
All Implemented Interfaces:
IConnectionBroker, IDestroyable, ILifeCycle

public final class TcpConnectionBroker
extends AbstractLifeCycle
implements IConnectionBroker

A connection broker implementation based on TCP/IP sockets. This has a single thread that handles input and output. This should be adequate as a context is usually the source or sink of data.

The TCP parameters are controlled by:

Author:
Ramon Servadei

Field Summary
static String CONTEXT_IP_ADDRESS
          The system property for the IP address of the context server socket.
static String CONTEXT_RCV_BUFFER
          The system property for overriding the default receive buffer size for the server port.
static String CONTEXT_TCP_PORT
          The system property for the TCP port
static int DEFAULT_CONTEXT_TCP_PORT
          The default for the TCP port
static String HOST_NAME
          The host name
 
Constructor Summary
TcpConnectionBroker(IFrameworkContext context)
          Default constructor that reads system properties for the IP address and TCP port to use.
TcpConnectionBroker(IFrameworkContext context, String address, int port)
          Construct the TcpConnectionBroker using parameters for the identity, IP address and TCP port.
 
Method Summary
 void connect(IConnectionParameters connectionParameters)
          Connect to the remote context identified in the connection parameters.
protected  void doDestroy()
          Overridden in subclasses to perform custom logic on destruction.
protected  void doStart()
          Overridden in subclasses to perform custom logic on activation.
 String getAddress()
           
protected  AsyncLog getLog()
          Get the log to use for the object hierarchy
 int getPort()
           
 String toString()
           
 
Methods inherited from class fulmine.AbstractLifeCycle
checkActive, destroy, finalize, isActive, start
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fulmine.distribution.connection.IConnectionBroker
start
 
Methods inherited from interface fulmine.ILifeCycle
isActive
 
Methods inherited from interface fulmine.IDestroyable
destroy
 

Field Detail

CONTEXT_IP_ADDRESS

public static final String CONTEXT_IP_ADDRESS
The system property for the IP address of the context server socket. On a multi-homed host, this is useful to control which address the server socket binds to. Use null to accept on all addresses the host uses.

See Also:
Constant Field Values

CONTEXT_TCP_PORT

public static final String CONTEXT_TCP_PORT
The system property for the TCP port

See Also:
Constant Field Values

DEFAULT_CONTEXT_TCP_PORT

public static final int DEFAULT_CONTEXT_TCP_PORT
The default for the TCP port

See Also:
Constant Field Values

CONTEXT_RCV_BUFFER

public static final String CONTEXT_RCV_BUFFER
The system property for overriding the default receive buffer size for the server port. This must be specified in units of bytes.

See Also:
Constant Field Values

HOST_NAME

public static final String HOST_NAME
The host name

Constructor Detail

TcpConnectionBroker

public TcpConnectionBroker(IFrameworkContext context,
                           String address,
                           int port)
Construct the TcpConnectionBroker using parameters for the identity, IP address and TCP port.

Parameters:
context - The context to use when subscribing for events
address - the IP address of the host of this TcpConnectionBroker , null for the host address of the local host
port - the TCP port for thisTcpConnectionBroker, 0 for DEFAULT_CONTEXT_TCP_PORT

TcpConnectionBroker

public TcpConnectionBroker(IFrameworkContext context)
Default constructor that reads system properties for the IP address and TCP port to use.

Parameters:
context - The context to use when subscribing for events
See Also:
CONTEXT_IP_ADDRESS, CONTEXT_TCP_PORT, DEFAULT_CONTEXT_TCP_PORT
Method Detail

getAddress

public String getAddress()

getPort

public int getPort()

doDestroy

protected void doDestroy()
Description copied from class: AbstractLifeCycle
Overridden in subclasses to perform custom logic on destruction. Any exceptions should be thrown as a RuntimeException or subclass thereof.

Specified by:
doDestroy in class AbstractLifeCycle

connect

public void connect(IConnectionParameters connectionParameters)
Description copied from interface: IConnectionBroker
Connect to the remote context identified in the connection parameters. The connection is created asynchronously.

When available, the connection will be encapsulated in a ConnectionAvailableEvent and distributed using the event framework. To receive the connection event, a listener should be registered against the connection event typed source ( IEventManager.getSystemEventSource(Class)).

Specified by:
connect in interface IConnectionBroker
Parameters:
connectionParameters - the parameters for creating the connection

getLog

protected AsyncLog getLog()
Description copied from class: AbstractLifeCycle
Get the log to use for the object hierarchy

Overrides:
getLog in class AbstractLifeCycle
Returns:
the log to use for the object hierarchy

doStart

protected void doStart()
Description copied from class: AbstractLifeCycle
Overridden in subclasses to perform custom logic on activation. Any exceptions should be thrown as a RuntimeException or subclass thereof. When this method is called, the AbstractLifeCycle.isActive() method will return true.

Specified by:
doStart in class AbstractLifeCycle

toString

public String toString()
Overrides:
toString in class AbstractLifeCycle


Copyright © 2007-2009. All Rights Reserved.