fulmine.distribution.connection.tcp
Class TcpConnection

java.lang.Object
  extended by fulmine.AbstractLifeCycle
      extended by fulmine.distribution.connection.tcp.TcpConnectionParameters
          extended by fulmine.distribution.connection.tcp.AbstractSocketChannelConnection
              extended by fulmine.distribution.connection.tcp.TcpConnection
All Implemented Interfaces:
IConnection, IConnectionParameters, IEventSource, IAddressable, IDescriptor, IDestroyable, ILifeCycle, ISelectionKeyTask

public final class TcpConnection
extends AbstractSocketChannelConnection
implements IEventSource, IConnection, ISelectionKeyTask

Handles the socket processing for a single connection to a remote IFrameworkContext.

Received TCP messages from the remote context may be concatenated together; e.g. the remote context sends "conn:lasers" then "syn". These may be received by this connection as a single message "conn:laserssyn". To be able to distinguish these messages, each message is prefixed with the byte length of the application message. This prefix is always 4 bytes, big-endian; e.g. the above example would resolve to "11conn:lasers3syn".

This generates the following events:

When this object is destroyed via the AbstractLifeCycle.destroy() method, this only closes down the TCP IO resources and signals that only when all pending MessageEvents have been processed should this object's IEventSource functions be terminated; this will then remove any IEventListeners that would normally receive messages from this connection.

Author:
Ramon Servadei

Field Summary
 
Fields inherited from class fulmine.distribution.connection.tcp.AbstractSocketChannelConnection
destroyWhenMessagesProcessed, eventSourceDelegate, messagesToProcess
 
Constructor Summary
TcpConnection(IFrameworkContext context, TcpConnectionBroker broker, String remoteContextIdentity, String address, int port, int connectionHashCode)
          Standard constructor
 
Method Summary
protected  void doComponentDestroy()
           
protected  void doDestroy()
          Destroy the internal TCP I/O components.
protected  AsyncLog getLog()
          Get the log to use for the object hierarchy
 SelectionKey getSelectionKey()
           
 void run()
          Run the task associated with the operation and selection key
 void send(byte[] data)
          Add the data to the pending messages list
 void setSelectionKey(SelectionKey selectionKey)
          Receives the selection key returned from the SelectableChannel.register(java.nio.channels.Selector, int) method called during the SelectorTasks.register(int, SelectableChannel, ISelectionKeyTask) method.
 
Methods inherited from class fulmine.distribution.connection.tcp.AbstractSocketChannelConnection
addEvent, addListener, connectionHandshakeComplete, doStart, getContext, getEventSourceGroupId, getListeners, getSocketChannel, isConnected, isConnectionHandshakeComplete, isOutbound, removeListener, removeListeners, toDetailedString, toIdentityString, toString
 
Methods inherited from class fulmine.distribution.connection.tcp.TcpConnectionParameters
equals, getAddress, getDomain, getIdentity, getRemoteContextHashCode, getRemoteContextIdentity, getRemoteHostAddress, getRemoteHostTcpPort, getType, hashCode, isEqual, setIdentity, setRemoteContextHashCode
 
Methods inherited from class fulmine.AbstractLifeCycle
checkActive, destroy, finalize, isActive, start
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fulmine.distribution.connection.IConnection
isOutbound
 
Methods inherited from interface fulmine.distribution.connection.IConnectionParameters
getRemoteContextHashCode, getRemoteContextIdentity, isEqual
 

Constructor Detail

TcpConnection

public TcpConnection(IFrameworkContext context,
                     TcpConnectionBroker broker,
                     String remoteContextIdentity,
                     String address,
                     int port,
                     int connectionHashCode)
Standard constructor

Parameters:
broker - the TcpConnectionBroker
remoteContextIdentity - the identity of the remote context this connection connects to
address - the TCP address of the server port the context exposes to other remote contexts
port - the TCP server port the context exposes to other remote contexts
connectionHashCode - the hashcode of the connection to the remote context
Method Detail

send

public void send(byte[] data)
Add the data to the pending messages list

Specified by:
send in interface IConnection
Parameters:
data - the data to add to the pending messages

run

public void run()
Description copied from interface: ISelectionKeyTask
Run the task associated with the operation and selection key

Specified by:
run in interface ISelectionKeyTask

doDestroy

protected void doDestroy()
Description copied from class: AbstractSocketChannelConnection
Destroy the internal TCP I/O components.

Overrides:
doDestroy in class AbstractSocketChannelConnection

getSelectionKey

public SelectionKey getSelectionKey()

setSelectionKey

public void setSelectionKey(SelectionKey selectionKey)
Description copied from interface: ISelectionKeyTask
Receives the selection key returned from the SelectableChannel.register(java.nio.channels.Selector, int) method called during the SelectorTasks.register(int, SelectableChannel, ISelectionKeyTask) method.

Specified by:
setSelectionKey in interface ISelectionKeyTask
Parameters:
selectionKey - the selection key for this

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

doComponentDestroy

protected void doComponentDestroy()
Overrides:
doComponentDestroy in class AbstractSocketChannelConnection


Copyright © 2007-2009. All Rights Reserved.