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 anIoEventQueueHandlerto anIoSession'sWriteRequestqueue to provide accurate write queue status tracking.The biggest difference from
OrderedThreadPoolExecutorandUnorderedThreadPoolExecutoris 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
IoSessionwhich writes too fast which will causeOutOfMemoryErrorsoon:session.getFilterChain().addLast( "writeThrottle", new WriteRequestFilter(new IoEventQueueThrottle()));Known issues
You can run into a dead lock if you run this filter with the blockingIoEventQueueHandlerimplementation such asIoEventQueueThrottlein theIoProcessorthread. It's because anIoProcessorthread is what processes theWriteRequests and notifies relatedWriteFutures; theIoEventQueueHandlerimplementation 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 anExecutorFilterbefore 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 voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoSession.write(Object)method invocation.IoEventQueueHandlergetQueueHandler()-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, event, 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- TheIoEventQueueHandlerinstance to use
-
-
Method Detail
-
getQueueHandler
public IoEventQueueHandler 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
-
-