Class TCP_NIO2

All Implemented Interfaces:
ConnectionListener, Receiver, Lifecycle, DiagnosticsHandler.ProbeHandler

public class TCP_NIO2 extends BasicTCP
Protocol using TCP/IP to send and receive messages. Contrary to TCP, TCP_NIO uses non-blocking I/O (NIO), which eliminates the thread per connection model. Instead, TCP_NIO uses a single selector to poll for incoming messages and dispatches handling of those to a (configurable) thread pool.

Most of the functionality is in NioServer. TCP_NIO sends messages using BaseServer.send(Address,byte[],int,int) and registers with the server to receive messages.

Since:
3.6.5
  • Field Details

    • server

      protected NioServer server
    • max_send_buffers

      protected int max_send_buffers
    • copy_on_partial_write

      protected boolean copy_on_partial_write
    • reader_idle_time

      protected long reader_idle_time
  • Constructor Details

    • TCP_NIO2

      public TCP_NIO2()
  • Method Details

    • getMaxSendBuffers

      public int getMaxSendBuffers()
    • setMaxSendBuffers

      public TCP_NIO2 setMaxSendBuffers(int m)
    • copyOnPartialWrite

      public boolean copyOnPartialWrite()
    • copyOnPartialWrite

      public TCP_NIO2 copyOnPartialWrite(boolean c)
    • getReaderIdleTime

      public long getReaderIdleTime()
    • setReaderIdleTime

      public TCP_NIO2 setReaderIdleTime(long r)
    • getOpenConnections

      public int getOpenConnections()
    • printConnections

      public String printConnections()
      Specified by:
      printConnections in class BasicTCP
    • printBuffers

      public String printBuffers()
    • clearConnections

      public void clearConnections()
    • isSelectorOpen

      public boolean isSelectorOpen()
    • isAcceptorRunning

      public boolean isAcceptorRunning()
    • numSelects

      public int numSelects()
    • numPartialWrites

      public int numPartialWrites()
    • readerIdleTime

      public void readerIdleTime(long t)
    • send

      public void send(Address dest, byte[] data, int offset, int length) throws Exception
      Specified by:
      send in class BasicTCP
      Throws:
      Exception
    • retainAll

      public void retainAll(Collection<Address> members)
      Specified by:
      retainAll in class BasicTCP
    • start

      public void start() throws Exception
      Description copied from class: TP
      Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
      Specified by:
      start in interface Lifecycle
      Overrides:
      start in class TP
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
    • stop

      public void stop()
      Description copied from class: Protocol
      Called on a JChannel.disconnect(); stops work (e.g. by closing multicast socket). Will be called from top to bottom.
      Specified by:
      stop in interface Lifecycle
      Overrides:
      stop in class TP
    • handleConnect

      protected void handleConnect() throws Exception
      Overrides:
      handleConnect in class TP
      Throws:
      Exception
    • handleDisconnect

      protected void handleDisconnect()
      Overrides:
      handleDisconnect in class TP
    • getPhysicalAddress

      protected PhysicalAddress getPhysicalAddress()
      Specified by:
      getPhysicalAddress in class TP