T - the type of the IoSession to be managed by the specified
IoProcessor.public class SimpleIoProcessorPool<T extends AbstractIoSession> extends Object implements IoProcessor<T>
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:
ExecutorService parameter.Executor parameter.
// 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();
| Constructor and Description |
|---|
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) |
| Modifier and Type | Method and Description |
|---|---|
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 |
updateTrafficControl(T session)
Controls the traffic of the specified
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flags |
public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType)
public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, int size)
public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, Executor executor)
public SimpleIoProcessorPool(Class<? extends IoProcessor<T>> processorType, Executor executor, int size)
public final void add(T session)
IoProcessorsession to the I/O processor so that
the I/O processor starts to perform any I/O operations related
with the session.add in interface IoProcessor<T extends AbstractIoSession>public final void flush(T session)
IoProcessorsession.flush in interface IoProcessor<T extends AbstractIoSession>public final void remove(T session)
IoProcessorsession from the I/O
processor so that the I/O processor closes the connection
associated with the session and releases any other related
resources.remove in interface IoProcessor<T extends AbstractIoSession>public final void updateTrafficControl(T session)
IoProcessorsession depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flagsupdateTrafficControl in interface IoProcessor<T extends AbstractIoSession>public boolean isDisposed()
IoProcessorisDisposed in interface IoProcessor<T extends AbstractIoSession>public boolean isDisposing()
IoProcessorIoProcessor.dispose() method has
been called. Please note that this method will return true
even after all the related resources are released.isDisposing in interface IoProcessor<T extends AbstractIoSession>public final void dispose()
IoProcessordispose in interface IoProcessor<T extends AbstractIoSession>Copyright © 2004–2017. All rights reserved.