Class AbstractPollingIoConnector<S extends AbstractIoSession,​H>

    • Method Detail

      • init

        protected abstract void init()
                              throws Exception
        Initialize the polling system, will be called at construction time.
        Throws:
        Exception - any exception thrown by the underlying system calls
      • destroy

        protected abstract void destroy()
                                 throws Exception
        Destroy the polling system, will be called when this IoConnector implementation will be disposed.
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • newHandle

        protected abstract H newHandle​(SocketAddress localAddress)
                                throws Exception
        Create a new client socket handle from a local SocketAddress
        Parameters:
        localAddress - the socket address for binding the new client socket
        Returns:
        a new client socket handle
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • connect

        protected abstract boolean connect​(H handle,
                                           SocketAddress remoteAddress)
                                    throws Exception
        Connect a newly created client socket handle to a remote SocketAddress. This operation is non-blocking, so at end of the call the socket can be still in connection process.
        Parameters:
        handle - the client socket handle
        remoteAddress - the remote address where to connect
        Returns:
        true if a connection was established, false if this client socket is in non-blocking mode and the connection operation is in progress
        Throws:
        Exception - If the connect failed
      • finishConnect

        protected abstract boolean finishConnect​(H handle)
                                          throws Exception
        Finish the connection process of a client socket after it was marked as ready to process by the select(int) call. The socket will be connected or reported as connection failed.
        Parameters:
        handle - the client socket handle to finish to connect
        Returns:
        true if the socket is connected
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • newSession

        protected abstract S newSession​(IoProcessor<S> processor,
                                        H handle)
                                 throws Exception
        Create a new IoSession from a connected socket client handle. Will assign the created IoSession to the given IoProcessor for managing future I/O events.
        Parameters:
        processor - the processor in charge of this session
        handle - the newly connected client socket handle
        Returns:
        a new IoSession
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • close

        protected abstract void close​(H handle)
                               throws Exception
        Close a client socket.
        Parameters:
        handle - the client socket
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • wakeup

        protected abstract void wakeup()
        Interrupt the select(int) method. Used when the poll set need to be modified.
      • select

        protected abstract int select​(int timeout)
                               throws Exception
        Check for connected sockets, interrupt when at least a connection is processed (connected or failed to connect). All the client socket descriptors processed need to be returned by selectedHandles()
        Parameters:
        timeout - The timeout for the select() method
        Returns:
        The number of socket having received some data
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • selectedHandles

        protected abstract Iterator<H> selectedHandles()
        Iterator for the set of client sockets found connected or failed to connect during the last select(int) call.
        Returns:
        the list of client socket handles to process
      • allHandles

        protected abstract Iterator<H> allHandles()
        Iterator for all the client sockets polled for connection.
        Returns:
        the list of client sockets currently polled for connection
      • connect0

        protected final ConnectFuture connect0​(SocketAddress remoteAddress,
                                               SocketAddress localAddress,
                                               IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
        Implement this method to perform the actual connect operation.
        Specified by:
        connect0 in class AbstractIoConnector
        Parameters:
        remoteAddress - The remote address to connect from
        localAddress - null if no local address is specified
        sessionInitializer - The IoSessionInitializer to use when the connection s successful
        Returns:
        The ConnectFuture associated with this asynchronous operation