Interface TcpConnection

All Superinterfaces:
Runnable
All Known Subinterfaces:
TcpConnectionInterceptor
All Known Implementing Classes:
TcpConnectionInterceptorSupport, TcpConnectionSupport, TcpNetConnection, TcpNioConnection, TcpNioSSLConnection

public interface TcpConnection extends 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
Author:
Gary Russell
  • Method Details

    • close

      void close()
      Closes the connection.
    • isOpen

      boolean isOpen()
      Returns:
      true if the connection is open.
    • send

      void send(Message<?> message)
      Converts and sends the message.
      Parameters:
      message - The message,
    • getPayload

      @Nullable Object 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

      @Nullable TcpListener getListener()
      Returns:
      this connection's listener
    • incrementAndGetConnectionSequence

      long incrementAndGetConnectionSequence()
      Returns:
      the next sequence number for a message received on this socket
    • getDeserializerStateKey

      @Nullable Object 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

      @Nullable SSLSession getSslSession()
      Returns:
      the SSLSession associated with this connection, if SSL is in use, null otherwise.
      Since:
      4.2
    • getSocketInfo

      SocketInfo getSocketInfo()
      Provides getters for Socket properties.
      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 IOException
      Set the connection's input stream to end of stream.
      Throws:
      IOException - an IO Exception.
      Since:
      5.2
    • shutdownOutput

      default void shutdownOutput() throws IOException
      Disable the socket's output stream.
      Throws:
      IOException - an IO Exception
      Since:
      5.2