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()
Returns buffer size.
|
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, filterClose, init, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toStringpublic 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 IoFilterfilterWrite in class IoFilterAdapterException - 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 IoFilterexceptionCaught in class IoFilterAdapterExceptionpublic void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
IoHandler.sessionClosed(IoSession) event.sessionClosed in interface IoFiltersessionClosed in class IoFilterAdapterException