Class NioSocketAcceptor

    • Field Detail

      • selector

        protected volatile java.nio.channels.Selector selector
      • selectorProvider

        protected volatile java.nio.channels.spi.SelectorProvider selectorProvider
    • Constructor Detail

      • NioSocketAcceptor

        public NioSocketAcceptor()
        Constructor for NioSocketAcceptor using default parameters (multiple thread model).
      • NioSocketAcceptor

        public NioSocketAcceptor​(int processorCount)
        Constructor for NioSocketAcceptor using default parameters, and given number of NioProcessor for multithreading I/O operations.
        Parameters:
        processorCount - the number of processor to create and place in a SimpleIoProcessorPool
      • NioSocketAcceptor

        public NioSocketAcceptor​(IoProcessor<NioSession> processor)
        Constructor for NioSocketAcceptor with default configuration but a specific IoProcessor, useful for sharing the same processor over multiple IoService of the same type.
        Parameters:
        processor - the processor to use for managing I/O events
      • NioSocketAcceptor

        public NioSocketAcceptor​(java.util.concurrent.Executor executor,
                                 IoProcessor<NioSession> processor)
        Constructor for NioSocketAcceptor with a given Executor for handling connection events and a given IoProcessor for handling I/O events, useful for sharing the same processor and executor over multiple IoService of the same type.
        Parameters:
        executor - the executor for connection
        processor - the processor for I/O operations
      • NioSocketAcceptor

        public NioSocketAcceptor​(int processorCount,
                                 java.nio.channels.spi.SelectorProvider selectorProvider)
        Constructor for NioSocketAcceptor using default parameters, and given number of NioProcessor for multithreading I/O operations, and a custom SelectorProvider for NIO
        Parameters:
        processorCount - the number of processor to create and place in a
        selectorProvider - teh SelectorProvider to use SimpleIoProcessorPool
    • Method Detail

      • init

        protected void init()
                     throws java.lang.Exception
        Initialize the polling system, will be called at construction time.
        Specified by:
        init in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Throws:
        java.lang.Exception - any exception thrown by the underlying system calls
      • init

        protected void init​(java.nio.channels.spi.SelectorProvider selectorProvider)
                     throws java.lang.Exception
        Initialize the polling system, will be called at construction time.
        Specified by:
        init in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Parameters:
        selectorProvider - The Selector Provider that will be used by this polling acceptor
        Throws:
        java.lang.Exception - any exception thrown by the underlying system calls
      • destroy

        protected void destroy()
                        throws java.lang.Exception
        Destroy the polling system, will be called when this IoAcceptor implementation will be disposed.
        Specified by:
        destroy in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Throws:
        java.lang.Exception - any exception thrown by the underlying systems calls
      • getLocalAddress

        public java.net.InetSocketAddress getLocalAddress()
        Returns the local address which is bound currently. If more than one address are bound, only one of them will be returned, but it's not necessarily the firstly bound address.
        Specified by:
        getLocalAddress in interface IoAcceptor
        Specified by:
        getLocalAddress in interface SocketAcceptor
        Overrides:
        getLocalAddress in class AbstractIoAcceptor
        Returns:
        The bound LocalAddress
      • open

        protected java.nio.channels.ServerSocketChannel open​(java.net.SocketAddress localAddress)
                                                      throws java.lang.Exception
        Open a server socket for a given local address.
        Specified by:
        open in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Parameters:
        localAddress - the associated local address
        Returns:
        the opened server socket
        Throws:
        java.lang.Exception - any exception thrown by the underlying systems calls
      • localAddress

        protected java.net.SocketAddress localAddress​(java.nio.channels.ServerSocketChannel handle)
                                               throws java.lang.Exception
        Get the local address associated with a given server socket
        Specified by:
        localAddress in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Parameters:
        handle - the server socket
        Returns:
        the local SocketAddress associated with this handle
        Throws:
        java.lang.Exception - any exception thrown by the underlying systems calls
      • select

        protected int select()
                      throws java.lang.Exception
        Check if we have at least one key whose corresponding channels is ready for I/O operations. This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first.
        Specified by:
        select in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Returns:
        The number of keys having their ready-operation set updated
        Throws:
        java.io.IOException - If an I/O error occurs
        java.lang.Exception - any exception thrown by the underlying systems calls
      • close

        protected void close​(java.nio.channels.ServerSocketChannel handle)
                      throws java.lang.Exception
        Close a server socket.
        Specified by:
        close in class AbstractPollingIoAcceptor<NioSession,​java.nio.channels.ServerSocketChannel>
        Parameters:
        handle - the server socket
        Throws:
        java.lang.Exception - any exception thrown by the underlying systems calls