|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.executor.ExecutorFilter
public class ExecutorFilter
A filter that forwards I/O events to Executor to enforce a certain
thread model while allowing the events per session to be processed
simultaneously. You can apply various thread model by inserting this filter
to a IoFilterChain.
Executor.
If you created this filter using ExecutorFilter(Executor) or similar
constructor that accepts an Executor that you've instantiated, you have
full control and responsibility of managing its life cycle (e.g. calling
ExecutorService.shutdown().
If you created this filter using convenience constructors like
ExecutorFilter(int), then you can shut down the executor by calling
destroy() explicitly.
OrderedThreadPoolExecutor instance. Therefore, the order of event is
maintained like the following:
Executor instance in the constructor,
the order of events are not maintained at all. This means more than one event
handler methods can be invoked at the same time with mixed order. For example,
let's assume that messageReceived, messageSent, and sessionClosed events are
fired.
OrderedThreadPoolExecutor instance or use the convenience constructors.
If you want to submit only a certain set of event types, you can specify them in the constructor. For example, you could configure a thread pool for write operation for the maximum performance:
IoService service = ...;
DefaultIoFilterChainBuilder chain = service.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(...));
// Use one thread pool for most events.
chain.addLast("executor1", new ExecutorFilter());
// and another dedicated thread pool for 'filterWrite' events.
chain.addLast("executor2", new ExecutorFilter(IoEventType.WRITE));
OutOfMemoryErrorIoEventQueueThrottle, which is specified as
a parameter of the convenience constructors.
OrderedThreadPoolExecutor,
UnorderedThreadPoolExecutor| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter |
|---|
IoFilter.NextFilter |
| Constructor Summary | |
|---|---|
ExecutorFilter()
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor, no thread in the pool, and a
maximum of 16 threads in the pool. |
|
ExecutorFilter(Executor executor)
Creates a new instance with the specified Executor. |
|
ExecutorFilter(Executor executor,
IoEventType... eventTypes)
Creates a new instance with the specified Executor. |
|
ExecutorFilter(int maximumPoolSize)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor, no thread in the pool, but
a maximum of threads in the pool is given. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor, a number of thread to start with, a
maximum of threads the pool can contain. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(int maximumPoolSize,
IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
ExecutorFilter(IoEventType... eventTypes)
(Convenience constructor) Creates a new instance with a new OrderedThreadPoolExecutor. |
|
| Method Summary | |
|---|---|
void |
destroy()
Shuts down the underlying executor if this filter hase been created via a convenience constructor. |
void |
exceptionCaught(IoFilter.NextFilter nextFilter,
IoSession session,
Throwable cause)
Filters IoHandler.exceptionCaught(IoSession,Throwable)
event. |
void |
filterClose(IoFilter.NextFilter nextFilter,
IoSession session)
Filters IoSession.close() method invocation. |
void |
filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters IoSession.write(Object) method invocation. |
protected void |
fireEvent(IoFilterEvent event)
Fires the specified event through the underlying executor. |
Executor |
getExecutor()
Returns the underlying Executor instance this filter uses. |
void |
messageReceived(IoFilter.NextFilter nextFilter,
IoSession session,
Object message)
Filters IoHandler.messageReceived(IoSession,Object)
event. |
void |
messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters IoHandler.messageSent(IoSession,Object)
event. |
void |
onPreAdd(IoFilterChain parent,
String name,
IoFilter.NextFilter nextFilter)
A trigger fired when adding this filter in a chain. |
void |
sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
Filters IoHandler.sessionClosed(IoSession) event. |
void |
sessionIdle(IoFilter.NextFilter nextFilter,
IoSession session,
IdleStatus status)
Filters IoHandler.sessionIdle(IoSession,IdleStatus)
event. |
void |
sessionOpened(IoFilter.NextFilter nextFilter,
IoSession session)
Filters IoHandler.sessionOpened(IoSession) event. |
| Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter |
|---|
init, onPostAdd, onPostRemove, onPreRemove, sessionCreated, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ExecutorFilter()
OrderedThreadPoolExecutor, no thread in the pool, and a
maximum of 16 threads in the pool. All the event will be handled
by this default executor.
public ExecutorFilter(int maximumPoolSize)
OrderedThreadPoolExecutor, no thread in the pool, but
a maximum of threads in the pool is given. All the event will be handled
by this default executor.
maximumPoolSize - The maximum number of thread the default executor can
use
public ExecutorFilter(int corePoolSize,
int maximumPoolSize)
OrderedThreadPoolExecutor, a number of thread to start with, a
maximum of threads the pool can contain. All the event will be handled
by this default executor.
corePoolSize - the base number of threads the pool will contain at startupmaximumPoolSize - The maximum number of thread the default executor can
use
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler)
OrderedThreadPoolExecutor.
public ExecutorFilter(IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int maximumPoolSize,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The base number of thread in the poolmaximumPoolSize - The macimum thread contained in the executorkeepAliveTime - The KeepAlive timeout, expressed using the time unitunit - The time unitthreadFactory - queueHandler - eventTypes - The list of events handled by the created executorpublic ExecutorFilter(Executor executor)
Executor.
public ExecutorFilter(Executor executor,
IoEventType... eventTypes)
Executor.
| Method Detail |
|---|
public void destroy()
destroy in interface IoFilterdestroy in class IoFilterAdapterpublic final Executor getExecutor()
Executor instance this filter uses.
Executorprotected void fireEvent(IoFilterEvent event)
public void onPreAdd(IoFilterChain parent,
String name,
IoFilter.NextFilter nextFilter)
throws Exception
onPreAdd in interface IoFilteronPreAdd in class IoFilterAdapterparent - The chain in which we want to inject this filtername - The Fitler's namenextFilter - The next filter in the chain
IllegalArgumentException - If the filter is already present in the chain
Exception
public final void sessionOpened(IoFilter.NextFilter nextFilter,
IoSession session)
IoFilterAdapterIoHandler.sessionOpened(IoSession) event.
sessionOpened in interface IoFiltersessionOpened in class IoFilterAdapter
public final void sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
IoFilterAdapterIoHandler.sessionClosed(IoSession) event.
sessionClosed in interface IoFiltersessionClosed in class IoFilterAdapter
public final void sessionIdle(IoFilter.NextFilter nextFilter,
IoSession session,
IdleStatus status)
IoFilterAdapterIoHandler.sessionIdle(IoSession,IdleStatus)
event.
sessionIdle in interface IoFiltersessionIdle in class IoFilterAdapter
public final void exceptionCaught(IoFilter.NextFilter nextFilter,
IoSession session,
Throwable cause)
IoFilterAdapterIoHandler.exceptionCaught(IoSession,Throwable)
event.
exceptionCaught in interface IoFilterexceptionCaught in class IoFilterAdapter
public final void messageReceived(IoFilter.NextFilter nextFilter,
IoSession session,
Object message)
IoFilterAdapterIoHandler.messageReceived(IoSession,Object)
event.
messageReceived in interface IoFiltermessageReceived in class IoFilterAdapter
public final void messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
IoFilterAdapterIoHandler.messageSent(IoSession,Object)
event.
messageSent in interface IoFiltermessageSent in class IoFilterAdapter
public final void filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
IoFilterAdapterIoSession.write(Object) method invocation.
filterWrite in interface IoFilterfilterWrite in class IoFilterAdapter
public final void filterClose(IoFilter.NextFilter nextFilter,
IoSession session)
throws Exception
IoFilterAdapterIoSession.close() method invocation.
filterClose in interface IoFilterfilterClose in class IoFilterAdapterException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||