Class TCP_NIO2

  • All Implemented Interfaces:
    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 Detail

      • 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 Detail

      • TCP_NIO2

        public TCP_NIO2()
    • Method Detail

      • 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()
      • printBuffers

        public java.lang.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 java.lang.Exception
        Specified by:
        send in class BasicTCP
        Throws:
        java.lang.Exception
      • retainAll

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

        public void start()
                   throws java.lang.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:
        java.lang.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 java.lang.Exception
        Overrides:
        handleConnect in class TP
        Throws:
        java.lang.Exception
      • handleDisconnect

        protected void handleDisconnect()
        Overrides:
        handleDisconnect in class TP