Interface TcpConnection
- All Superinterfaces:
java.lang.Runnable
- All Known Subinterfaces:
TcpConnectionInterceptor
- All Known Implementing Classes:
TcpConnectionInterceptorSupport,TcpConnectionSupport,TcpNetConnection,TcpNioConnection,TcpNioSSLConnection
public interface TcpConnection
extends java.lang.Runnable
An abstraction over
Socket and SocketChannel
that sends Message objects by serializing the payload and streaming it to the
destination. Requires a TcpListener to receive incoming messages.- Since:
- 2.0
-
Method Summary
Modifier and Type Method Description voidclose()Closes the connection.java.lang.StringgetConnectionId()org.springframework.core.serializer.Deserializer<?>getDeserializer()java.lang.ObjectgetDeserializerStateKey()java.lang.StringgetHostAddress()java.lang.StringgetHostName()TcpListenergetListener()java.lang.ObjectgetPayload()Uses the deserializer to obtain the message payload from the connection's input stream.intgetPort()org.springframework.core.serializer.Serializer<?>getSerializer()SocketInfogetSocketInfo()Provides getters forSocketproperties.javax.net.ssl.SSLSessiongetSslSession()longincrementAndGetConnectionSequence()booleanisOpen()booleanisServer()voidsend(org.springframework.messaging.Message<?> message)Converts and sends the message.default voidshutdownInput()Set the connection's input stream to end of stream.default voidshutdownOutput()Disable the socket's output stream.
-
Method Details
-
close
void close()Closes the connection. -
isOpen
boolean isOpen()- Returns:
- true if the connection is open.
-
send
void send(org.springframework.messaging.Message<?> message)Converts and sends the message.- Parameters:
message- The message,
-
getPayload
@Nullable java.lang.Object getPayload()Uses the deserializer to obtain the message payload from the connection's input stream.- Returns:
- The payload.
-
getHostName
java.lang.String getHostName()- Returns:
- the host name
-
getHostAddress
java.lang.String getHostAddress()- Returns:
- the host address
-
getPort
int getPort()- Returns:
- the port
-
getConnectionId
java.lang.String getConnectionId()- Returns:
- a string uniquely representing a connection.
-
isServer
boolean isServer()- Returns:
- True if connection is used once.
-
getDeserializer
org.springframework.core.serializer.Deserializer<?> getDeserializer()- Returns:
- the deserializer
-
getSerializer
org.springframework.core.serializer.Serializer<?> getSerializer()- Returns:
- the serializer
-
getListener
- Returns:
- this connection's listener
-
incrementAndGetConnectionSequence
long incrementAndGetConnectionSequence()- Returns:
- the next sequence number for a message received on this socket
-
getDeserializerStateKey
@Nullable java.lang.Object getDeserializerStateKey()- 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
@Nullable javax.net.ssl.SSLSession getSslSession()- Returns:
- the
SSLSessionassociated with this connection, if SSL is in use, null otherwise. - Since:
- 4.2
-
getSocketInfo
SocketInfo getSocketInfo()Provides getters forSocketproperties.- Returns:
- the socketInfo - may be null, for example in interceptors; interceptors should override and delegate to the actual TcpConnection.
- Since:
- 4.3
-
shutdownInput
default void shutdownInput() throws java.io.IOExceptionSet the connection's input stream to end of stream.- Throws:
java.io.IOException- an IO Exception.- Since:
- 5.2
-
shutdownOutput
default void shutdownOutput() throws java.io.IOExceptionDisable the socket's output stream.- Throws:
java.io.IOException- an IO Exception- Since:
- 5.2
-