Package org.apache.mina.filter.buffer
Class BufferedWriteFilter
- java.lang.Object
-
- org.apache.mina.core.filterchain.IoFilterAdapter
-
- org.apache.mina.filter.buffer.BufferedWriteFilter
-
- All Implemented Interfaces:
IoFilter
public final class BufferedWriteFilter extends IoFilterAdapter
AnIoFilterimplementation used to buffer outgoingWriteRequestalmost like whatBufferedOutputStreamdoes. Using this filter allows to be less dependent from network latency. It is also useful when a session is generating very small messages too frequently and consequently generating unnecessary traffic overhead. Please note that it should always be placed before theProtocolCodecFilteras it only handlesWriteRequest's carryingIoBufferobjects.- Since:
- MINA 2.0.0-M2
- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEDefault buffer size value in bytes.
-
Constructor Summary
Constructors Constructor Description BufferedWriteFilter()Default constructor.BufferedWriteFilter(int bufferSize)Constructor which sets buffer size tobufferSize.Uses a default instance ofConcurrentHashMap.BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession,IoBuffer> buffersMap)Constructor which sets buffer size tobufferSize.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoSession.write(Object)method invocation.voidflush(IoSession session)Flushes the buffered data.intgetBufferSize()voidsessionClosed(IoFilter.NextFilter nextFilter, IoSession session)FiltersIoHandler.sessionClosed(IoSession)event.voidsetBufferSize(int bufferSize)Sets the buffer size but only for the newly created buffers.-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, event, filterClose, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toString
-
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default buffer size value in bytes.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BufferedWriteFilter
public BufferedWriteFilter()
Default constructor. Sets buffer size toDEFAULT_BUFFER_SIZEbytes. Uses a default instance ofConcurrentHashMap.
-
BufferedWriteFilter
public BufferedWriteFilter(int bufferSize)
Constructor which sets buffer size tobufferSize.Uses a default instance ofConcurrentHashMap.- Parameters:
bufferSize- the new buffer size
-
BufferedWriteFilter
public BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession,IoBuffer> buffersMap)Constructor which sets buffer size tobufferSize. IfbuffersMapis null then a default instance ofConcurrentHashMapis created else the provided instance is used.- Parameters:
bufferSize- the new buffer sizebuffersMap- the map to use for storing each session buffer
-
-
Method Detail
-
getBufferSize
public int getBufferSize()
- Returns:
- The buffer size.
-
setBufferSize
public void setBufferSize(int bufferSize)
Sets the buffer size but only for the newly created buffers.- Parameters:
bufferSize- the new buffer size
-
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- ifwriteRequest.messageisn't anIoBufferinstance.
-
flush
public void flush(IoSession session)
Flushes the buffered data.- Parameters:
session- the session where buffer will be written
-
exceptionCaught
public void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.- Specified by:
exceptionCaughtin interfaceIoFilter- Overrides:
exceptionCaughtin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventcause- The exception that cause this event to be received- Throws:
Exception- If an error occurred while processing the event
-
sessionClosed
public void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.sessionClosed(IoSession)event.- Specified by:
sessionClosedin interfaceIoFilter- Overrides:
sessionClosedin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
-