public class WriteRequestFilter extends IoFilterAdapter
IoEventQueueHandler
to an IoSession
's
WriteRequest
queue to provide accurate write queue status tracking.
The biggest difference from OrderedThreadPoolExecutor
and
UnorderedThreadPoolExecutor
is that IoEventQueueHandler.polled(Object, IoEvent)
is invoked when the write operation is completed by an IoProcessor
,
consequently providing the accurate tracking of the write request queue
status to the IoEventQueueHandler
.
Most common usage of this filter could be detecting an IoSession
which writes too fast which will cause OutOfMemoryError
soon:
session.getFilterChain().addLast( "writeThrottle", new WriteRequestFilter(new IoEventQueueThrottle()));
IoEventQueueHandler
implementation such as IoEventQueueThrottle
in the IoProcessor
thread. It's because an IoProcessor
thread is what processes the WriteRequest
s and notifies related
WriteFuture
s; the IoEventQueueHandler
implementation that
waits for the size of the write request queue to decrease will never wake
up. To use such an handler, you have to insert an ExecutorFilter
before this filter or call IoSession.write(Object)
method always
from a different thread.IoFilter.NextFilter
构造器和说明 |
---|
WriteRequestFilter()
Creates a new instance with a new default
IoEventQueueThrottle . |
WriteRequestFilter(IoEventQueueHandler queueHandler)
Creates a new instance with the specified
IoEventQueueHandler . |
限定符和类型 | 方法和说明 |
---|---|
void |
filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters
IoSession.write(Object) method invocation. |
IoEventQueueHandler |
getQueueHandler() |
destroy, exceptionCaught, filterClose, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened, toString
public WriteRequestFilter()
IoEventQueueThrottle
.public WriteRequestFilter(IoEventQueueHandler queueHandler)
IoEventQueueHandler
.queueHandler
- The IoEventQueueHandler
instance to usepublic IoEventQueueHandler getQueueHandler()
IoEventQueueHandler
which is attached to this
filter.public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws java.lang.Exception
IoFilterAdapter
IoSession.write(Object)
method invocation.filterWrite
在接口中 IoFilter
filterWrite
在类中 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 processjava.lang.Exception
- If an error occurred while processing the event