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

  An `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.
  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 and Description
    --- | ---
    `static int` | `DEFAULT_BUFFER_SIZE` Default buffer size value in bytes.

  - ### Constructor Summary

    Constructors
    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`.

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter

      `destroy, filterClose, init, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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 to `DEFAULT_BUFFER_SIZE` bytes. Uses a default instance of `ConcurrentHashMap`.

    - #### BufferedWriteFilter

          public BufferedWriteFilter(int bufferSize)

      Constructor which sets buffer size to `bufferSize`.Uses a default instance of `ConcurrentHashMap`.
      Parameters:
        `bufferSize` - the new buffer size

    - #### BufferedWriteFilter

          public BufferedWriteFilter(int bufferSize,
                             LazyInitializedCacheMap<IoSession,IoBuffer> buffersMap)

      Constructor which sets buffer size to `bufferSize`. If `buffersMap` is null then a default instance of `ConcurrentHashMap` is created else the provided instance is used.
      Parameters:
        `bufferSize` - the new buffer size
        `buffersMap` - the map to use for storing each session buffer

  - ### Method Detail

    - #### getBufferSize

          public int getBufferSize()

      Returns 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

      Filters `IoSession.write(Object)` method invocation.
      Specified by:
        `filterWrite` in interface `IoFilter`
      Overrides:
        `filterWrite` in class `IoFilterAdapter`
      Throws:
        `Exception` - if `writeRequest.message` isn't an `IoBuffer` 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

      Filters `IoHandler.exceptionCaught(IoSession,Throwable)` event.
      Specified by:
        `exceptionCaught` in interface `IoFilter`
      Overrides:
        `exceptionCaught` in class `IoFilterAdapter`
      Throws:
        `Exception`

    - #### sessionClosed

          public void sessionClosed(IoFilter.NextFilter nextFilter,
                           IoSession session)
                             throws Exception

      Filters `IoHandler.sessionClosed(IoSession)` event.
      Specified by:
        `sessionClosed` in interface `IoFilter`
      Overrides:
        `sessionClosed` in class `IoFilterAdapter`
      Throws:
        `Exception`

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.