Class TcpConnectionSupport
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
- All Implemented Interfaces:
java.lang.Runnable,TcpConnection
- Direct Known Subclasses:
TcpConnectionInterceptorSupport,TcpNetConnection,TcpNioConnection
public abstract class TcpConnectionSupport extends java.lang.Object implements TcpConnection
Base class for TcpConnections. TcpConnections are established by
client connection factories (outgoing) or server connection factories
(incoming).
- Since:
- 2.0
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.Loglogger -
Constructor Summary
Constructors Constructor Description TcpConnectionSupport()TcpConnectionSupport(java.net.Socket socket, boolean server, boolean lookupHost, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, java.lang.String connectionFactoryName)Creates aTcpConnectionSupportobject and publishes aTcpConnectionOpenEvent, if an event publisher is provided.TcpConnectionSupport(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) -
Method Summary
Modifier and Type Method Description voidclose()Closes this connection.protected voidcloseConnection(boolean isException)If we have been intercepted, propagate the close from the outermost interceptor; otherwise, just call close().voidenableManualListenerRegistration()Set whether or not automatic or manual registration of theTcpListeneris to be used.java.lang.StringgetConnectionFactoryName()java.lang.StringgetConnectionId()org.springframework.core.serializer.Deserializer<?>getDeserializer()java.lang.StringgetHostAddress()java.lang.StringgetHostName()TcpListenergetListener()TcpMessageMappergetMapper()TcpSendergetSender()java.util.List<TcpSender>getSenders()Return the list of senders.org.springframework.core.serializer.Serializer<?>getSerializer()SocketInfogetSocketInfo()Provides getters forSocketproperties.longincrementAndGetConnectionSequence()protected booleanisNoReadErrorOnClose()booleanisServer()protected voidpublishConnectionCloseEvent()protected voidpublishConnectionExceptionEvent(java.lang.Throwable t)protected voidpublishConnectionOpenEvent()voidpublishEvent(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)Registers a sender.voidregisterSenders(java.util.List<TcpSender> sendersToRegister)Registers the senders.voidregisterTestListener(TcpListener tListener)Set a temporary listener to receive just the first incoming message.protected voidsendExceptionToListener(java.lang.Exception e)voidsetDeserializer(org.springframework.core.serializer.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(org.springframework.core.serializer.Serializer<?> serializer)java.lang.StringtoString()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
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
TcpConnectionSupport
public TcpConnectionSupport() -
TcpConnectionSupport
public TcpConnectionSupport(@Nullable org.springframework.context.ApplicationEventPublisher applicationEventPublisher) -
TcpConnectionSupport
public TcpConnectionSupport(java.net.Socket socket, boolean server, boolean lookupHost, @Nullable org.springframework.context.ApplicationEventPublisher applicationEventPublisher, @Nullable java.lang.String connectionFactoryName)Creates 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()Closes 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
public org.springframework.core.serializer.Deserializer<?> getDeserializer()- Specified by:
getDeserializerin interfaceTcpConnection- Returns:
- the deserializer
-
setDeserializer
public void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)- Parameters:
deserializer- the deserializer to set
-
getSerializer
public org.springframework.core.serializer.Serializer<?> getSerializer()- Specified by:
getSerializerin interfaceTcpConnection- Returns:
- the serializer
-
setSerializer
public void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)- 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
Registers a sender. Used on server side connections so a sender can determine which connection to send a reply to.- Parameters:
senderToRegister- the sender.
-
registerSenders
Registers 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
public java.lang.String getHostAddress()- Specified by:
getHostAddressin interfaceTcpConnection- Returns:
- the host address
-
getHostName
public java.lang.String getHostName()- Specified by:
getHostNamein interfaceTcpConnection- Returns:
- the host name
-
getConnectionId
public java.lang.String 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
-
getConnectionFactoryName
public java.lang.String getConnectionFactoryName() -
isNoReadErrorOnClose
protected boolean isNoReadErrorOnClose() -
setNoReadErrorOnClose
protected void setNoReadErrorOnClose(boolean noReadErrorOnClose) -
sendExceptionToListener
protected final void sendExceptionToListener(java.lang.Exception e) -
publishConnectionOpenEvent
protected void publishConnectionOpenEvent() -
publishConnectionCloseEvent
protected void publishConnectionCloseEvent() -
publishConnectionExceptionEvent
protected void publishConnectionExceptionEvent(java.lang.Throwable t) -
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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-