Package org.apache.mina.core.service
Class SimpleIoProcessorPool<S extends AbstractIoSession>
- java.lang.Object
-
- org.apache.mina.core.service.SimpleIoProcessorPool<S>
-
- Type Parameters:
S- the type of theIoSessionto be managed by the specifiedIoProcessor.
- All Implemented Interfaces:
IoProcessor<S>
public class SimpleIoProcessorPool<S extends AbstractIoSession> extends Object implements IoProcessor<S>
AnIoProcessorpool that distributesIoSessions into one or moreIoProcessors. 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 multipleIoServices 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 newSimpleIoProcessorPoolinstance by yourself and provide the pool as a constructor parameter when you create the services.This pool uses Java reflection API to create multiple
IoProcessorinstances. It tries to instantiate the processor in the following order:- A public constructor with one
ExecutorServiceparameter. - A public constructor with one
Executorparameter. - A public default constructor
// 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();- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType)Creates a new instance of SimpleIoProcessorPool with a default size of NbCPUs +1.SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, int size)Creates a new instance of SimpleIoProcessorPool with a defined number of IoProcessors in the poolSimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, int size, SelectorProvider selectorProvider)Creates a new instance of SimpleIoProcessorPool with a defined number of IoProcessors in the poolSimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, Executor executor)Creates a new instance of SimpleIoProcessorPool with an executorSimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, Executor executor, int size, SelectorProvider selectorProvider)Creates a new instance of SimpleIoProcessorPool with an executor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(S session)Adds the specifiedsessionto the I/O processor so that the I/O processor starts to perform any I/O operations related with thesession.voiddispose()Releases any resources allocated by this processor.voidflush(S session)Flushes the internal write request queue of the specifiedsession.booleanisDisposed()booleanisDisposing()voidremove(S session)Removes and closes the specifiedsessionfrom the I/O processor so that the I/O processor closes the connection associated with thesessionand releases any other related resources.voidupdateTrafficControl(S session)Controls the traffic of the specifiedsessiondepending of theIoSession.isReadSuspended()andIoSession.isWriteSuspended()flagsvoidwrite(S session, WriteRequest writeRequest)Writes the WriteRequest for the specifiedsession.
-
-
-
Constructor Detail
-
SimpleIoProcessorPool
public SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType)
Creates a new instance of SimpleIoProcessorPool with a default size of NbCPUs +1.- Parameters:
processorType- The type of IoProcessor to use
-
SimpleIoProcessorPool
public SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, int size)
Creates a new instance of SimpleIoProcessorPool with a defined number of IoProcessors in the pool- Parameters:
processorType- The type of IoProcessor to usesize- The number of IoProcessor in the pool
-
SimpleIoProcessorPool
public SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, int size, SelectorProvider selectorProvider)
Creates a new instance of SimpleIoProcessorPool with a defined number of IoProcessors in the pool- Parameters:
processorType- The type of IoProcessor to usesize- The number of IoProcessor in the poolselectorProvider- The SelectorProvider to use
-
SimpleIoProcessorPool
public SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, Executor executor)
Creates a new instance of SimpleIoProcessorPool with an executor- Parameters:
processorType- The type of IoProcessor to useexecutor- TheExecutor
-
SimpleIoProcessorPool
public SimpleIoProcessorPool(Class<? extends IoProcessor<S>> processorType, Executor executor, int size, SelectorProvider selectorProvider)
Creates a new instance of SimpleIoProcessorPool with an executor- Parameters:
processorType- The type of IoProcessor to useexecutor- TheExecutorsize- The number of IoProcessor in the poolselectorProvider- The SelectorProvider to used
-
-
Method Detail
-
add
public final void add(S session)
Adds the specifiedsessionto the I/O processor so that the I/O processor starts to perform any I/O operations related with thesession.- Specified by:
addin interfaceIoProcessor<S extends AbstractIoSession>- Parameters:
session- The added session
-
flush
public final void flush(S session)
Flushes the internal write request queue of the specifiedsession.- Specified by:
flushin interfaceIoProcessor<S extends AbstractIoSession>- Parameters:
session- The session we want the message to be written
-
write
public final void write(S session, WriteRequest writeRequest)
Writes the WriteRequest for the specifiedsession.- Specified by:
writein interfaceIoProcessor<S extends AbstractIoSession>- Parameters:
session- The session we want the message to be writtenwriteRequest- the WriteRequest to write
-
remove
public final void remove(S session)
Removes and closes the specifiedsessionfrom the I/O processor so that the I/O processor closes the connection associated with thesessionand releases any other related resources.- Specified by:
removein interfaceIoProcessor<S extends AbstractIoSession>- Parameters:
session- The session to be removed
-
updateTrafficControl
public final void updateTrafficControl(S session)
Controls the traffic of the specifiedsessiondepending of theIoSession.isReadSuspended()andIoSession.isWriteSuspended()flags- Specified by:
updateTrafficControlin interfaceIoProcessor<S extends AbstractIoSession>- Parameters:
session- The session to be updated
-
isDisposed
public boolean isDisposed()
- Specified by:
isDisposedin interfaceIoProcessor<S extends AbstractIoSession>- Returns:
trueif and if only all resources of this processor have been disposed.
-
isDisposing
public boolean isDisposing()
- Specified by:
isDisposingin interfaceIoProcessor<S extends AbstractIoSession>- Returns:
trueif and if onlyIoProcessor.dispose()method has been called. Please note that this method will returntrueeven after all the related resources are released.
-
dispose
public final void dispose()
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:
disposein interfaceIoProcessor<S extends AbstractIoSession>
-
-