Spring Integration

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

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

public abstract class TcpConnectionSupport
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
Author:
Gary Russell

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
TcpConnectionSupport()
           
TcpConnectionSupport(java.net.Socket socket, boolean server, boolean lookupHost, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, java.lang.String connectionFactoryName)
          Creates a TcpConnectionSupport object and publishes a TcpConnectionEvent with TcpConnectionEvent.TcpConnectionEventType.OPEN, if so configured.
 
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()
           
 org.springframework.core.serializer.Deserializer<?> getDeserializer()
           
 java.lang.String getHostAddress()
           
 java.lang.String getHostName()
           
 TcpListener getListener()
           
 TcpMessageMapper getMapper()
           
 TcpSender getSender()
           
 org.springframework.core.serializer.Serializer<?> getSerializer()
           
 long incrementAndGetConnectionSequence()
           
 boolean isServer()
           
 boolean isSingleUse()
           
protected  void publishConnectionCloseEvent()
           
protected  void publishConnectionExceptionEvent(java.lang.Throwable t)
           
protected  void publishConnectionOpenEvent()
           
 void publishEvent(TcpConnectionEvent event)
          Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent.
 void registerListener(TcpListener listener)
          Sets the listener that will receive incoming Messages.
 void registerSender(TcpSender sender)
          Registers a sender.
 void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
           
 void setMapper(TcpMessageMapper mapper)
           
 void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
           
 void setSingleUse(boolean singleUse)
           
 
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
getDeserializerStateKey, getPayload, getPort, isOpen, send
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

TcpConnectionSupport

public TcpConnectionSupport()

TcpConnectionSupport

public TcpConnectionSupport(java.net.Socket socket,
                            boolean server,
                            boolean lookupHost,
                            org.springframework.context.ApplicationEventPublisher applicationEventPublisher,
                            java.lang.String connectionFactoryName)
Creates a TcpConnectionSupport object and publishes a TcpConnectionEvent with TcpConnectionEvent.TcpConnectionEventType.OPEN, if so configured.

Parameters:
socket - the underlying socket.
server - true if this connection is a server connection
lookupHost - true if reverse lookup of the host name should be performed, otherwise, the ip address will be used for identification purposes.
applicationEventPublisher - the publisher to which OPEN, CLOSE and EXCEPTION events will be sent; may be null if event publishing is not required.
connectionFactoryName - the name of the connection factory creating this connection; used during event publishing, may be null, in which case "unknown" will be used.
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)
Parameters:
mapper - the mapper to set

getDeserializer

public org.springframework.core.serializer.Deserializer<?> getDeserializer()
Specified by:
getDeserializer in interface TcpConnection
Returns:
the deserializer

setDeserializer

public void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
Parameters:
deserializer - the deserializer to set

getSerializer

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

setSerializer

public void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
Parameters:
serializer - the serializer to set

registerListener

public void registerListener(TcpListener listener)
Sets the listener that will receive incoming Messages.

Parameters:
listener - The listener.

registerSender

public void registerSender(TcpSender sender)
Registers a sender. Used on server side connections so a sender can determine which connection to send a reply to.

Parameters:
sender - the sender.

getListener

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

getSender

public TcpSender getSender()
Returns:
the sender

setSingleUse

public void setSingleUse(boolean singleUse)
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.

incrementAndGetConnectionSequence

public long incrementAndGetConnectionSequence()
Specified by:
incrementAndGetConnectionSequence 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.

publishConnectionOpenEvent

protected void publishConnectionOpenEvent()

publishConnectionCloseEvent

protected void publishConnectionCloseEvent()

publishConnectionExceptionEvent

protected void publishConnectionExceptionEvent(java.lang.Throwable t)

publishEvent

public void publishEvent(TcpConnectionEvent event)
Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent. The event source must be this connection.

Parameters:
event - the event to publish.

Spring Integration