org.apache.mina.core.service

## Class AbstractIoService

- java.lang.Object
- - org.apache.mina.core.service.AbstractIoService

- All Implemented Interfaces:
    IoService
  Direct Known Subclasses:
    AbstractIoAcceptor, AbstractIoConnector

      public abstract class AbstractIoService
      extends Object
      implements IoService

  Base implementation of `IoService`s. An instance of IoService contains an Executor which will handle the incoming events.
  Author:
    Apache MINA Project

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `AbstractIoService.ServiceOperationFuture`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Object` | `disposalLock` A lock object which must be acquired when related resources are destroyed.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractIoService(IoSessionConfig sessionConfig, Executor executor)` Constructor for `AbstractIoService`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addListener(IoServiceListener listener)` Adds an `IoServiceListener` that listens any events related with this service.
    `Set<WriteFuture>` | `broadcast(Object message)` Writes the specified `message` to all the `IoSession`s managed by this service.
    `void` | `dispose()` Releases any resources allocated by this service.
    `void` | `dispose(boolean awaitTermination)` Releases any resources allocated by this service.
    `protected abstract void` | `dispose0()` Implement this method to release any acquired resources.
    `protected void` | `executeWorker(Runnable worker)`
    `protected void` | `executeWorker(Runnable worker, String suffix)`
    `protected void` | `finishSessionInitialization0(IoSession session, IoFuture future)` Implement this method to perform additional tasks required for session initialization.
    `long` | `getActivationTime()` Returns the time when this service was activated.
    `DefaultIoFilterChainBuilder` | `getFilterChain()` A shortcut for `( ( DefaultIoFilterChainBuilder )` `IoService.getFilterChainBuilder()``)`.
    `IoFilterChainBuilder` | `getFilterChainBuilder()` Returns the `IoFilterChainBuilder` which will build the `IoFilterChain` of all `IoSession`s which is created by this service.
    `IoHandler` | `getHandler()` Returns the handler which will handle all connections managed by this service.
    `IoServiceListenerSupport` | `getListeners()`
    `int` | `getManagedSessionCount()` Returns the number of all sessions which are currently managed by this service.
    `Map<Long,IoSession>` | `getManagedSessions()` Returns the map of all sessions which are currently managed by this service.
    `int` | `getScheduledWriteBytes()` Returns the number of bytes scheduled to be written
    `int` | `getScheduledWriteMessages()` Returns the number of messages scheduled to be written
    `IoSessionConfig` | `getSessionConfig()` Returns the default configuration of the new `IoSession`s created by this service.
    `IoSessionDataStructureFactory` | `getSessionDataStructureFactory()` Returns the `IoSessionDataStructureFactory` that provides related data structures for a new session created by this service.
    `IoServiceStatistics` | `getStatistics()` Returns the IoServiceStatistics object for this service.
    `protected void` | `initSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)`
    `boolean` | `isActive()` Returns a value of whether or not this service is active
    `boolean` | `isDisposed()` Returns `true` if and if only all resources of this processor have been disposed.
    `boolean` | `isDisposing()` Returns `true` if and if only `IoService.dispose()` method has been called.
    `void` | `removeListener(IoServiceListener listener)` Removed an existing `IoServiceListener` that listens any events related with this service.
    `void` | `setFilterChainBuilder(IoFilterChainBuilder builder)` Sets the `IoFilterChainBuilder` which will build the `IoFilterChain` of all `IoSession`s which is created by this service.
    `void` | `setHandler(IoHandler handler)` Sets the handler which will handle all connections managed by this service.
    `void` | `setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)` Sets the `IoSessionDataStructureFactory` that provides related data structures for a new session created by this service.

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

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

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

      `getTransportMetadata`

- - ### Field Detail

    - #### disposalLock

          protected final Object disposalLock

      A lock object which must be acquired when related resources are destroyed.

  - ### Constructor Detail

    - #### AbstractIoService

          protected AbstractIoService(IoSessionConfig sessionConfig,
                           Executor executor)

      Constructor for `AbstractIoService`. 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()`.
      Parameters:
        `sessionConfig` - the default configuration for the managed `IoSession`
        `executor` - the `Executor` used for handling execution of I/O events. Can be `null`.

  - ### Method Detail

    - #### getFilterChainBuilder

          public final IoFilterChainBuilder getFilterChainBuilder()

      Returns the `IoFilterChainBuilder` which will build the `IoFilterChain` of all `IoSession`s which is created by this service. The default value is an empty `DefaultIoFilterChainBuilder`.
      Specified by:
        `getFilterChainBuilder` in interface `IoService`

    - #### setFilterChainBuilder

          public final void setFilterChainBuilder(IoFilterChainBuilder builder)

      Sets the `IoFilterChainBuilder` which will build the `IoFilterChain` of all `IoSession`s which is created by this service. If you specify `null` this property will be set to an empty `DefaultIoFilterChainBuilder`.
      Specified by:
        `setFilterChainBuilder` in interface `IoService`

    - #### getFilterChain

          public final DefaultIoFilterChainBuilder getFilterChain()

      A shortcut for `( ( DefaultIoFilterChainBuilder )` `IoService.getFilterChainBuilder()``)`. Please note that the returned object is not a real `IoFilterChain` but a `DefaultIoFilterChainBuilder`. Modifying the returned builder won't affect the existing `IoSession`s at all, because `IoFilterChainBuilder`s affect only newly created `IoSession`s.
      Specified by:
        `getFilterChain` in interface `IoService`

    - #### addListener

          public final void addListener(IoServiceListener listener)

      Adds an `IoServiceListener` that listens any events related with this service.
      Specified by:
        `addListener` in interface `IoService`

    - #### removeListener

          public final void removeListener(IoServiceListener listener)

      Removed an existing `IoServiceListener` that listens any events related with this service.
      Specified by:
        `removeListener` in interface `IoService`

    - #### isActive

          public final boolean isActive()

      Returns a value of whether or not this service is active
      Specified by:
        `isActive` in interface `IoService`
      Returns:
        whether of not the service is active.

    - #### isDisposing

          public final boolean isDisposing()

      Returns `true` if and if only `IoService.dispose()` method has been called. Please note that this method will return `true` even after all the related resources are released.
      Specified by:
        `isDisposing` in interface `IoService`

    - #### isDisposed

          public final boolean isDisposed()

      Returns `true` if and if only all resources of this processor have been disposed.
      Specified by:
        `isDisposed` in interface `IoService`

    - #### dispose

          public final void dispose()

      Releases any resources allocated by this service. Please note that this method might block as long as there are any sessions managed by this service.
      Specified by:
        `dispose` in interface `IoService`

    - #### dispose

          public final void dispose(boolean awaitTermination)

      Releases any resources allocated by this service. Please note that this method might block as long as there are any sessions managed by this service. Warning : calling this method from a IoFutureListener with `awaitTermination` = true will probably lead to a deadlock.
      Specified by:
        `dispose` in interface `IoService`
      Parameters:
        `awaitTermination` - When true this method will block until the underlying ExecutorService is terminated

    - #### dispose0

          protected abstract void dispose0()
                                    throws Exception

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

    - #### getManagedSessions

          public final Map<Long,IoSession> getManagedSessions()

      Returns the map of all sessions which are currently managed by this service. The key of map is the `ID` of the session.
      Specified by:
        `getManagedSessions` in interface `IoService`
      Returns:
        the sessions. An empty collection if there's no session.

    - #### getManagedSessionCount

          public final int getManagedSessionCount()

      Returns the number of all sessions which are currently managed by this service.
      Specified by:
        `getManagedSessionCount` in interface `IoService`

    - #### getHandler

          public final IoHandler getHandler()

      Returns the handler which will handle all connections managed by this service.
      Specified by:
        `getHandler` in interface `IoService`

    - #### setHandler

          public final void setHandler(IoHandler handler)

      Sets the handler which will handle all connections managed by this service.
      Specified by:
        `setHandler` in interface `IoService`

    - #### getSessionConfig

          public IoSessionConfig getSessionConfig()

      Returns the default configuration of the new `IoSession`s created by this service.
      Specified by:
        `getSessionConfig` in interface `IoService`

    - #### getSessionDataStructureFactory

          public final IoSessionDataStructureFactory getSessionDataStructureFactory()

      Returns the `IoSessionDataStructureFactory` that provides related data structures for a new session created by this service.
      Specified by:
        `getSessionDataStructureFactory` in interface `IoService`

    - #### setSessionDataStructureFactory

          public final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)

      Sets the `IoSessionDataStructureFactory` that provides related data structures for a new session created by this service.
      Specified by:
        `setSessionDataStructureFactory` in interface `IoService`

    - #### getStatistics

          public IoServiceStatistics getStatistics()

      Returns the IoServiceStatistics object for this service.
      Specified by:
        `getStatistics` in interface `IoService`
      Returns:
        The statistics object for this service.

    - #### getActivationTime

          public final long getActivationTime()

      Returns the time when this service was activated. It returns the last time when this service was activated if the service is not active now.
      Specified by:
        `getActivationTime` in interface `IoService`
      Returns:
        The time by using `System.currentTimeMillis()`

    - #### broadcast

          public final Set<WriteFuture> broadcast(Object message)

      Writes the specified `message` to all the `IoSession`s managed by this service. This method is a convenience shortcut for `IoUtil.broadcast(Object, Collection)`.
      Specified by:
        `broadcast` in interface `IoService`

    - #### getListeners

          public final IoServiceListenerSupport getListeners()

    - #### executeWorker

          protected final void executeWorker(Runnable worker)

    - #### executeWorker

          protected final void executeWorker(Runnable worker,
                           String suffix)

    - #### initSession

          protected final void initSession(IoSession session,
                         IoFuture future,
                         IoSessionInitializer sessionInitializer)

    - #### finishSessionInitialization0

          protected void finishSessionInitialization0(IoSession session,
                                          IoFuture future)

      Implement this method to perform additional tasks required for session initialization. Do not call this method directly; `initSession(IoSession, IoFuture, IoSessionInitializer)` will call this method instead.

    - #### getScheduledWriteBytes

          public int getScheduledWriteBytes()

      Returns the number of bytes scheduled to be written
      Specified by:
        `getScheduledWriteBytes` in interface `IoService`
      Returns:
        The number of bytes scheduled to be written

    - #### getScheduledWriteMessages

          public int getScheduledWriteMessages()

      Returns the number of messages scheduled to be written
      Specified by:
        `getScheduledWriteMessages` in interface `IoService`
      Returns:
        The number of messages scheduled to be written

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