org.springframework.integration.ip.tcp.connection
Class AbstractTcpConnection

java.lang.Object
  extended by org.springframework.integration.ip.tcp.connection.AbstractTcpConnection
All Implemented Interfaces:
java.lang.Runnable, TcpConnection
Direct Known Subclasses:
TcpNetConnection, TcpNioConnection

public abstract class AbstractTcpConnection
extends java.lang.Object
implements TcpConnection

Base class for TcpConnections. TcpConnections are established by client connection factories (outgoing) or server connection factories (incoming).

Since:
2.0

Field Summary
protected  java.lang.String connectionId
           
protected  Deserializer deserializer
           
protected  TcpListener listener
           
protected  org.apache.commons.logging.Log logger
           
protected  TcpMessageMapper mapper
           
protected  TcpSender sender
           
protected  Serializer serializer
           
protected  boolean server
           
protected  boolean singleUse
           
 
Constructor Summary
AbstractTcpConnection(java.net.Socket socket, boolean server, boolean lookupHost)
           
 
Method Summary
 void afterSend(Message<?> message)
           
 void close()
          Closes this connection.
protected  void closeConnection()
          If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().
 java.lang.String getConnectionId()
           
 long getConnectionSeq()
           
 Deserializer<?> getDeserializer()
           
 java.lang.String getHostAddress()
           
 java.lang.String getHostName()
           
 TcpListener getListener()
           
 TcpMessageMapper getMapper()
           
 Serializer<?> getSerializer()
           
 boolean isServer()
           
 boolean isSingleUse()
           
 void registerListener(TcpListener listener)
          Sets the listener that will receive incoming Messages.
 void registerSender(TcpSender sender)
          Registers a sender.
 void setDeserializer(Deserializer<?> deserializer)
           
 void setMapper(TcpMessageMapper mapper)
           
 void setSerializer(Serializer<?> serializer)
           
 void setSingleUse(boolean singleUse)
          When true, the socket is used once and discarded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.ip.tcp.connection.TcpConnection
getPayload, getPort, isOpen, send
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

logger

protected org.apache.commons.logging.Log logger

deserializer

protected Deserializer deserializer

serializer

protected Serializer serializer

mapper

protected TcpMessageMapper mapper

listener

protected TcpListener listener

sender

protected TcpSender sender

singleUse

protected boolean singleUse

server

protected final boolean server

connectionId

protected java.lang.String connectionId
Constructor Detail

AbstractTcpConnection

public AbstractTcpConnection(java.net.Socket socket,
                             boolean server,
                             boolean lookupHost)
Method Detail

afterSend

public void afterSend(Message<?> message)
               throws java.lang.Exception
Throws:
java.lang.Exception

close

public void close()
Closes this connection.

Specified by:
close in interface TcpConnection

closeConnection

protected void closeConnection()
If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().


getMapper

public TcpMessageMapper getMapper()
Returns:
the mapper

setMapper

public void setMapper(TcpMessageMapper mapper)
Specified by:
setMapper in interface TcpConnection
Parameters:
mapper - the mapper to set

getDeserializer

public Deserializer<?> getDeserializer()
Specified by:
getDeserializer in interface TcpConnection
Returns:
the deserializer

setDeserializer

public void setDeserializer(Deserializer<?> deserializer)
Specified by:
setDeserializer in interface TcpConnection
Parameters:
deserializer - the deserializer to set

getSerializer

public Serializer<?> getSerializer()
Specified by:
getSerializer in interface TcpConnection
Returns:
the serializer

setSerializer

public void setSerializer(Serializer<?> serializer)
Specified by:
setSerializer in interface TcpConnection
Parameters:
serializer - the serializer to set

registerListener

public void registerListener(TcpListener listener)
Description copied from interface: TcpConnection
Sets the listener that will receive incoming Messages.

Specified by:
registerListener in interface TcpConnection
Parameters:
listener - the listener to set

registerSender

public void registerSender(TcpSender sender)
Description copied from interface: TcpConnection
Registers a sender. Used on server side sockets so a sender can determine which connection to send a reply to.

Specified by:
registerSender in interface TcpConnection
Parameters:
sender - the sender to set

getListener

public TcpListener getListener()
Specified by:
getListener in interface TcpConnection
Returns:
the listener

setSingleUse

public void setSingleUse(boolean singleUse)
Description copied from interface: TcpConnection
When true, the socket is used once and discarded.

Specified by:
setSingleUse in interface TcpConnection
Parameters:
singleUse - true if this socket is to used once and discarded.

isSingleUse

public boolean isSingleUse()
Specified by:
isSingleUse in interface TcpConnection
Returns:
True if connection is used once.

isServer

public boolean isServer()
Specified by:
isServer in interface TcpConnection
Returns:
True if connection is used once.

getConnectionSeq

public long getConnectionSeq()
Specified by:
getConnectionSeq in interface TcpConnection
Returns:
the next sequence number for a message received on this socket

getHostAddress

public java.lang.String getHostAddress()
Specified by:
getHostAddress in interface TcpConnection
Returns:
the host address

getHostName

public java.lang.String getHostName()
Specified by:
getHostName in interface TcpConnection
Returns:
the host name

getConnectionId

public java.lang.String getConnectionId()
Specified by:
getConnectionId in interface TcpConnection
Returns:
a string uniquely representing a connection.