org.apache.mina.core.polling

## Class AbstractPollingIoAcceptor<S extends AbstractIoSession,H>

- java.lang.Object
- - org.apache.mina.core.service.AbstractIoService
  - - org.apache.mina.core.service.AbstractIoAcceptor
    - - org.apache.mina.core.polling.AbstractPollingIoAcceptor<S,H>

- 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`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoAcceptor

      `AbstractIoAcceptor.AcceptorOperationFuture`

    - ### Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoService

      `AbstractIoService.ServiceOperationFuture`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `backlog` Define the number of socket that can wait to be accepted.
    `protected boolean` | `reuseAddress`

    - ### Fields inherited from class org.apache.mina.core.service.AbstractIoAcceptor

      `bindLock`

    - ### Fields inherited from class org.apache.mina.core.service.AbstractIoService

      `disposalLock`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass)` Constructor for `AbstractPollingIoAcceptor`.
    `protected` | `AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass, int processorCount)` Constructor for `AbstractPollingIoAcceptor`.
    `protected` | `AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor)` Constructor for `AbstractPollingIoAcceptor`.
    `protected` | `AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, IoProcessor<S> processor)` Constructor for `AbstractPollingIoAcceptor`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract S` | `accept(IoProcessor<S> processor, H handle)` Accept a client connection for a server socket and return a new `IoSession` associated with the given `IoProcessor`
    `protected Set<SocketAddress>` | `bindInternal(List<? extends SocketAddress> localAddresses)` Starts the acceptor, and register the given addresses
    `protected abstract void` | `close(H handle)` Close a server socket.
    `protected abstract void` | `destroy()` Destroy the polling system, will be called when this `IoAcceptor` implementation will be disposed.
    `protected void` | `dispose0()` Implement this method to release any acquired resources.
    `int` | `getBacklog()`
    `protected abstract void` | `init()` Initialize the polling system, will be called at construction time.
    `boolean` | `isReuseAddress()`
    `protected abstract SocketAddress` | `localAddress(H handle)` Get the local address associated with a given server socket
    `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.
    `protected abstract H` | `open(SocketAddress localAddress)` Open a server socket for a given local address.
    `protected abstract int` | `select()` Check for acceptable connections, interrupt when at least a server is ready for accepting.
    `protected abstract Iterator<H>` | `selectedHandles()` `Iterator` for the set of server sockets found with acceptable incoming connections during the last `select()` call.
    `void` | `setBacklog(int backlog)`
    `void` | `setReuseAddress(boolean reuseAddress)`
    `protected void` | `unbind0(List<? extends SocketAddress> localAddresses)` Implement this method to perform the actual unbind operation.
    `protected abstract void` | `wakeup()` Interrupt the `select()` method.

    - ### Methods inherited from class org.apache.mina.core.service.AbstractIoAcceptor

      `bind, bind, bind, bind, bind, getDefaultLocalAddress, getDefaultLocalAddresses, getLocalAddress, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, toString, unbind, unbind, unbind, unbind`

    - ### Methods inherited from class org.apache.mina.core.service.AbstractIoService

      `addListener, broadcast, dispose, dispose, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.mina.core.service.IoService

      `addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, getTransportMetadata, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory`

- - ### 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).

  - ### Constructor Detail

    - #### AbstractPollingIoAcceptor

          protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
                                   Class<? extends IoProcessor<S>> processorClass)

      Constructor for `AbstractPollingIoAcceptor`. You need to provide a default session configuration, a class of `IoProcessor` which will be instantiated in a `SimpleIoProcessorPool` for better scaling in multiprocessor systems. The default pool size will be used.
      Parameters:
        `sessionConfig` - the default configuration for the managed `IoSession`
        `processorClass` - a `Class` of `IoProcessor` for the associated `IoSession` type.
      See Also:
        `SimpleIoProcessorPool`

    - #### AbstractPollingIoAcceptor

          protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
                                   Class<? extends IoProcessor<S>> processorClass,
                                   int processorCount)

      Constructor for `AbstractPollingIoAcceptor`. You need to provide a default session configuration, a class of `IoProcessor` which will be instantiated in a `SimpleIoProcessorPool` for using multiple thread for better scaling in multiprocessor systems.
      Parameters:
        `sessionConfig` - the default configuration for the managed `IoSession`
        `processorClass` - a `Class` of `IoProcessor` for the associated `IoSession` type.
        `processorCount` - the amount of processor to instantiate for the pool
      See Also:
        `SimpleIoProcessorPool`

    - #### AbstractPollingIoAcceptor

          protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
                                   IoProcessor<S> processor)

      Constructor for `AbstractPollingIoAcceptor`. You need to provide a default session configuration, a default `Executor` will be created using `Executors.newCachedThreadPool()`. `AbstractIoService#AbstractIoService(IoSessionConfig, Executor)`
      Parameters:
        `sessionConfig` - the default configuration for the managed `IoSession`
        `processor` - the `IoProcessor` for processing the `IoSession` of this transport, triggering events to the bound `IoHandler` and processing the chains of `IoFilter`

    - #### AbstractPollingIoAcceptor

          protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
                                   Executor executor,
                                   IoProcessor<S> processor)

      Constructor for `AbstractPollingIoAcceptor`. You need to provide a default session configuration and an `Executor` for handling I/O events. If a null `Executor` is provided, a default one will be created using `Executors.newCachedThreadPool()`. `AbstractIoService#AbstractIoService(IoSessionConfig, Executor)`
      Parameters:
        `sessionConfig` - the default configuration for the managed `IoSession`
        `executor` - the `Executor` used for handling asynchronous execution of I/O events. Can be `null`.
        `processor` - the `IoProcessor` for processing the `IoSession` of this transport, triggering events to the bound `IoHandler` and processing the chains of `IoFilter`

  - ### 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 `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

    - #### dispose0

          protected void dispose0()
                           throws Exception

      Implement this method to release any acquired resources. This method is invoked only once by `AbstractIoService.dispose()`.
      Specified by:
        `dispose0` in class `AbstractIoService`
      Throws:
        `Exception`

    - #### bindInternal

          protected final Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses)
                                                   throws Exception

      Starts the acceptor, and register the given addresses
      Specified by:
        `bindInternal` in class `AbstractIoAcceptor`
      Returns:
        the `Set` of the local addresses which is bound actually
      Throws:
        `Exception`

    - #### 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`
      Throws:
        `Exception`

    - #### 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.

    - #### getBacklog

          public int getBacklog()

    - #### setBacklog

          public void setBacklog(int backlog)

    - #### isReuseAddress

          public boolean isReuseAddress()

    - #### setReuseAddress

          public void setReuseAddress(boolean reuseAddress)

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.