de.undercouch.bson4jackson.io
Class StaticBuffers

java.lang.Object
  extended by de.undercouch.bson4jackson.io.StaticBuffers

public class StaticBuffers
extends java.lang.Object

Keeps thread-local re-usable buffers. Each buffer is identified by a key. This class is a singleton, whereas the reference to the instance is hold in a SoftReference so buffers can be freed when they are not needed anymore.

See Also:
BufferRecycler

Nested Class Summary
static class StaticBuffers.Key
          Possible buffer keys
 
Field Summary
static int GLOBAL_MIN_SIZE
          All buffers have a minimum size of 64 kb
 
Method Summary
 java.nio.ByteBuffer byteBuffer(StaticBuffers.Key key, int minSize)
           
 java.nio.CharBuffer charBuffer(StaticBuffers.Key key, int minSize)
          Creates or re-uses a CharBuffer that has a minimum size.
static StaticBuffers getInstance()
           
 void releaseByteBuffer(StaticBuffers.Key key, java.nio.ByteBuffer buf)
           
 void releaseCharBuffer(StaticBuffers.Key key, java.nio.CharBuffer buf)
          Marks a buffer a being re-usable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBAL_MIN_SIZE

public static final int GLOBAL_MIN_SIZE
All buffers have a minimum size of 64 kb

See Also:
Constant Field Values
Method Detail

getInstance

public static StaticBuffers getInstance()
Returns:
a thread-local singleton instance of this class

charBuffer

public java.nio.CharBuffer charBuffer(StaticBuffers.Key key,
                                      int minSize)
Creates or re-uses a CharBuffer that has a minimum size. Calling this method multiple times with the same key will always return the same buffer, as long as it has the minimum size and is marked to be re-used. Buffers that are allowed to be re-used should be released using releaseCharBuffer(Key, CharBuffer).

Parameters:
key - the buffer's identifier
minSize - the minimum size
Returns:
the CharBuffer instance

releaseCharBuffer

public void releaseCharBuffer(StaticBuffers.Key key,
                              java.nio.CharBuffer buf)
Marks a buffer a being re-usable.

Parameters:
key - the buffer's key
buf - the buffer

byteBuffer

public java.nio.ByteBuffer byteBuffer(StaticBuffers.Key key,
                                      int minSize)
See Also:
charBuffer(Key, int)

releaseByteBuffer

public void releaseByteBuffer(StaticBuffers.Key key,
                              java.nio.ByteBuffer buf)
See Also:
releaseCharBuffer(Key, CharBuffer)