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, Christian Tzolov, Ngoc Nhan
  • Constructor Details

    • TcpNetConnection

      public TcpNetConnection(Socket socket, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName)
      Construct a TcpNetConnection for the socket.
      Parameters:
      socket - the socket
      server - 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 interface SchedulingAwareRunnable
    • close

      public void close()
      Closes this connection.
      Specified by:
      close in interface TcpConnection
      Overrides:
      close in class TcpConnectionSupport
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface TcpConnection
      Returns:
      true if the connection is open.
    • send

      public void send(Message<?> message)
      Description copied from interface: TcpConnection
      Converts and sends the message.
      Specified by:
      send in interface TcpConnection
      Parameters:
      message - The message,
    • getPayload

      public Object getPayload()
      Description copied from interface: TcpConnection
      Uses the deserializer to obtain the message payload from the connection's input stream.
      Specified by:
      getPayload in interface TcpConnection
      Returns:
      The payload.
    • getPort

      public int getPort()
      Specified by:
      getPort in interface TcpConnection
      Returns:
      the port
    • getDeserializerStateKey

      public @Nullable Object getDeserializerStateKey()
      Specified by:
      getDeserializerStateKey in interface TcpConnection
      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

      public @Nullable SSLSession getSslSession()
      Specified by:
      getSslSession in interface TcpConnection
      Returns:
      the SSLSession associated with this connection, if SSL is in use, null otherwise.
    • inputStream

      protected InputStream inputStream() throws IOException
      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 the Deserializer and the listener's TcpListener.onMessage(Message) method is called.
      Specified by:
      run in interface Runnable
    • handleReadException

      protected boolean handleReadException(Exception exception)
    • shutdownInput

      public void shutdownInput() throws IOException
      Set the socket's input stream to end of stream.
      Specified by:
      shutdownInput in interface TcpConnection
      Throws:
      IOException - an IO Exception.
      Since:
      5.2
      See Also:
    • shutdownOutput

      public void shutdownOutput() throws IOException
      Disable the socket's output stream.
      Specified by:
      shutdownOutput in interface TcpConnection
      Throws:
      IOException - an IO Exception
      Since:
      5.2
      See Also: