Class TcpConnectionSupport
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
- All Implemented Interfaces:
Runnable
,TcpConnection
- Direct Known Subclasses:
TcpConnectionInterceptorSupport
,TcpNetConnection
,TcpNioConnection
Base class for TcpConnections. TcpConnections are established by
client connection factories (outgoing) or server connection factories
(incoming).
- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTcpConnectionSupport
(Socket socket, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Create aTcpConnectionSupport
object and publishes aTcpConnectionOpenEvent
, if an event publisher is provided.TcpConnectionSupport
(ApplicationEventPublisher applicationEventPublisher) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this connection.protected void
closeConnection
(boolean isException) If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().void
Set whether or not automatic or manual registration of theTcpListener
is to be used.Deserializer<?>
Return the list of senders.Serializer<?>
Provides getters forSocket
properties.long
protected boolean
boolean
isServer()
protected void
protected void
protected void
void
publishEvent
(TcpConnectionEvent event) Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent.void
registerListener
(TcpListener listener) Set the listener that will receive incoming Messages.void
registerSender
(TcpSender senderToRegister) Register a sender.void
registerSenders
(List<TcpSender> sendersToRegister) Register the senders.void
registerTestListener
(TcpListener tListener) Set a temporary listener to receive just the first incoming message.protected final void
void
setDeserializer
(Deserializer<?> deserializer) void
setMapper
(TcpMessageMapper mapper) void
setNeedsTest
(boolean needsTest) Set to true to use a temporary listener for just the first incoming message.protected void
setNoReadErrorOnClose
(boolean noReadErrorOnClose) void
setSerializer
(Serializer<?> serializer) void
setWrapped
(boolean wrapped) Set to true if intercepted.void
setWrapper
(TcpConnectionSupport wrapper) Set the wrapper.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
getDeserializerStateKey, getPayload, getPort, getSslSession, isOpen, send, shutdownInput, shutdownOutput
-
Field Details
-
logger
-
-
Constructor Details
-
TcpConnectionSupport
public TcpConnectionSupport() -
TcpConnectionSupport
-
TcpConnectionSupport
public TcpConnectionSupport(Socket socket, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName) Create aTcpConnectionSupport
object and publishes aTcpConnectionOpenEvent
, if an event publisher is provided.- Parameters:
socket
- the underlying socket.server
- true if this connection is a server connectionlookupHost
- 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 Details
-
close
public void close()Close this connection.- Specified by:
close
in interfaceTcpConnection
-
closeConnection
protected void closeConnection(boolean isException) If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().- Parameters:
isException
- true when this call is the result of an Exception.
-
getMapper
- Returns:
- the mapper
-
setMapper
- Parameters:
mapper
- the mapper to set
-
getDeserializer
- Specified by:
getDeserializer
in interfaceTcpConnection
- Returns:
- the deserializer
-
setDeserializer
- Parameters:
deserializer
- the deserializer to set
-
getSerializer
- Specified by:
getSerializer
in interfaceTcpConnection
- Returns:
- the serializer
-
setSerializer
- Parameters:
serializer
- the serializer to set
-
setNeedsTest
public void setNeedsTest(boolean needsTest) Set to true to use a temporary listener for just the first incoming message.- Parameters:
needsTest
- true for a temporary listener.- Since:
- 5.3
-
registerListener
Set the listener that will receive incoming Messages.- Parameters:
listener
- The listener.
-
registerTestListener
Set a temporary listener to receive just the first incoming message. Used in conjunction with a connectionTest in a client connection factory.- Parameters:
tListener
- the test listener.- Since:
- 5.3
-
enableManualListenerRegistration
public void enableManualListenerRegistration()Set whether or not automatic or manual registration of theTcpListener
is to be used. (Default automatic). When manual registration is in place, incoming messages will be delayed until the listener is registered.- Since:
- 1.4.5
-
registerSender
Register a sender. Used on server side connections so a sender can determine which connection to send a reply to.- Parameters:
senderToRegister
- the sender.
-
registerSenders
Register the senders. Used on server side connections so a sender can determine which connection to send a reply to.- Parameters:
sendersToRegister
- the sender.- Since:
- 5.4
-
getListener
- Specified by:
getListener
in interfaceTcpConnection
- Returns:
- the listener
-
getSender
- Returns:
- the first sender, if present.
-
getSenders
Return the list of senders.- Returns:
- the senders.
- Since:
- 5.4
-
isServer
public boolean isServer()- Specified by:
isServer
in interfaceTcpConnection
- Returns:
- True if connection is used once.
-
incrementAndGetConnectionSequence
public long incrementAndGetConnectionSequence()- Specified by:
incrementAndGetConnectionSequence
in interfaceTcpConnection
- Returns:
- the next sequence number for a message received on this socket
-
getHostAddress
- Specified by:
getHostAddress
in interfaceTcpConnection
- Returns:
- the host address
-
getHostName
- Specified by:
getHostName
in interfaceTcpConnection
- Returns:
- the host name
-
getConnectionId
- Specified by:
getConnectionId
in interfaceTcpConnection
- Returns:
- a string uniquely representing a connection.
-
getSocketInfo
Description copied from interface:TcpConnection
Provides getters forSocket
properties.- Specified by:
getSocketInfo
in interfaceTcpConnection
- Returns:
- the socketInfo - may be null, for example in interceptors; interceptors should override and delegate to the actual TcpConnection.
- Since:
- 4.2.5
-
setWrapped
public void setWrapped(boolean wrapped) Set to true if intercepted.- Parameters:
wrapped
- true if wrapped.- Since:
- 5.4.5
-
setWrapper
Set the wrapper.- Parameters:
wrapper
- the wrapper.- Since:
- 5.4.6
-
getConnectionFactoryName
-
isNoReadErrorOnClose
protected boolean isNoReadErrorOnClose() -
setNoReadErrorOnClose
protected void setNoReadErrorOnClose(boolean noReadErrorOnClose) -
sendExceptionToListener
-
publishConnectionOpenEvent
protected void publishConnectionOpenEvent() -
publishConnectionCloseEvent
protected void publishConnectionCloseEvent() -
publishConnectionExceptionEvent
-
publishEvent
Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent. The event source must be this connection.- Parameters:
event
- the event to publish.
-
toString
-