Class TcpNioConnection

java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpNioConnection
All Implemented Interfaces:
Runnable, TcpConnection
Direct Known Subclasses:
TcpNioSSLConnection

public class TcpNioConnection
extends TcpConnectionSupport
A TcpConnection that uses and underlying SocketChannel.
Since:
2.0
Author:
Gary Russell, John Anderson, Artem Bilan
  • Constructor Details

    • TcpNioConnection

      public TcpNioConnection​(SocketChannel socketChannel, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName)
      Construct a TcpNetConnection for the SocketChannel.
      Parameters:
      socketChannel - The socketChannel.
      server - If true, this connection was created as a result of an incoming request.
      lookupHost - true to perform reverse lookups.
      applicationEventPublisher - The event publisher.
      connectionFactoryName - The name of the connection factory creating this connection.
  • Method Details

    • setPipeTimeout

      public void setPipeTimeout​(long pipeTimeout)
    • close

      public void close()
      Description copied from class: TcpConnectionSupport
      Close this connection.
      Specified by:
      close in interface TcpConnection
      Overrides:
      close in class TcpConnectionSupport
    • isOpen

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

      public void send​(Message<?> message)
      Description copied from interface: TcpConnection
      Converts and sends the message.
      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.
      Returns:
      The payload.
    • getPort

      public int getPort()
      Returns:
      the port
    • getDeserializerStateKey

      public 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 public SSLSession getSslSession()
      Returns:
      the SSLSession associated with this connection, if SSL is in use, null otherwise.
    • inputStream

      protected InputStream inputStream()
      Subclasses can override this, for example to wrap the input stream.
      Returns:
      the input stream.
      Since:
      5.0
    • allocate

      protected ByteBuffer allocate​(int length)
      Allocate a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.
      Parameters:
      length - The buffer length.
      Returns:
      The buffer.
    • run

      public void run()
      If there is no listener, this method exits. When there is a listener, this method assembles data into messages by invoking convertAndSend whenever there is data in the input Stream. Method exits when a message is complete and there is no more data; thus freeing the thread to work on other sockets.
    • sendToPipe

      protected void sendToPipe​(ByteBuffer rawBufferToSend) throws IOException
      Throws:
      IOException
    • readPacket

      public void readPacket()
      Invoked by the factory when there is data to be read.
    • setTaskExecutor

      public void setTaskExecutor​(Executor taskExecutor)
      Parameters:
      taskExecutor - the taskExecutor to set
    • setUsingDirectBuffers

      public void setUsingDirectBuffers​(boolean usingDirectBuffers)
      If true, connection will attempt to use direct buffers where possible.
      Parameters:
      usingDirectBuffers - the usingDirectBuffers to set.
    • isUsingDirectBuffers

      protected boolean isUsingDirectBuffers()
    • getChannelOutputStream

      protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStream getChannelOutputStream()
    • getLastRead

      public long getLastRead()
      Returns:
      Time of last read.
    • setLastRead

      public void setLastRead​(long lastRead)
      Parameters:
      lastRead - The time of the last read.
    • getLastSend

      public long getLastSend()
      Returns:
      the time of the last send
    • shutdownInput

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

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