org.apache.mina.core.service
Class SimpleIoProcessorPool<T extends AbstractIoSession>

java.lang.Object
  extended by org.apache.mina.core.service.SimpleIoProcessorPool<T>
Type Parameters:
T - the type of the IoSession to be managed by the specified IoProcessor.
All Implemented Interfaces:
IoProcessor<T>

public class SimpleIoProcessorPool<T extends AbstractIoSession>
extends Object
implements IoProcessor<T>

An IoProcessor pool that distributes IoSessions into one or more IoProcessors. Most current transport implementations use this pool internally to perform better in a multi-core environment, and therefore, you won't need to use this pool directly unless you are running multiple IoServices in the same JVM.

If you are running multiple IoServices, you could want to share the pool among all services. To do so, you can create a new SimpleIoProcessorPool instance by yourself and provide the pool as a constructor parameter when you create the services.

This pool uses Java reflection API to create multiple IoProcessor instances. It tries to instantiate the processor in the following order:

  1. A public constructor with one ExecutorService parameter.
  2. A public constructor with one Executor parameter.
  3. A public default constructor
The following is an example for the NIO socket transport:

 // Create a shared pool.
 SimpleIoProcessorPool<NioSession> pool = 
         new SimpleIoProcessorPool<NioSession>(NioProcessor.class, 16);
 
 // Create two services that share the same pool.
 SocketAcceptor acceptor = new NioSocketAcceptor(pool);
 SocketConnector connector = new NioSocketConnector(pool);
 
 ...
 
 // Release related resources.
 connector.dispose();
 acceptor.dispose();
 pool.dispose();
 

Version:
$Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Constructor Summary
SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType)
           
SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, Executor executor)
           
SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, Executor executor, int size)
           
SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, int size)
           
 
Method Summary
 void add(T session)
          Adds the specified session to the I/O processor so that the I/O processor starts to perform any I/O operations related with the session.
 void dispose()
          Releases any resources allocated by this processor.
 void flush(T session)
          Flushes the internal write request queue of the specified session.
 boolean isDisposed()
          Returns true if and if only all resources of this processor have been disposed.
 boolean isDisposing()
          Returns true if and if only IoProcessor.dispose() method has been called.
 void remove(T session)
          Removes and closes the specified session from the I/O processor so that the I/O processor closes the connection associated with the session and releases any other related resources.
 void updateTrafficMask(T session)
          Controls the traffic of the specified session as specified in IoSession.getTrafficMask().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleIoProcessorPool

public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType)

SimpleIoProcessorPool

public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType,
                             int size)

SimpleIoProcessorPool

public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType,
                             Executor executor)

SimpleIoProcessorPool

public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType,
                             Executor executor,
                             int size)
Method Detail

add

public final void add(T session)
Description copied from interface: IoProcessor
Adds the specified session to the I/O processor so that the I/O processor starts to perform any I/O operations related with the session.

Specified by:
add in interface IoProcessor<T extends AbstractIoSession>

flush

public final void flush(T session)
Description copied from interface: IoProcessor
Flushes the internal write request queue of the specified session.

Specified by:
flush in interface IoProcessor<T extends AbstractIoSession>

remove

public final void remove(T session)
Description copied from interface: IoProcessor
Removes and closes the specified session from the I/O processor so that the I/O processor closes the connection associated with the session and releases any other related resources.

Specified by:
remove in interface IoProcessor<T extends AbstractIoSession>

updateTrafficMask

public final void updateTrafficMask(T session)
Description copied from interface: IoProcessor
Controls the traffic of the specified session as specified in IoSession.getTrafficMask().

Specified by:
updateTrafficMask in interface IoProcessor<T extends AbstractIoSession>

isDisposed

public boolean isDisposed()
Description copied from interface: IoProcessor
Returns true if and if only all resources of this processor have been disposed.

Specified by:
isDisposed in interface IoProcessor<T extends AbstractIoSession>

isDisposing

public boolean isDisposing()
Description copied from interface: IoProcessor
Returns true if and if only IoProcessor.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 IoProcessor<T extends AbstractIoSession>

dispose

public final void dispose()
Description copied from interface: IoProcessor
Releases any resources allocated by this processor. Please note that the resources might not be released as long as there are any sessions managed by this processor. Most implementations will close all sessions immediately and release the related resources.

Specified by:
dispose in interface IoProcessor<T extends AbstractIoSession>


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