public class ExecutorFilter extends IoFilterAdapter
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));
OutOfMemoryError
IoEventQueueThrottle
, which is specified as
a parameter of the convenience constructors.OrderedThreadPoolExecutor
,
UnorderedThreadPoolExecutor
IoFilter.NextFilter
Constructor and Description |
---|
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 . |
event, init, inputClosed, onPostAdd, onPostRemove, onPreRemove, sessionCreated, toString
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 sizepublic 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 sizepublic 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 valuepublic 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 eventspublic 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 threadspublic 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 usedpublic ExecutorFilter(int maximumPoolSize, IoEventType... eventTypes)
OrderedThreadPoolExecutor
.maximumPoolSize
- The maximum pool sizeeventTypes
- The event for which the executor will be usedpublic 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 usedpublic 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 usedpublic 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 usedpublic 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 usedpublic 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 filterpublic 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 usedpublic void destroy()
destroy
in interface IoFilter
destroy
in class IoFilterAdapter
public final Executor getExecutor()
Executor
instance this filter uses.protected void fireEvent(IoFilterEvent event)
event
- The filtered eventpublic void onPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
IoFilter.init()
is invoked.onPreAdd
in interface IoFilter
onPreAdd
in class IoFilterAdapter
parent
- 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
- If an error occurred while processing the eventpublic final void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session)
IoHandler.sessionOpened(IoSession)
event.sessionOpened
in interface IoFilter
sessionOpened
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventpublic final void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
IoHandler.sessionClosed(IoSession)
event.sessionClosed
in interface IoFilter
sessionClosed
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventpublic final void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status)
IoHandler.sessionIdle(IoSession,IdleStatus)
event.sessionIdle
in interface IoFilter
sessionIdle
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventstatus
- The IdleStatus
typepublic final void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)
IoHandler.exceptionCaught(IoSession,Throwable)
event.exceptionCaught
in interface IoFilter
exceptionCaught
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventcause
- The exception that cause this event to be receivedpublic final void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)
IoHandler.messageReceived(IoSession,Object)
event.messageReceived
in interface IoFilter
messageReceived
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventmessage
- The received messagepublic final void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
IoHandler.messageSent(IoSession,Object)
event.messageSent
in interface IoFilter
messageSent
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventwriteRequest
- The WriteRequest
that contains the sent messagepublic final void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
IoSession.write(Object)
method invocation.filterWrite
in interface IoFilter
filterWrite
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has to process this invocationwriteRequest
- The WriteRequest
to processpublic final void filterClose(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
IoSession.closeNow()
or a IoSession.closeOnFlush()
method invocations.filterClose
in interface IoFilter
filterClose
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has to process this method
invocationException
- If an error occurred while processing the eventCopyright © 2004–2021 Apache MINA Project. All rights reserved.