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
AnIoFilter
implementation used to buffer outgoingWriteRequest
almost like whatBufferedOutputStream
does. 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 theProtocolCodecFilter
as it only handlesWriteRequest
's carryingIoBuffer
objects.- 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 int
DEFAULT_BUFFER_SIZE
Default 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 void
exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)
FiltersIoHandler.exceptionCaught(IoSession,Throwable)
event.void
filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
FiltersIoSession.write(Object)
method invocation.void
flush(IoSession session)
Flushes the buffered data.int
getBufferSize()
void
sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoHandler.sessionClosed(IoSession)
event.void
setBufferSize(int bufferSize)
Sets the buffer size but only for the newly created buffers.-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, 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_SIZE
bytes. 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
. IfbuffersMap
is null then a default instance ofConcurrentHashMap
is 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:
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
- ifwriteRequest.message
isn't anIoBuffer
instance.
-
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:
exceptionCaught
in interfaceIoFilter
- Overrides:
exceptionCaught
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 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:
sessionClosed
in interfaceIoFilter
- Overrides:
sessionClosed
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 received this event- Throws:
Exception
- If an error occurred while processing the event
-
-