Package de.undercouch.bson4jackson.io
Class StaticBuffers
java.lang.Object
de.undercouch.bson4jackson.io.StaticBuffers
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 held
in a
SoftReference so buffers can be freed when they are not needed
anymore.- See Also:
-
BufferRecycler
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteBuffer[]Maps of already allocated re-usable buffersprotected CharBuffer[]protected static final ThreadLocal<SoftReference<StaticBuffers>>A thread-local soft reference to the singleton instance of this classstatic final intAll buffers have a minimum size of 64 kb -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyteBuffer(StaticBuffers.Key key, int minSize) Creates or re-uses aByteBufferthat has a minimum size.charBuffer(StaticBuffers.Key key, int minSize) Creates or re-uses aCharBufferthat has a minimum size.static StaticBuffersvoidreleaseByteBuffer(StaticBuffers.Key key, ByteBuffer buf) Marks a buffer a being re-usable.voidreleaseCharBuffer(StaticBuffers.Key key, CharBuffer buf) Marks a buffer a being re-usable.
-
Field Details
-
GLOBAL_MIN_SIZE
public static final int GLOBAL_MIN_SIZEAll buffers have a minimum size of 64 kb- See Also:
-
_instance
A thread-local soft reference to the singleton instance of this class -
_byteBuffers
Maps of already allocated re-usable buffers -
_charBuffers
-
-
Constructor Details
-
StaticBuffers
protected StaticBuffers()Hidden constructor
-
-
Method Details
-
getInstance
- Returns:
- a thread-local singleton instance of this class
-
charBuffer
Creates or re-uses aCharBufferthat 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 usingreleaseCharBuffer(Key, CharBuffer).- Parameters:
key- the buffer's identifierminSize- the minimum size- Returns:
- the
CharBufferinstance - See Also:
-
releaseCharBuffer
Marks a buffer a being re-usable.- Parameters:
key- the buffer's keybuf- the buffer- See Also:
-
byteBuffer
Creates or re-uses aByteBufferthat 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 usingreleaseByteBuffer(Key, ByteBuffer).- Parameters:
key- the buffer's identifierminSize- the minimum size- Returns:
- the
ByteBufferinstance - See Also:
-
releaseByteBuffer
Marks a buffer a being re-usable.- Parameters:
key- the buffer's keybuf- the buffer- See Also:
-