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 theIoSession
to be managed by the specifiedIoProcessor
.
- All Implemented Interfaces:
IoProcessor<S>
public class SimpleIoProcessorPool<S extends AbstractIoSession> extends Object implements IoProcessor<S>
AnIoProcessor
pool that distributesIoSession
s into one or moreIoProcessor
s. 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 multipleIoService
s in the same JVM.If you are running multiple
IoService
s, you could want to share the pool among all services. To do so, you can create a newSimpleIoProcessorPool
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:- A public constructor with one
ExecutorService
parameter. - A public constructor with one
Executor
parameter. - 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 void
add(S session)
Adds the specifiedsession
to the I/O processor so that the I/O processor starts to perform any I/O operations related with thesession
.void
dispose()
Releases any resources allocated by this processor.void
flush(S session)
Flushes the internal write request queue of the specifiedsession
.boolean
isDisposed()
boolean
isDisposing()
void
remove(S session)
Removes and closes the specifiedsession
from the I/O processor so that the I/O processor closes the connection associated with thesession
and releases any other related resources.void
updateTrafficControl(S session)
Controls the traffic of the specifiedsession
depending of theIoSession.isReadSuspended()
andIoSession.isWriteSuspended()
flagsvoid
write(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
- TheExecutor
size
- The number of IoProcessor in the poolselectorProvider
- The SelectorProvider to used
-
-
Method Detail
-
add
public final void add(S session)
Adds the specifiedsession
to the I/O processor so that the I/O processor starts to perform any I/O operations related with thesession
.- Specified by:
add
in 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:
flush
in 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:
write
in 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 specifiedsession
from the I/O processor so that the I/O processor closes the connection associated with thesession
and releases any other related resources.- Specified by:
remove
in interfaceIoProcessor<S extends AbstractIoSession>
- Parameters:
session
- The session to be removed
-
updateTrafficControl
public final void updateTrafficControl(S session)
Controls the traffic of the specifiedsession
depending of theIoSession.isReadSuspended()
andIoSession.isWriteSuspended()
flags- Specified by:
updateTrafficControl
in interfaceIoProcessor<S extends AbstractIoSession>
- Parameters:
session
- The session to be updated
-
isDisposed
public boolean isDisposed()
- Specified by:
isDisposed
in interfaceIoProcessor<S extends AbstractIoSession>
- Returns:
true
if and if only all resources of this processor have been disposed.
-
isDisposing
public boolean isDisposing()
- Specified by:
isDisposing
in interfaceIoProcessor<S extends AbstractIoSession>
- Returns:
true
if and if onlyIoProcessor.dispose()
method has been called. Please note that this method will returntrue
even 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:
dispose
in interfaceIoProcessor<S extends AbstractIoSession>
-
-