Class TcpNetConnection
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpNetConnection
- All Implemented Interfaces:
- Runnable,- TcpConnection,- SchedulingAwareRunnable
A TcpConnection that uses and underlying 
Socket.- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Christian Tzolov, Ngoc Nhan
- 
Field SummaryFields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupportlogger
- 
Constructor SummaryConstructorsConstructorDescriptionTcpNetConnection(Socket socket, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Construct a TcpNetConnection for the socket.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes this connection.Uses the deserializer to obtain the message payload from the connection's input stream.intgetPort()protected booleanhandleReadException(Exception exception) protected InputStreamSubclasses can override this, for example to wrap the input stream.booleanbooleanisOpen()voidrun()If there is no listener, this method exits.voidConverts and sends the message.voidSet the socket's input stream to end of stream.voidDisable the socket's output stream.Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupportcloseConnection, enableManualListenerRegistration, getConnectionFactoryName, getConnectionId, getDeserializer, getHostAddress, getHostName, getListener, getMapper, getSender, getSenders, getSerializer, getSocketInfo, incrementAndGetConnectionSequence, isNoReadErrorOnClose, isServer, publishConnectionCloseEvent, publishConnectionExceptionEvent, publishConnectionOpenEvent, publishEvent, registerListener, registerSender, registerSenders, registerTestListener, sendExceptionToListener, setDeserializer, setMapper, setNeedsTest, setNoReadErrorOnClose, setSerializer, setWrapped, setWrapper, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.scheduling.SchedulingAwareRunnablegetQualifier
- 
Constructor Details- 
TcpNetConnectionpublic TcpNetConnection(Socket socket, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Construct a TcpNetConnection for the socket.- Parameters:
- socket- the socket
- server- if true this connection was created as a result of an incoming request.
- lookupHost- true if hostname lookup should be performed, otherwise the connection will be identified using the ip address.
- 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- 
isLongLivedpublic boolean isLongLived()- Specified by:
- isLongLivedin interface- SchedulingAwareRunnable
 
- 
closepublic void close()Closes this connection.- Specified by:
- closein interface- TcpConnection
- Overrides:
- closein class- TcpConnectionSupport
 
- 
isOpenpublic boolean isOpen()- Specified by:
- isOpenin interface- TcpConnection
- Returns:
- true if the connection is open.
 
- 
sendDescription copied from interface:TcpConnectionConverts and sends the message.- Specified by:
- sendin interface- TcpConnection
- Parameters:
- message- The message,
 
- 
getPayloadDescription copied from interface:TcpConnectionUses the deserializer to obtain the message payload from the connection's input stream.- Specified by:
- getPayloadin interface- TcpConnection
- Returns:
- The payload.
 
- 
getPortpublic int getPort()- Specified by:
- getPortin interface- TcpConnection
- Returns:
- the port
 
- 
getDeserializerStateKey- Specified by:
- getDeserializerStateKeyin interface- TcpConnection
- Returns:
- a key that can be used to reference state in a Deserializerthat 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.
 
- 
getSslSession- Specified by:
- getSslSessionin interface- TcpConnection
- Returns:
- the SSLSessionassociated with this connection, if SSL is in use, null otherwise.
 
- 
inputStreamSubclasses can override this, for example to wrap the input stream.- Returns:
- the input stream.
- Throws:
- IOException- if an exception occurs.
- Since:
- 5.0
 
- 
runpublic void run()If there is no listener, this method exits. When there is a listener, the method runs in a loop reading input from the connection's stream, data is converted to an object using theDeserializerand the listener'sTcpListener.onMessage(Message)method is called.
- 
handleReadException
- 
shutdownInputSet the socket's input stream to end of stream.- Specified by:
- shutdownInputin interface- TcpConnection
- Throws:
- IOException- an IO Exception.
- Since:
- 5.2
- See Also:
 
- 
shutdownOutputDisable the socket's output stream.- Specified by:
- shutdownOutputin interface- TcpConnection
- Throws:
- IOException- an IO Exception
- Since:
- 5.2
- See Also:
 
 
-