|
||||||||||
| 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)
Invoked before this filter is added to the specified parent. |
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 pool size
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 initial pool sizemaximumPoolSize - The maximum pool size
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive value
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuequeueHandler - The queue used to store events
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threads
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threadsqueueHandler - The queue used to store eventspublic ExecutorFilter(IoEventType... eventTypes)
OrderedThreadPoolExecutor.
eventTypes - The event for which the executor will be used
public ExecutorFilter(int maximumPoolSize,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
maximumPoolSize - The maximum pool sizeeventTypes - The event for which the executor will be used
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizeeventTypes - The event for which the executor will be used
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valueeventTypes - The event for which the executor will be used
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuequeueHandler - The queue used to store eventseventTypes - The event for which the executor will be used
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threadseventTypes - The event for which the executor will be used
public ExecutorFilter(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
ThreadFactory threadFactory,
IoEventQueueHandler queueHandler,
IoEventType... eventTypes)
OrderedThreadPoolExecutor.
corePoolSize - The initial pool sizemaximumPoolSize - The maximum pool sizekeepAliveTime - Default duration for a threadunit - Time unit used for the keepAlive valuethreadFactory - The factory used to create threadsqueueHandler - The queue used to store eventseventTypes - The event for which the executor will be usedpublic ExecutorFilter(Executor executor)
Executor.
executor - the user's managed Executor to use in this filter
public ExecutorFilter(Executor executor,
IoEventType... eventTypes)
Executor.
executor - the user's managed Executor to use in this filtereventTypes - The event for which the executor will be used| 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)
event - The filtered event
public void onPreAdd(IoFilterChain parent,
String name,
IoFilter.NextFilter nextFilter)
throws Exception
IoFilter.init() is invoked.
onPreAdd in interface IoFilteronPreAdd in class IoFilterAdapterparent - the parent who called this methodname - the name assigned to this filternextFilter - the IoFilter.NextFilter for this filter. You can reuse
this object until this filter is removed from the chain.
Exception
public final void sessionOpened(IoFilter.NextFilter nextFilter,
IoSession session)
IoHandler.sessionOpened(IoSession) event.
sessionOpened in interface IoFiltersessionOpened in class IoFilterAdapter
public final void sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
IoHandler.sessionClosed(IoSession) event.
sessionClosed in interface IoFiltersessionClosed in class IoFilterAdapter
public final void sessionIdle(IoFilter.NextFilter nextFilter,
IoSession session,
IdleStatus status)
IoHandler.sessionIdle(IoSession,IdleStatus)
event.
sessionIdle in interface IoFiltersessionIdle in class IoFilterAdapter
public final void exceptionCaught(IoFilter.NextFilter nextFilter,
IoSession session,
Throwable cause)
IoHandler.exceptionCaught(IoSession,Throwable)
event.
exceptionCaught in interface IoFilterexceptionCaught in class IoFilterAdapter
public final void messageReceived(IoFilter.NextFilter nextFilter,
IoSession session,
Object message)
IoHandler.messageReceived(IoSession,Object)
event.
messageReceived in interface IoFiltermessageReceived in class IoFilterAdapter
public final void messageSent(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
IoHandler.messageSent(IoSession,Object)
event.
messageSent in interface IoFiltermessageSent in class IoFilterAdapter
public final void filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
IoSession.write(Object) method invocation.
filterWrite in interface IoFilterfilterWrite in class IoFilterAdapter
public final void filterClose(IoFilter.NextFilter nextFilter,
IoSession session)
throws Exception
IoSession.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 | |||||||||