Package org.apache.mina.filter.executor
Class WriteRequestFilter
- java.lang.Object
-
- org.apache.mina.core.filterchain.IoFilterAdapter
-
- org.apache.mina.filter.executor.WriteRequestFilter
-
- All Implemented Interfaces:
IoFilter
public class WriteRequestFilter extends IoFilterAdapter
Attaches anIoEventQueueHandler
to anIoSession
'sWriteRequest
queue to provide accurate write queue status tracking.The biggest difference from
OrderedThreadPoolExecutor
andUnorderedThreadPoolExecutor
is thatIoEventQueueHandler.polled(Object, IoEvent)
is invoked when the write operation is completed by anIoProcessor
, consequently providing the accurate tracking of the write request queue status to theIoEventQueueHandler
.Most common usage of this filter could be detecting an
IoSession
which writes too fast which will causeOutOfMemoryError
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 asIoEventQueueThrottle
in theIoProcessor
thread. It's because anIoProcessor
thread is what processes theWriteRequest
s and notifies relatedWriteFuture
s; theIoEventQueueHandler
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 anExecutorFilter
before this filter or callIoSession.write(Object)
method always from a different thread.- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter
-
-
Constructor Summary
Constructors Constructor Description WriteRequestFilter()
Creates a new instance with a new defaultIoEventQueueThrottle
.WriteRequestFilter(IoEventQueueHandler queueHandler)
Creates a new instance with the specifiedIoEventQueueHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
FiltersIoSession.write(Object)
method invocation.IoEventQueueHandler
getQueueHandler()
-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, exceptionCaught, filterClose, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened, toString
-
-
-
-
Constructor Detail
-
WriteRequestFilter
public WriteRequestFilter()
Creates a new instance with a new defaultIoEventQueueThrottle
.
-
WriteRequestFilter
public WriteRequestFilter(IoEventQueueHandler queueHandler)
Creates a new instance with the specifiedIoEventQueueHandler
.- Parameters:
queueHandler
- TheIoEventQueueHandler
instance to use
-
-
Method Detail
-
getQueueHandler
public IoEventQueueHandler getQueueHandler()
- Returns:
- the
IoEventQueueHandler
which 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:
filterWrite
in interfaceIoFilter
- Overrides:
filterWrite
in classIoFilterAdapter
- Parameters:
nextFilter
- theIoFilter.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.session
- TheIoSession
which has to process this invocationwriteRequest
- TheWriteRequest
to process- Throws:
Exception
- If an error occurred while processing the event
-
-