public final class BufferedWriteFilter extends IoFilterAdapter
IoFilter
implementation used to buffer outgoing WriteRequest
almost
like what BufferedOutputStream
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 the ProtocolCodecFilter
as it only handles WriteRequest
's carrying IoBuffer
objects.IoFilter.NextFilter
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE
Default buffer size value in bytes.
|
Constructor and Description |
---|
BufferedWriteFilter()
Default constructor.
|
BufferedWriteFilter(int bufferSize)
Constructor which sets buffer size to
bufferSize .Uses a default
instance of ConcurrentHashMap . |
BufferedWriteFilter(int bufferSize,
LazyInitializedCacheMap<IoSession,IoBuffer> buffersMap)
Constructor which sets buffer size to
bufferSize . |
Modifier and Type | Method and Description |
---|---|
void |
exceptionCaught(IoFilter.NextFilter nextFilter,
IoSession session,
Throwable cause)
Filters
IoHandler.exceptionCaught(IoSession,Throwable) event. |
void |
filterWrite(IoFilter.NextFilter nextFilter,
IoSession session,
WriteRequest writeRequest)
Filters
IoSession.write(Object) method invocation. |
void |
flush(IoSession session)
Flushes the buffered data.
|
int |
getBufferSize() |
void |
sessionClosed(IoFilter.NextFilter nextFilter,
IoSession session)
Filters
IoHandler.sessionClosed(IoSession) event. |
void |
setBufferSize(int bufferSize)
Sets the buffer size but only for the newly created buffers.
|
destroy, event, filterClose, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toString
public static final int DEFAULT_BUFFER_SIZE
public BufferedWriteFilter()
DEFAULT_BUFFER_SIZE
bytes. Uses a default instance of ConcurrentHashMap
.public BufferedWriteFilter(int bufferSize)
bufferSize
.Uses a default
instance of ConcurrentHashMap
.bufferSize
- the new buffer sizepublic BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession,IoBuffer> buffersMap)
bufferSize
. If
buffersMap
is null then a default instance of ConcurrentHashMap
is created else the provided instance is used.bufferSize
- the new buffer sizebuffersMap
- the map to use for storing each session bufferpublic int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize
- the new buffer sizepublic void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
IoSession.write(Object)
method invocation.filterWrite
in interface IoFilter
filterWrite
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has to process this invocationwriteRequest
- The WriteRequest
to processException
- if writeRequest.message
isn't an
IoBuffer
instance.public void flush(IoSession session)
session
- the session where buffer will be writtenpublic void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
IoHandler.exceptionCaught(IoSession,Throwable)
event.exceptionCaught
in interface IoFilter
exceptionCaught
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventcause
- The exception that cause this event to be receivedException
- If an error occurred while processing the eventpublic void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
IoHandler.sessionClosed(IoSession)
event.sessionClosed
in interface IoFilter
sessionClosed
in class IoFilterAdapter
nextFilter
- the IoFilter.NextFilter
for this filter. You can reuse this
object until this filter is removed from the chain.session
- The IoSession
which has received this eventException
- If an error occurred while processing the eventCopyright © 2004–2021 Apache MINA Project. All rights reserved.