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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTcpConnectionSupport(Socket socket, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Create aTcpConnectionSupportobject and publishes aTcpConnectionOpenEvent, if an event publisher is provided.TcpConnectionSupport(ApplicationEventPublisher applicationEventPublisher) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this connection.protected voidcloseConnection(boolean isException) If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().voidSet whether or not automatic or manual registration of theTcpListeneris to be used.Deserializer<?>Return the list of senders.Serializer<?>Provides getters forSocketproperties.longprotected booleanbooleanisServer()protected voidprotected voidprotected voidvoidpublishEvent(TcpConnectionEvent event) Allow interceptors etc to publish events, perhaps subclasses of TcpConnectionEvent.voidregisterListener(TcpListener listener) Set the listener that will receive incoming Messages.voidregisterSender(TcpSender senderToRegister) Register a sender.voidregisterSenders(List<TcpSender> sendersToRegister) Register the senders.voidregisterTestListener(TcpListener tListener) Set a temporary listener to receive just the first incoming message.protected final voidvoidsetDeserializer(Deserializer<?> deserializer) voidsetMapper(TcpMessageMapper mapper) voidsetNeedsTest(boolean needsTest) Set to true to use a temporary listener for just the first incoming message.protected voidsetNoReadErrorOnClose(boolean noReadErrorOnClose) voidsetSerializer(Serializer<?> serializer) voidsetWrapped(boolean wrapped) Set to true if intercepted.voidsetWrapper(TcpConnectionSupport wrapper) Set the wrapper.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 aTcpConnectionSupportobject 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:
closein 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:
getDeserializerin interfaceTcpConnection- Returns:
- the deserializer
-
setDeserializer
- Parameters:
deserializer- the deserializer to set
-
getSerializer
- Specified by:
getSerializerin 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 theTcpListeneris 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:
getListenerin 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:
isServerin interfaceTcpConnection- Returns:
- True if connection is used once.
-
incrementAndGetConnectionSequence
public long incrementAndGetConnectionSequence()- Specified by:
incrementAndGetConnectionSequencein interfaceTcpConnection- Returns:
- the next sequence number for a message received on this socket
-
getHostAddress
- Specified by:
getHostAddressin interfaceTcpConnection- Returns:
- the host address
-
getHostName
- Specified by:
getHostNamein interfaceTcpConnection- Returns:
- the host name
-
getConnectionId
- Specified by:
getConnectionIdin interfaceTcpConnection- Returns:
- a string uniquely representing a connection.
-
getSocketInfo
Description copied from interface:TcpConnectionProvides getters forSocketproperties.- Specified by:
getSocketInfoin 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
-