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
public class TcpNetConnection extends TcpConnectionSupport implements SchedulingAwareRunnable
A TcpConnection that uses and underlying
Socket.- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger -
Constructor Summary
Constructors Constructor Description TcpNetConnection(Socket socket, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName)Construct a TcpNetConnection for the socket. -
Method Summary
Modifier and Type Method Description voidclose()Closes this connection.ObjectgetDeserializerStateKey()ObjectgetPayload()Uses the deserializer to obtain the message payload from the connection's input stream.intgetPort()SSLSessiongetSslSession()protected booleanhandleReadException(Exception exception)protected InputStreaminputStream()Subclasses can override this, for example to wrap the input stream.booleanisLongLived()booleanisOpen()voidrun()If there is no listener, this method exits.voidsend(Message<?> message)Converts and sends the message.voidshutdownInput()Set the socket's input stream to end of stream.voidshutdownOutput()Disable the socket's output stream.Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
closeConnection, 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, toString
-
Constructor Details
-
TcpNetConnection
public TcpNetConnection(Socket socket, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName)Construct a TcpNetConnection for the socket.- Parameters:
socket- the socketserver- 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
-
isLongLived
public boolean isLongLived()- Specified by:
isLongLivedin interfaceSchedulingAwareRunnable
-
close
public void close()Closes this connection.- Specified by:
closein interfaceTcpConnection- Overrides:
closein classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Specified by:
isOpenin interfaceTcpConnection- Returns:
- true if the connection is open.
-
send
Description copied from interface:TcpConnectionConverts and sends the message.- Specified by:
sendin interfaceTcpConnection- Parameters:
message- The message,
-
getPayload
Description copied from interface:TcpConnectionUses the deserializer to obtain the message payload from the connection's input stream.- Specified by:
getPayloadin interfaceTcpConnection- Returns:
- The payload.
-
getPort
public int getPort()- Specified by:
getPortin interfaceTcpConnection- Returns:
- the port
-
getDeserializerStateKey
- Specified by:
getDeserializerStateKeyin interfaceTcpConnection- 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 interfaceTcpConnection- Returns:
- the
SSLSessionassociated with this connection, if SSL is in use, null otherwise.
-
inputStream
Subclasses can override this, for example to wrap the input stream.- Returns:
- the input stream.
- Throws:
IOException- if an exception occurs.- Since:
- 5.0
-
run
public 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
-
shutdownInput
Set the socket's input stream to end of stream.- Specified by:
shutdownInputin interfaceTcpConnection- Throws:
IOException- an IO Exception.- Since:
- 5.2
- See Also:
Socket.shutdownInput()
-
shutdownOutput
Disable the socket's output stream.- Specified by:
shutdownOutputin interfaceTcpConnection- Throws:
IOException- an IO Exception- Since:
- 5.2
- See Also:
Socket.shutdownOutput()
-