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
Author:
Bela Ban
  • 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 TCP_NIO2 clearConnections(boolean graceful)
      Specified by:
      clearConnections in class BasicTCP
    • isSelectorOpen

      public boolean isSelectorOpen()
    • isAcceptorRunning

      public boolean isAcceptorRunning()
    • numSelects

      public int numSelects()
    • numPartialWrites

      public int numPartialWrites()
    • numDrops

      public int numDrops()
    • readerIdleTime

      public void readerIdleTime(long t)
    • sendUnicast

      public void sendUnicast(PhysicalAddress dest, ByteBuffer data) throws Exception
      Description copied from class: TP
      Send a unicast message to a member. Note that the destination address is a *physical*, not a logical address
      Specified by:
      sendUnicast in class TP
      Parameters:
      dest - Must be a non-null physical unicast address (e.g. IpAddress)
      data - The data to be sent. This is not a copy, so don't modify it
      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()
      Description copied from class: TP
      Returns the physical address of this transport
      Specified by:
      getPhysicalAddress in class TP