Class WriteRequestFilter
java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.executor.WriteRequestFilter
- All Implemented Interfaces:
IoFilter
Attaches an
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()));
Known issues
You can run into a dead lock if you run this filter with the blockingIoEventQueueHandler implementation such as IoEventQueueThrottle
in the IoProcessor thread. It's because an IoProcessor
thread is what processes the WriteRequests and notifies related
WriteFutures; 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.-
Nested Class Summary
Nested classes/interfaces inherited from interface IoFilter
IoFilter.NextFilter -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with a new defaultIoEventQueueThrottle.WriteRequestFilter(IoEventQueueHandler queueHandler) Creates a new instance with the specifiedIoEventQueueHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) FiltersIoSession.write(Object)method invocation.Methods inherited from class IoFilterAdapter
destroy, event, exceptionCaught, filterClose, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened, toString
-
Field Details
-
queueHandler
-
-
Constructor Details
-
WriteRequestFilter
public WriteRequestFilter()Creates a new instance with a new defaultIoEventQueueThrottle. -
WriteRequestFilter
Creates a new instance with the specifiedIoEventQueueHandler.- Parameters:
queueHandler- TheIoEventQueueHandlerinstance to use
-
-
Method Details
-
getQueueHandler
- Returns:
- the
IoEventQueueHandlerwhich is attached to this filter.
-
filterWrite
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception FiltersIoSession.write(Object)method invocation.- Specified by:
filterWritein interfaceIoFilter- Overrides:
filterWritein classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this invocationwriteRequest- TheWriteRequestto process- Throws:
Exception- If an error occurred while processing the event
-