public class BufferRecycler extends Object implements RecyclerPool.WithPool<BufferRecycler>
RecyclerPool
(starting with 2.16): multiple pool
implementations exists.
The default pool implementation uses
ThreadLocal
combined with SoftReference
.
The end result is a low-overhead GC-cleanable recycling: hopefully
ideal for use by stream readers.
Rewritten in 2.10 to be thread-safe (see [jackson-core#479] for details),
to not rely on ThreadLocal
access.
Rewritten in 2.16 to work with RecyclerPool
abstraction.
Modifier and Type | Class and Description |
---|---|
static interface |
BufferRecycler.Gettable
Tag-on interface to allow various other types to expose
BufferRecycler
they are constructed with. |
Modifier and Type | Field and Description |
---|---|
protected AtomicReferenceArray<byte[]> |
_byteBuffers |
protected AtomicReferenceArray<char[]> |
_charBuffers |
static int |
BYTE_BASE64_CODEC_BUFFER
Buffer used for concatenating binary data that is either being
encoded as base64 output, or decoded from base64 input.
|
static int |
BYTE_READ_IO_BUFFER
Buffer used for reading byte-based input.
|
static int |
BYTE_WRITE_CONCAT_BUFFER
Buffer used for temporarily concatenating output; used for
example when requesting output as byte array.
|
static int |
BYTE_WRITE_ENCODING_BUFFER
Buffer used for temporarily storing encoded content; used
for example by UTF-8 encoding writer
|
static int |
CHAR_CONCAT_BUFFER
Buffer used by generators; for byte-backed generators for buffering of
String values to output (before encoding into UTF-8),
and for char-backed generators as actual concatenation buffer. |
static int |
CHAR_NAME_COPY_BUFFER
For parsers, temporary buffer into which
char[] for names is copied
when requested as such; for WriterBasedGenerator used for buffering
during writeString(Reader) operation (not commonly used). |
static int |
CHAR_TEXT_BUFFER
Used through
TextBuffer : directly by parsers (to concatenate
String values)
and indirectly via
SegmentedStringWriter
when serializing (databind level ObjectMapper and
ObjectWriter ). |
static int |
CHAR_TOKEN_BUFFER
Buffer used as input buffer for tokenization for character-based parsers.
|
Modifier | Constructor and Description |
---|---|
|
BufferRecycler()
Default constructor used for creating instances of this default
implementation.
|
protected |
BufferRecycler(int bbCount,
int cbCount)
Alternate constructor to be used by sub-classes, to allow customization
of number of low-level buffers in use.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
allocByteBuffer(int ix) |
byte[] |
allocByteBuffer(int ix,
int minSize) |
char[] |
allocCharBuffer(int ix) |
char[] |
allocCharBuffer(int ix,
int minSize) |
protected byte[] |
balloc(int size) |
protected int |
byteBufferLength(int ix) |
protected char[] |
calloc(int size) |
protected int |
charBufferLength(int ix) |
boolean |
isLinkedWithPool() |
void |
releaseByteBuffer(int ix,
byte[] buffer) |
void |
releaseCharBuffer(int ix,
char[] buffer) |
void |
releaseToPool()
Method called when owner of this recycler no longer wishes use it; this should
return it to pool passed via
withPool() (if any). |
BufferRecycler |
withPool(RecyclerPool<BufferRecycler> pool)
Method called by owner of this recycler instance, to provide reference to
RecyclerPool into which instance is to be released (if any) |
public static final int BYTE_READ_IO_BUFFER
public static final int BYTE_WRITE_ENCODING_BUFFER
public static final int BYTE_WRITE_CONCAT_BUFFER
public static final int BYTE_BASE64_CODEC_BUFFER
public static final int CHAR_TOKEN_BUFFER
public static final int CHAR_CONCAT_BUFFER
String
values to output (before encoding into UTF-8),
and for char-backed generators as actual concatenation buffer.public static final int CHAR_TEXT_BUFFER
TextBuffer
: directly by parsers (to concatenate
String values)
and indirectly via
SegmentedStringWriter
when serializing (databind level ObjectMapper
and
ObjectWriter
). In both cases used as segments (and not for whole value),
but may result in retention of larger chunks for big content
(long text values during parsing; bigger output documents for generation).public static final int CHAR_NAME_COPY_BUFFER
char[]
for names is copied
when requested as such; for WriterBasedGenerator
used for buffering
during writeString(Reader)
operation (not commonly used).protected final AtomicReferenceArray<byte[]> _byteBuffers
protected final AtomicReferenceArray<char[]> _charBuffers
public BufferRecycler()
protected BufferRecycler(int bbCount, int cbCount)
bbCount
- Number of byte[]
buffers to allocatecbCount
- Number of char[]
buffers to allocatepublic boolean isLinkedWithPool()
releaseToPool()
; false if no linkage exists.public final byte[] allocByteBuffer(int ix)
ix
- One of READ_IO_BUFFER
constants.public byte[] allocByteBuffer(int ix, int minSize)
public void releaseByteBuffer(int ix, byte[] buffer)
public final char[] allocCharBuffer(int ix)
public char[] allocCharBuffer(int ix, int minSize)
public void releaseCharBuffer(int ix, char[] buffer)
protected int byteBufferLength(int ix)
protected int charBufferLength(int ix)
protected byte[] balloc(int size)
protected char[] calloc(int size)
public BufferRecycler withPool(RecyclerPool<BufferRecycler> pool)
RecyclerPool
into which instance is to be released (if any)withPool
in interface RecyclerPool.WithPool<BufferRecycler>
pool
- Pool that "owns" pooled itempublic void releaseToPool()
withPool()
(if any).releaseToPool
in interface RecyclerPool.WithPool<BufferRecycler>
Copyright © 2008–2024 FasterXML. All rights reserved.