org.objectweb.dream.protocol.channel
Class TCPIPProtocolImpl

java.lang.Object
  extended by org.objectweb.dream.AbstractComponent
      extended by org.objectweb.dream.protocol.channel.TCPIPProtocolImpl
All Implemented Interfaces:
ContextualBindingController, NeedAsyncStartController, PrepareStopLifeCycleController, Loggable, ChannelProtocol, ConnectionManager, TCPIPProtocol, TCPIPProtocolAttributeController, Protocol, AttributeController, BindingController, LifeCycleController

public class TCPIPProtocolImpl
extends AbstractComponent
implements TCPIPProtocolAttributeController, TCPIPProtocol, ConnectionManager

Implementation of the TCP/IP protocol.


Nested Class Summary
protected  class TCPIPProtocolImpl.ReaderTask
           
protected  class TCPIPProtocolImpl.Session
           
 
Field Summary
protected static String BIND_REPLY_CHUNK_NAME
           
protected  ConnectionFactory connectionFactoryItf
           
protected  int connectionRetry
           
protected  ChunkFactoryReference<ExceptionChunk> exceptionChunkFactory
           
protected  Map<IPExportIdentifier,ChannelFactory> exportedChanels
           
protected  TCPIPProtocolImpl.Session firstAvailable
           
protected static String hostName
           
protected  TCPIPProtocolImpl.Session lastAvailable
           
protected  MessageCodec messageCodecItf
           
protected  MessageManager messageManagerItf
           
protected  int port
           
protected  TCPIPProtocolImpl.ReaderTask readerTask
           
protected  Set<TCPIPProtocolImpl.Session> sessions
           
protected  int soLinger
           
protected  int soTimeout
           
protected  boolean tcpNoDelay
           
protected  ThreadPoolManager threadPoolManager
           
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, fcNeedAsyncStart, fcState, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.dream.protocol.channel.TCPIPProtocolAttributeController
CONNECTION_RETRY_DEFAULT
 
Fields inherited from interface org.objectweb.dream.protocol.channel.TCPIPProtocol
ADDRESS, CONNECTION_RETRY, PORT, PORT_RANGE, SO_LINGER, SO_TIMEOUT, TCP_NO_DELAY
 
Fields inherited from interface org.objectweb.dream.protocol.Protocol
ITF_NAME, LOWER_PROTOCOL_ITF_NAME
 
Fields inherited from interface org.objectweb.dream.protocol.channel.ConnectionManager
ITF_NAME
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Constructor Summary
TCPIPProtocolImpl()
           
 
Method Summary
protected  void beforeFirstStart(Component componentItf)
           
 OutgoingPush bind(ExportIdentifier exportId, IncomingPush toClientPush, Map<String,Object> hints)
          Binds to a previously exported ChannelFactory interface designated by the given export identifier.
 OutgoingPush bind(String hostName, int port, IncomingPush toClientPush)
          Utility method.
 void bindFc(String clientItfName, Object serverItf)
           
protected  Socket createConnection(IPExportIdentifier exportIdentifier)
           
 ExportIdentifier createExportIdentifier(Map<String,Object> info, ExportIdentifier[] next)
          Creates a new export identifier with the provided info
 IPExportIdentifier createExportIdentifier(String hostName, int port)
          Utility method.
 IPExportIdentifier export(ChannelFactory channel, int port, int range)
          Utility method.
 ExportIdentifier export(ChannelFactory channel, Map<String,Object> hints)
          Exports a ChannelFactory interface using this protocol.
protected  TCPIPProtocolImpl.Session getAvailable()
           
 int getConnectionRetry()
          Returns the default value of the TCPIPProtocol.CONNECTION_RETRY hint.
 int getPort()
          Returns the default value of the TCPIPProtocol.PORT hint.
 int getSoLinger()
          Returns the default value of the TCPIPProtocol.SO_LINGER hint.
 int getSoTimeout()
          Returns the default value of the TCPIPProtocol.SO_TIMEOUT hint.
 boolean getTcpNoDelay()
          Returns the default value of the TCPIPProtocol.TCP_NO_DELAY hint.
protected  TCPIPProtocolImpl.Session initSession(TCPIPProtocolImpl.Session session, IncomingPush incomingPush)
           
 String[] listFc()
           
 void newConnection(Socket socket, IPExportIdentifier identifier)
          Informs the protocol component that a new connection has been opened.
 void prepareStopFc()
           
protected  void sessionError(TCPIPProtocolImpl.Session session, Exception exception)
           
protected  void setAvailable(TCPIPProtocolImpl.Session session)
           
 void setConnectionRetry(int connectionRetry)
          Sets the default value of the TCPIPProtocol.CONNECTION_RETRY hint.
 void setPort(int port)
          Sets the default value of the TCPIPProtocol.PORT hint.
protected  void setSocketOption(Socket sock)
           
 void setSoLinger(int timeout)
          Sets the default value of the TCPIPProtocol.SO_LINGER hint.
 void setSoTimeout(int timeout)
          Sets the default value of the TCPIPProtocol.SO_TIMEOUT hint.
 void setTcpNoDelay(boolean tcpNoDelay)
          Sets the default value of the TCPIPProtocol.TCP_NO_DELAY hint.
protected  void setThreadPoolManager(ThreadPoolManager threadPoolManager)
           
protected  void silentClose(Socket socket)
           
protected  void silentClose(TCPIPProtocolImpl.Session session)
           
 void unexport(ExportIdentifier exportIdentifier)
          Closes the export of a previously exported ChannelFactory interface.
 
Methods inherited from class org.objectweb.dream.AbstractComponent
bindFc, getFcNeedAsyncStart, getFcState, initComponent, lookupFc, setLogger, startFc, stopFc, unbindFc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIND_REPLY_CHUNK_NAME

protected static final String BIND_REPLY_CHUNK_NAME
See Also:
Constant Field Values

hostName

protected static String hostName

exceptionChunkFactory

protected ChunkFactoryReference<ExceptionChunk> exceptionChunkFactory

sessions

protected Set<TCPIPProtocolImpl.Session> sessions

firstAvailable

protected TCPIPProtocolImpl.Session firstAvailable

lastAvailable

protected TCPIPProtocolImpl.Session lastAvailable

threadPoolManager

protected ThreadPoolManager threadPoolManager

readerTask

protected TCPIPProtocolImpl.ReaderTask readerTask

exportedChanels

protected Map<IPExportIdentifier,ChannelFactory> exportedChanels

port

protected int port

connectionRetry

protected int connectionRetry

tcpNoDelay

protected boolean tcpNoDelay

soTimeout

protected int soTimeout

soLinger

protected int soLinger

connectionFactoryItf

protected ConnectionFactory connectionFactoryItf

messageManagerItf

protected MessageManager messageManagerItf

messageCodecItf

protected MessageCodec messageCodecItf
Constructor Detail

TCPIPProtocolImpl

public TCPIPProtocolImpl()
Method Detail

export

public ExportIdentifier export(ChannelFactory channel,
                               Map<String,Object> hints)
                        throws ExportException
Description copied from interface: ChannelProtocol
Exports a ChannelFactory interface using this protocol. This method informs the protocol that the provided ChannelFactory is willing to accept connection. The returned export identifier is a specific name for the exported channel.

Specified by:
export in interface ChannelProtocol
Parameters:
channel - a ChannelFactory interface to export.
hints - additional parameters, can be null.
Returns:
an identifier for the exported interface.
Throws:
ExportException - if the export process fails.
See Also:
ChannelProtocol.export(ChannelFactory, Map)

unexport

public void unexport(ExportIdentifier exportIdentifier)
              throws InvalidExportIdentifierException
Description copied from interface: ChannelProtocol
Closes the export of a previously exported ChannelFactory interface. This methods do not close communication channels created by the exported channel factory.

Specified by:
unexport in interface ChannelProtocol
Parameters:
exportIdentifier - the export identifier of the channel.
Throws:
InvalidExportIdentifierException - if the given export identifier is incorrect.
See Also:
ChannelProtocol.unexport(ExportIdentifier)

bind

public OutgoingPush bind(ExportIdentifier exportId,
                         IncomingPush toClientPush,
                         Map<String,Object> hints)
                  throws InvalidExportIdentifierException,
                         BindException
Description copied from interface: ChannelProtocol
Binds to a previously exported ChannelFactory interface designated by the given export identifier. This methods instantiate a new communication channel and returns an interface on which messages can be sent to the server. In addition the toClientPush interface is the interface on which the client want to receive messages from the server.

Specified by:
bind in interface ChannelProtocol
Parameters:
exportId - the identifier of the exported interface.
toClientPush - the interface on which the client want to receive messages from the server, may be null if no messages are expected from the server.
hints - additional parameters, can be null.
Returns:
a OutgoingPush interface on which message can be send over the new communication channel.
Throws:
InvalidExportIdentifierException - if the given export identifier is incorrect.
BindException - if the binding process fails.
See Also:
ChannelProtocol.bind(ExportIdentifier, IncomingPush, Map)

createExportIdentifier

public ExportIdentifier createExportIdentifier(Map<String,Object> info,
                                               ExportIdentifier[] next)
                                        throws InvalidExportIdentifierException
Description copied from interface: Protocol
Creates a new export identifier with the provided info

Specified by:
createExportIdentifier in interface Protocol
Parameters:
info - the info used to create the export identifier.
next - the export identifier of the lower level protocols.
Returns:
a new export identifier.
Throws:
InvalidExportIdentifierException - if the export identifier can't be created.
See Also:
Protocol.createExportIdentifier(Map, ExportIdentifier[])

export

public IPExportIdentifier export(ChannelFactory channel,
                                 int port,
                                 int range)
                          throws ExportException
Description copied from interface: TCPIPProtocol
Utility method. Exports the channel through the given port.

Specified by:
export in interface TCPIPProtocol
Parameters:
channel - the channel to export
port - the listening port on which the TCP/IP protocol will wait incoming connection for an exported channel.
If null, the current listening port of the protocol is used.
range - the range of listening ports on which the TCP/IP protocol will try to open server socket.
If null, only one port will be tried before aborting. If negative, range is infinite.
Returns:
An export identifier.
Throws:
ExportException - if the export process fails.
See Also:
TCPIPProtocol.export(ChannelFactory, int, int)

bind

public OutgoingPush bind(String hostName,
                         int port,
                         IncomingPush toClientPush)
                  throws InvalidExportIdentifierException,
                         BindException
Description copied from interface: TCPIPProtocol
Utility method.

Specified by:
bind in interface TCPIPProtocol
Throws:
InvalidExportIdentifierException
BindException
See Also:
TCPIPProtocol.bind(String, int, IncomingPush)

createExportIdentifier

public IPExportIdentifier createExportIdentifier(String hostName,
                                                 int port)
Description copied from interface: TCPIPProtocol
Utility method.

Specified by:
createExportIdentifier in interface TCPIPProtocol
See Also:
TCPIPProtocol.createExportIdentifier(String, int)

newConnection

public void newConnection(Socket socket,
                          IPExportIdentifier identifier)
Description copied from interface: ConnectionManager
Informs the protocol component that a new connection has been opened.

Specified by:
newConnection in interface ConnectionManager
Parameters:
socket - the new connection.
identifier - the identifier of the server socket on which the new connection has been established.
See Also:
ConnectionManager.newConnection(Socket, IPExportIdentifier)

silentClose

protected final void silentClose(TCPIPProtocolImpl.Session session)

silentClose

protected final void silentClose(Socket socket)

setAvailable

protected void setAvailable(TCPIPProtocolImpl.Session session)

getAvailable

protected TCPIPProtocolImpl.Session getAvailable()

initSession

protected TCPIPProtocolImpl.Session initSession(TCPIPProtocolImpl.Session session,
                                                IncomingPush incomingPush)

setThreadPoolManager

protected void setThreadPoolManager(ThreadPoolManager threadPoolManager)

sessionError

protected void sessionError(TCPIPProtocolImpl.Session session,
                            Exception exception)

createConnection

protected Socket createConnection(IPExportIdentifier exportIdentifier)
                           throws IOException
Throws:
IOException

setSocketOption

protected void setSocketOption(Socket sock)
                        throws IOException
Throws:
IOException

beforeFirstStart

protected void beforeFirstStart(Component componentItf)
                         throws IllegalLifeCycleException
Overrides:
beforeFirstStart in class AbstractComponent
Throws:
IllegalLifeCycleException
See Also:
AbstractComponent.beforeFirstStart(Component)

prepareStopFc

public void prepareStopFc()
                   throws IllegalLifeCycleException
Specified by:
prepareStopFc in interface PrepareStopLifeCycleController
Overrides:
prepareStopFc in class AbstractComponent
Throws:
IllegalLifeCycleException
See Also:
PrepareStopLifeCycleController.prepareStopFc()

getPort

public int getPort()
Description copied from interface: TCPIPProtocolAttributeController
Returns the default value of the TCPIPProtocol.PORT hint.

Specified by:
getPort in interface TCPIPProtocolAttributeController
Returns:
the port attribute's value.
See Also:
TCPIPProtocolAttributeController.getPort()

setPort

public void setPort(int port)
Description copied from interface: TCPIPProtocolAttributeController
Sets the default value of the TCPIPProtocol.PORT hint.

Specified by:
setPort in interface TCPIPProtocolAttributeController
Parameters:
port - the new port attribute's value.
See Also:
TCPIPProtocolAttributeController.setPort(int)

getConnectionRetry

public int getConnectionRetry()
Description copied from interface: TCPIPProtocolAttributeController
Returns the default value of the TCPIPProtocol.CONNECTION_RETRY hint.

Specified by:
getConnectionRetry in interface TCPIPProtocolAttributeController
Returns:
TCPIPProtocolAttributeController.CONNECTION_RETRY_DEFAULT by default, or the value set by TCPIPProtocolAttributeController.setConnectionRetry(int).
See Also:
TCPIPProtocolAttributeController.getConnectionRetry()

setConnectionRetry

public void setConnectionRetry(int connectionRetry)
Description copied from interface: TCPIPProtocolAttributeController
Sets the default value of the TCPIPProtocol.CONNECTION_RETRY hint.

Specified by:
setConnectionRetry in interface TCPIPProtocolAttributeController
Parameters:
connectionRetry - the new connectionRetry attribute's value.
See Also:
TCPIPProtocolAttributeController.setConnectionRetry(int)

getSoLinger

public int getSoLinger()
Description copied from interface: TCPIPProtocolAttributeController
Returns the default value of the TCPIPProtocol.SO_LINGER hint.

Specified by:
getSoLinger in interface TCPIPProtocolAttributeController
Returns:
the soLinger attribute's value.
See Also:
TCPIPProtocolAttributeController.getSoLinger()

setSoLinger

public void setSoLinger(int timeout)
Description copied from interface: TCPIPProtocolAttributeController
Sets the default value of the TCPIPProtocol.SO_LINGER hint.

Specified by:
setSoLinger in interface TCPIPProtocolAttributeController
Parameters:
timeout - the new soLinger attribute's value.
See Also:
TCPIPProtocolAttributeController.setSoLinger(int)

getSoTimeout

public int getSoTimeout()
Description copied from interface: TCPIPProtocolAttributeController
Returns the default value of the TCPIPProtocol.SO_TIMEOUT hint.

Specified by:
getSoTimeout in interface TCPIPProtocolAttributeController
Returns:
the soTimeout attribute's value.
See Also:
TCPIPProtocolAttributeController.getSoTimeout()

setSoTimeout

public void setSoTimeout(int timeout)
Description copied from interface: TCPIPProtocolAttributeController
Sets the default value of the TCPIPProtocol.SO_TIMEOUT hint.

Specified by:
setSoTimeout in interface TCPIPProtocolAttributeController
Parameters:
timeout - the new soTimeout attribute's value.
See Also:
TCPIPProtocolAttributeController.setSoTimeout(int)

getTcpNoDelay

public boolean getTcpNoDelay()
Description copied from interface: TCPIPProtocolAttributeController
Returns the default value of the TCPIPProtocol.TCP_NO_DELAY hint.

Specified by:
getTcpNoDelay in interface TCPIPProtocolAttributeController
Returns:
the tcpNoDelay attribute's value.
See Also:
TCPIPProtocolAttributeController.getTcpNoDelay()

setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)
Description copied from interface: TCPIPProtocolAttributeController
Sets the default value of the TCPIPProtocol.TCP_NO_DELAY hint.

Specified by:
setTcpNoDelay in interface TCPIPProtocolAttributeController
Parameters:
tcpNoDelay - the new tcpNoDelay attribute's value.
See Also:
TCPIPProtocolAttributeController.setTcpNoDelay(boolean)

listFc

public String[] listFc()
Specified by:
listFc in interface BindingController
See Also:
BindingController.listFc()

bindFc

public void bindFc(String clientItfName,
                   Object serverItf)
            throws NoSuchInterfaceException,
                   IllegalBindingException,
                   IllegalLifeCycleException
Specified by:
bindFc in interface BindingController
Overrides:
bindFc in class AbstractComponent
Throws:
NoSuchInterfaceException
IllegalBindingException
IllegalLifeCycleException
See Also:
BindingController.bindFc(String, Object)


Copyright © 2003, 2005 - INRIA Rhone-Alpes - All Rights Reserved.