Spring Integration

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

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

public abstract class AbstractTcpConnectionInterceptor
extends java.lang.Object
implements TcpConnectionInterceptor

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

Since:
2.0
Author:
Gary Russell

Constructor Summary
AbstractTcpConnectionInterceptor()
           
 
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 the connection.
 java.lang.String getConnectionId()
           
 org.springframework.core.serializer.Deserializer<?> getDeserializer()
           
 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()
           
 org.springframework.core.serializer.Serializer<?> getSerializer()
           
 TcpConnection 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)
          When true, the socket is used once and discarded.
 void setTheConnection(TcpConnection theConnection)
          Sets the underlying connection (or next interceptor)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTcpConnectionInterceptor

public AbstractTcpConnectionInterceptor()
Method Detail

close

public void close()
Description copied from interface: TcpConnection
Closes the connection.

Specified by:
close in interface TcpConnection

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
Returns:
the host name

getHostAddress

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

getPort

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

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

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

getConnectionId

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

isSingleUse

public boolean isSingleUse()
Specified by:
isSingleUse in interface TcpConnection
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)
Description copied from interface: TcpConnection
When true, the socket is used once and discarded.

Specified by:
setSingleUse in interface TcpConnection
Parameters:
singleUse - the singleUse

setMapper

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

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)
Specified by:
setDeserializer in interface TcpConnection
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)
Specified by:
setSerializer in interface TcpConnection
Parameters:
serializer - the serializer to set

isServer

public boolean isServer()
Specified by:
isServer in interface TcpConnection
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 TcpConnection getTheConnection()
Returns the underlying connection (or next interceptor)

Returns:
the connection

setTheConnection

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

Specified by:
setTheConnection in interface TcpConnectionInterceptor
Parameters:
theConnection - the connection

getListener

public TcpListener getListener()
Specified by:
getListener in interface TcpConnection
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
Returns:
the next sequence number for a message received on this socket

hasRealSender

protected boolean hasRealSender()

Spring Integration