Interface TcpConnection
- All Superinterfaces:
Runnable
- All Known Subinterfaces:
TcpConnectionInterceptor
- All Known Implementing Classes:
TcpConnectionInterceptorSupport
,TcpConnectionSupport
,TcpNetConnection
,TcpNioConnection
,TcpNioSSLConnection
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
- Author:
- Gary Russell
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the connection.Deserializer<?>
Uses the deserializer to obtain the message payload from the connection's input stream.int
getPort()
Serializer<?>
Provides getters forSocket
properties.long
boolean
isOpen()
boolean
isServer()
void
Converts and sends the message.default void
Set the connection's input stream to end of stream.default void
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
Converts and sends the message.- Parameters:
message
- The message,
-
getPayload
Uses the deserializer to obtain the message payload from the connection's input stream.- Returns:
- The payload.
-
getHostName
String getHostName()- Returns:
- the host name
-
getHostAddress
String getHostAddress()- Returns:
- the host address
-
getPort
int getPort()- Returns:
- the port
-
getConnectionId
String getConnectionId()- Returns:
- a string uniquely representing a connection.
-
isServer
boolean isServer()- Returns:
- True if connection is used once.
-
getDeserializer
Deserializer<?> getDeserializer()- Returns:
- the deserializer
-
getSerializer
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
- 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
- Returns:
- the
SSLSession
associated with this connection, if SSL is in use, null otherwise. - Since:
- 4.2
-
getSocketInfo
SocketInfo getSocketInfo()Provides getters forSocket
properties.- Returns:
- the socketInfo - may be null, for example in interceptors; interceptors should override and delegate to the actual TcpConnection.
- Since:
- 4.3
-
shutdownInput
Set the connection's input stream to end of stream.- Throws:
IOException
- an IO Exception.- Since:
- 5.2
-
shutdownOutput
Disable the socket's output stream.- Throws:
IOException
- an IO Exception- Since:
- 5.2
-