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
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger
-
Constructor Summary
ConstructorDescriptionTcpNetConnection
(Socket socket, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Construct a TcpNetConnection for the socket. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this connection.Uses the deserializer to obtain the message payload from the connection's input stream.int
getPort()
protected boolean
handleReadException
(Exception exception) protected InputStream
Subclasses can override this, for example to wrap the input stream.boolean
boolean
isOpen()
void
run()
If there is no listener, this method exits.void
Converts and sends the message.void
Set the socket's input stream to end of stream.void
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:
isLongLived
in interfaceSchedulingAwareRunnable
-
close
public void close()Closes this connection.- Specified by:
close
in interfaceTcpConnection
- Overrides:
close
in classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Specified by:
isOpen
in interfaceTcpConnection
- Returns:
- true if the connection is open.
-
send
Description copied from interface:TcpConnection
Converts and sends the message.- Specified by:
send
in interfaceTcpConnection
- Parameters:
message
- The message,
-
getPayload
Description copied from interface:TcpConnection
Uses the deserializer to obtain the message payload from the connection's input stream.- Specified by:
getPayload
in interfaceTcpConnection
- Returns:
- The payload.
-
getPort
public int getPort()- Specified by:
getPort
in interfaceTcpConnection
- Returns:
- the port
-
getDeserializerStateKey
- Specified by:
getDeserializerStateKey
in interfaceTcpConnection
- Returns:
- a key that can be used to reference state in a
Deserializer
that 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:
getSslSession
in interfaceTcpConnection
- Returns:
- the
SSLSession
associated 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 theDeserializer
and the listener'sTcpListener.onMessage(Message)
method is called. -
handleReadException
-
shutdownInput
Set the socket's input stream to end of stream.- Specified by:
shutdownInput
in interfaceTcpConnection
- Throws:
IOException
- an IO Exception.- Since:
- 5.2
- See Also:
-
shutdownOutput
Disable the socket's output stream.- Specified by:
shutdownOutput
in interfaceTcpConnection
- Throws:
IOException
- an IO Exception- Since:
- 5.2
- See Also:
-