Spring Integration

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

java.lang.Object
  extended by org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
      extended by org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorSupport
All Implemented Interfaces:
java.lang.Runnable, TcpConnection, TcpConnectionInterceptor, TcpListener, TcpSender

public abstract class TcpConnectionInterceptorSupport
extends TcpConnectionSupport
implements TcpConnectionInterceptor

Base class for TcpConnectionIntercepters; passes all method calls through to the underlying TcpConnection.

Since:
2.0
Author:
Gary Russell

Field Summary
 
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger
 
Constructor Summary
TcpConnectionInterceptorSupport()
           
 
Method Summary
 void addNewConnection(TcpConnection connection)
          When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.
 void close()
          Closes this connection.
 java.lang.String getConnectionId()
           
 org.springframework.core.serializer.Deserializer<?> getDeserializer()
           
 java.lang.Object getDeserializerStateKey()
           
 java.lang.String getHostAddress()
           
 java.lang.String getHostName()
           
 TcpListener getListener()
           
 java.lang.Object getPayload()
          Uses the deserializer to obtain the message payload from the connection's input stream.
 int getPort()
           
 TcpSender getSender()
           
 org.springframework.core.serializer.Serializer<?> getSerializer()
           
 TcpConnectionSupport getTheConnection()
          Returns the underlying connection (or next interceptor)
protected  boolean hasRealSender()
           
 long incrementAndGetConnectionSequence()
           
 boolean isOpen()
           
 boolean isServer()
           
 boolean isSingleUse()
           
 boolean onMessage(Message<?> message)
          Called by a TCPConnection when a new message arrives.
 void registerListener(TcpListener listener)
          Sets the listener that will receive incoming Messages.
 void registerSender(TcpSender sender)
          Registers a sender.
 void removeDeadConnection(TcpConnection connection)
          When we are using sockets owned by a TcpListener, this method is called each time a connection is closed.
 void run()
           
 void send(Message<?> message)
          Converts and sends the message.
 void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
           
 void setMapper(TcpMessageMapper mapper)
           
 void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
           
 void setSingleUse(boolean singleUse)
           
 void setTheConnection(TcpConnectionSupport theConnection)
          Sets the underlying connection (or next interceptor)
 
Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
afterSend, closeConnection, getMapper, publishConnectionCloseEvent, publishConnectionExceptionEvent, publishConnectionOpenEvent, publishEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpConnectionInterceptorSupport

public TcpConnectionInterceptorSupport()
Method Detail

close

public void close()
Description copied from class: TcpConnectionSupport
Closes this connection.

Specified by:
close in interface TcpConnection
Overrides:
close in class TcpConnectionSupport

isOpen

public boolean isOpen()
Specified by:
isOpen in interface TcpConnection
Returns:
true if the connection is open.

getPayload

public java.lang.Object getPayload()
                            throws java.lang.Exception
Description copied from interface: TcpConnection
Uses the deserializer to obtain the message payload from the connection's input stream.

Specified by:
getPayload in interface TcpConnection
Returns:
The payload
Throws:
java.lang.Exception

getHostName

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

getHostAddress

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

getPort

public int getPort()
Specified by:
getPort in interface TcpConnection
Returns:
the port

getDeserializerStateKey

public java.lang.Object getDeserializerStateKey()
Specified by:
getDeserializerStateKey in interface TcpConnection
Returns:
a key that can be used to reference state in a Deserializer that maintains state for this connection. Currently, this would be the InputStream associated with the connection, but the object should be treated as opaque and ONLY used as a key.

registerListener

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

Overrides:
registerListener in class TcpConnectionSupport
Parameters:
listener - The listener.

registerSender

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

Overrides:
registerSender in class TcpConnectionSupport
Parameters:
sender - the sender.

getConnectionId

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

isSingleUse

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

run

public void run()
Specified by:
run in interface java.lang.Runnable

setSingleUse

public void setSingleUse(boolean singleUse)
Overrides:
setSingleUse in class TcpConnectionSupport
Parameters:
singleUse - true if this socket is to used once and discarded.

setMapper

public void setMapper(TcpMessageMapper mapper)
Overrides:
setMapper in class TcpConnectionSupport
Parameters:
mapper - the mapper to set

getDeserializer

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

setDeserializer

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

getSerializer

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

setSerializer

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

isServer

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

onMessage

public boolean onMessage(Message<?> message)
Description copied from interface: TcpListener
Called by a TCPConnection when a new message arrives.

Specified by:
onMessage in interface TcpListener
Parameters:
message - The message.
Returns:
true if the message was intercepted

send

public void send(Message<?> message)
          throws java.lang.Exception
Description copied from interface: TcpConnection
Converts and sends the message.

Specified by:
send in interface TcpConnection
Parameters:
message - The message
Throws:
java.lang.Exception

getTheConnection

public TcpConnectionSupport getTheConnection()
Returns the underlying connection (or next interceptor)

Returns:
the connection

setTheConnection

public void setTheConnection(TcpConnectionSupport theConnection)
Sets the underlying connection (or next interceptor)

Parameters:
theConnection - the connection

getListener

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

addNewConnection

public void addNewConnection(TcpConnection connection)
Description copied from interface: TcpSender
When we are using sockets owned by a TcpListener, this method is called each time a new connection is made.

Specified by:
addNewConnection in interface TcpSender
Parameters:
connection - The connection.

removeDeadConnection

public void removeDeadConnection(TcpConnection connection)
Description copied from interface: TcpSender
When we are using sockets owned by a TcpListener, this method is called each time a connection is closed.

Specified by:
removeDeadConnection in interface TcpSender
Parameters:
connection - The connection.

incrementAndGetConnectionSequence

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

getSender

public TcpSender getSender()
Overrides:
getSender in class TcpConnectionSupport
Returns:
the sender

hasRealSender

protected boolean hasRealSender()

Spring Integration