Class AbstractPollingIoAcceptor<S extends AbstractIoSession,​H>

  • Type Parameters:
    H - The type of IoHandler
    S - The type of IoSession
    All Implemented Interfaces:
    IoAcceptor, IoService
    Direct Known Subclasses:
    AprSocketAcceptor, NioSocketAcceptor

    public abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession,​H>
    extends AbstractIoAcceptor
    A base class for implementing transport using a polling strategy. The underlying sockets will be checked in an active loop and woke up when an socket needed to be processed. This class handle the logic behind binding, accepting and disposing the server sockets. An Executor will be used for running client accepting and an AbstractPollingIoProcessor will be used for processing client I/O operations like reading, writing and closing. All the low level methods for binding, accepting, closing need to be provided by the subclassing implementation.
    Author:
    Apache MINA Project
    See Also:
    for a example of implementation
    • Field Detail

      • reuseAddress

        protected boolean reuseAddress
      • backlog

        protected int backlog
        Define the number of socket that can wait to be accepted. Default to 50 (as in the SocketServer default).
    • 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
      • init

        protected abstract void init​(SelectorProvider selectorProvider)
                              throws Exception
        Initialize the polling system, will be called at construction time.
        Parameters:
        selectorProvider - The Selector Provider that will be used by this polling acceptor
        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 IoAcceptor implementation will be disposed.
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • select

        protected abstract int select()
                               throws Exception
        Check for acceptable connections, interrupt when at least a server is ready for accepting. All the ready server socket descriptors need to be returned by selectedHandles()
        Returns:
        The number of sockets having got incoming client
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • wakeup

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

        protected abstract Iterator<H> selectedHandles()
        Iterator for the set of server sockets found with acceptable incoming connections during the last select() call.
        Returns:
        the list of server handles ready
      • open

        protected abstract H open​(SocketAddress localAddress)
                           throws Exception
        Open a server socket for a given local address.
        Parameters:
        localAddress - the associated local address
        Returns:
        the opened server socket
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • localAddress

        protected abstract SocketAddress localAddress​(H handle)
                                               throws Exception
        Get the local address associated with a given server socket
        Parameters:
        handle - the server socket
        Returns:
        the local SocketAddress associated with this handle
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • accept

        protected abstract S accept​(IoProcessor<S> processor,
                                    H handle)
                             throws Exception
        Accept a client connection for a server socket and return a new IoSession associated with the given IoProcessor
        Parameters:
        processor - the IoProcessor to associate with the IoSession
        handle - the server handle
        Returns:
        the created IoSession
        Throws:
        Exception - any exception thrown by the underlying systems calls
      • close

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

        protected void bindRequestAdded()
        Invoked when a bind request has been registered for processing. The default implementation does nothing.
      • unbind0

        protected final void unbind0​(List<? extends SocketAddress> localAddresses)
                              throws Exception
        Implement this method to perform the actual unbind operation.
        Specified by:
        unbind0 in class AbstractIoAcceptor
        Parameters:
        localAddresses - The address to unbind from
        Throws:
        Exception - If the unbind failed
      • processHandles

        protected void processHandles​(Iterator<H> handles)
                               throws Exception
        Handles new incoming connections by accepting the connections and creating new sessions for them.
        Parameters:
        handles - the connection handles to accept and create new sessions for
        Throws:
        Exception - on errors
      • hasUnbindings

        protected boolean hasUnbindings()
        Tells whether there are pending unbindings.
        Returns:
        true if there are any unbindings pending; false otherwise
      • newSession

        public final IoSession newSession​(SocketAddress remoteAddress,
                                          SocketAddress localAddress)
        (Optional) Returns an IoSession that is bound to the specified localAddress and the specified remoteAddress which reuses the local address that is already bound by this service.

        This operation is optional. Please throw UnsupportedOperationException if the transport type doesn't support this operation. This operation is usually implemented for connectionless transport types.

        Parameters:
        remoteAddress - The remote address bound to the service
        localAddress - The local address the session will be bound to
        Returns:
        The session bound to the the given localAddress and remote address
      • getBacklog

        public int getBacklog()
        Returns:
        the backLog
      • setBacklog

        public void setBacklog​(int backlog)
        Sets the Backlog parameter
        Parameters:
        backlog - the backlog variable
      • isReuseAddress

        public boolean isReuseAddress()
        Returns:
        the flag that sets the reuseAddress information
      • setReuseAddress

        public void setReuseAddress​(boolean reuseAddress)
        Set the Reuse Address flag
        Parameters:
        reuseAddress - The flag to set
      • getSessionConfig

        public SocketSessionConfig getSessionConfig()
        Returns:
        the default configuration of the new IoSessions created by this service.