Class TcpConnectionInterceptorSupport
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorSupport
- All Implemented Interfaces:
Runnable
,TcpConnection
,TcpConnectionInterceptor
,TcpListener
,TcpSender
public abstract class TcpConnectionInterceptorSupport
extends TcpConnectionSupport
implements TcpConnectionInterceptor
Base class for
TcpConnectionInterceptor
s; passes all method calls through
to the underlying TcpConnection
.- Since:
- 2.0
- Author:
- Gary Russell, Kazuki Shimizu, Christian Tzolov, Ngoc Nhan
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger
-
Constructor Summary
ConstructorDescriptionTcpConnectionInterceptorSupport
(ApplicationEventPublisher applicationEventPublisher) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNewConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.void
close()
Close this connection.Deserializer<?>
Uses the deserializer to obtain the message payload from the connection's input stream.int
getPort()
Return the list of senders.Serializer<?>
Provides getters forSocket
properties.Return the underlying connection (or next interceptor).protected boolean
long
boolean
isOpen()
boolean
isServer()
boolean
Called by a TCPConnection when a new message arrives.void
registerListener
(TcpListener listener) Set the listener that will receive incoming Messages.void
registerSender
(TcpSender sender) Register a sender.void
registerSenders
(List<TcpSender> sendersToRegister) Register the senders.void
removeDeadConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.void
run()
void
Converts and sends the message.void
setDeserializer
(Deserializer<?> deserializer) void
setMapper
(TcpMessageMapper mapper) void
setSerializer
(Serializer<?> serializer) void
setTheConnection
(TcpConnectionSupport theConnection) Set the underlying connection (or next interceptor).Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
closeConnection, enableManualListenerRegistration, getMapper, isNoReadErrorOnClose, publishConnectionCloseEvent, publishConnectionExceptionEvent, publishConnectionOpenEvent, publishEvent, registerTestListener, sendExceptionToListener, setNeedsTest, setNoReadErrorOnClose, setWrapped, setWrapper, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.ip.tcp.connection.TcpConnection
shutdownInput, shutdownOutput
-
Constructor Details
-
TcpConnectionInterceptorSupport
public TcpConnectionInterceptorSupport() -
TcpConnectionInterceptorSupport
-
-
Method Details
-
close
public void close()Description copied from class:TcpConnectionSupport
Close this connection.- Specified by:
close
in interfaceTcpConnection
- Overrides:
close
in classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Specified by:
isOpen
in interfaceTcpConnection
- Returns:
- true if the connection is open.
-
getPayload
Description copied from interface:TcpConnection
Uses the deserializer to obtain the message payload from the connection's input stream.- Specified by:
getPayload
in interfaceTcpConnection
- Returns:
- The payload.
-
getHostName
- Specified by:
getHostName
in interfaceTcpConnection
- Overrides:
getHostName
in classTcpConnectionSupport
- Returns:
- the host name
-
getHostAddress
- Specified by:
getHostAddress
in interfaceTcpConnection
- Overrides:
getHostAddress
in classTcpConnectionSupport
- Returns:
- the host address
-
getPort
public int getPort()- Specified by:
getPort
in interfaceTcpConnection
- Returns:
- the port
-
getDeserializerStateKey
- Specified by:
getDeserializerStateKey
in interfaceTcpConnection
- 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
Description copied from class:TcpConnectionSupport
Set the listener that will receive incoming Messages.- Overrides:
registerListener
in classTcpConnectionSupport
- Parameters:
listener
- The listener.
-
registerSender
Description copied from class:TcpConnectionSupport
Register a sender. Used on server side connections so a sender can determine which connection to send a reply to.- Overrides:
registerSender
in classTcpConnectionSupport
- Parameters:
sender
- the sender.
-
registerSenders
Description copied from class:TcpConnectionSupport
Register the senders. Used on server side connections so a sender can determine which connection to send a reply to.- Overrides:
registerSenders
in classTcpConnectionSupport
- Parameters:
sendersToRegister
- the sender.
-
getConnectionId
IMPORTANT: Do not override this method in your interceptor implementation if the intercepted connection is created by a server connection factory, because the connection id of the underlying connection is used for routing when arbitrary outbound messaging is being used. The method is not final because client-side interceptors can override it without any issues.
- Specified by:
getConnectionId
in interfaceTcpConnection
- Overrides:
getConnectionId
in classTcpConnectionSupport
- Returns:
- a string uniquely representing a connection.
-
getSocketInfo
Description copied from interface:TcpConnection
Provides getters forSocket
properties.- Specified by:
getSocketInfo
in interfaceTcpConnection
- Overrides:
getSocketInfo
in classTcpConnectionSupport
- Returns:
- the socketInfo - may be null, for example in interceptors; interceptors should override and delegate to the actual TcpConnection.
-
getConnectionFactoryName
- Overrides:
getConnectionFactoryName
in classTcpConnectionSupport
-
run
public void run() -
setMapper
- Overrides:
setMapper
in classTcpConnectionSupport
- Parameters:
mapper
- the mapper to set
-
getDeserializer
- Specified by:
getDeserializer
in interfaceTcpConnection
- Overrides:
getDeserializer
in classTcpConnectionSupport
- Returns:
- the deserializer
-
setDeserializer
- Overrides:
setDeserializer
in classTcpConnectionSupport
- Parameters:
deserializer
- the deserializer to set
-
getSerializer
- Specified by:
getSerializer
in interfaceTcpConnection
- Overrides:
getSerializer
in classTcpConnectionSupport
- Returns:
- the serializer
-
setSerializer
- Overrides:
setSerializer
in classTcpConnectionSupport
- Parameters:
serializer
- the serializer to set
-
isServer
public boolean isServer()- Specified by:
isServer
in interfaceTcpConnection
- Overrides:
isServer
in classTcpConnectionSupport
- Returns:
- True if connection is used once.
-
getSslSession
- Specified by:
getSslSession
in interfaceTcpConnection
- Returns:
- the
SSLSession
associated with this connection, if SSL is in use, null otherwise.
-
onMessage
Description copied from interface:TcpListener
Called by a TCPConnection when a new message arrives.- Specified by:
onMessage
in interfaceTcpListener
- Parameters:
message
- The message.- Returns:
- true if the message was intercepted
-
send
Description copied from interface:TcpConnection
Converts and sends the message.- Specified by:
send
in interfaceTcpConnection
- Parameters:
message
- The message,
-
getTheConnection
Return the underlying connection (or next interceptor).- Returns:
- the connection
-
setTheConnection
Set the underlying connection (or next interceptor).- Parameters:
theConnection
- the connection
-
getListener
- Specified by:
getListener
in interfaceTcpConnection
- Overrides:
getListener
in classTcpConnectionSupport
- Returns:
- the listener
-
addNewConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.- Specified by:
addNewConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
removeDeadConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.- Specified by:
removeDeadConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
incrementAndGetConnectionSequence
public long incrementAndGetConnectionSequence()- Specified by:
incrementAndGetConnectionSequence
in interfaceTcpConnection
- Overrides:
incrementAndGetConnectionSequence
in classTcpConnectionSupport
- Returns:
- the next sequence number for a message received on this socket
-
getSender
- Overrides:
getSender
in classTcpConnectionSupport
- Returns:
- the first sender, if present.
-
getSenders
Description copied from class:TcpConnectionSupport
Return the list of senders.- Overrides:
getSenders
in classTcpConnectionSupport
- Returns:
- the senders.
-
hasRealSender
protected boolean hasRealSender()
-