Class TcpNetConnection

java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpNetConnection
All Implemented Interfaces:
java.lang.Runnable, TcpConnection, org.springframework.scheduling.SchedulingAwareRunnable

public class TcpNetConnection
extends TcpConnectionSupport
implements org.springframework.scheduling.SchedulingAwareRunnable
A TcpConnection that uses and underlying Socket.
Since:
2.0
  • Constructor Details

    • TcpNetConnection

      public TcpNetConnection​(java.net.Socket socket, boolean server, boolean lookupHost, @Nullable org.springframework.context.ApplicationEventPublisher applicationEventPublisher, java.lang.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 org.springframework.scheduling.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​(org.springframework.messaging.Message<?> message)
      Description copied from interface: TcpConnection
      Converts and sends the message.
      Specified by:
      send in interface TcpConnection
      Parameters:
      message - The message,
    • getPayload

      public java.lang.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

      @Nullable public java.lang.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

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

      protected java.io.InputStream inputStream() throws java.io.IOException
      Subclasses can override this, for example to wrap the input stream.
      Returns:
      the input stream.
      Throws:
      java.io.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 java.lang.Runnable
    • handleReadException

      protected boolean handleReadException​(java.lang.Exception exception)
    • shutdownInput

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

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