@InterfaceAudience.Private public abstract class Chunk extends Object
Modifier and Type | Field and Description |
---|---|
protected AtomicInteger |
allocCount
Total number of allocations satisfied from this buffer
|
private ChunkCreator.ChunkType |
chunkType |
protected ByteBuffer |
data
Actual underlying data
|
private boolean |
fromPool |
private int |
id |
protected AtomicInteger |
nextFreeOffset
Offset for the next allocation, or the sentinel value -1 which implies that the chunk is still
uninitialized.
|
protected static int |
OOM |
protected int |
size
Size of chunk in bytes
|
protected static int |
UNINITIALIZED |
Constructor and Description |
---|
Chunk(int size,
int id,
ChunkCreator.ChunkType chunkType)
Create an uninitialized chunk.
|
Chunk(int size,
int id,
ChunkCreator.ChunkType chunkType,
boolean fromPool)
Create an uninitialized chunk.
|
Modifier and Type | Method and Description |
---|---|
int |
alloc(int size)
Try to allocate
size bytes from the chunk. |
(package private) abstract void |
allocateDataBuffer() |
(package private) ChunkCreator.ChunkType |
getChunkType() |
(package private) ByteBuffer |
getData()
Returns This chunk's backing data.
|
(package private) int |
getId() |
(package private) int |
getNextFreeOffset() |
void |
init()
Actually claim the memory for this chunk.
|
(package private) boolean |
isDataChunk() |
(package private) boolean |
isFromPool() |
(package private) boolean |
isIndexChunk() |
(package private) boolean |
isJumbo() |
(package private) void |
reset()
Reset the offset to UNINITIALIZED before before reusing an old chunk
|
String |
toString() |
protected ByteBuffer data
protected static final int UNINITIALIZED
protected static final int OOM
protected AtomicInteger nextFreeOffset
protected AtomicInteger allocCount
protected final int size
private final int id
private final ChunkCreator.ChunkType chunkType
private final boolean fromPool
public Chunk(int size, int id, ChunkCreator.ChunkType chunkType)
size
- in bytesid
- the chunk idpublic Chunk(int size, int id, ChunkCreator.ChunkType chunkType, boolean fromPool)
size
- in bytesid
- the chunk idfromPool
- if the chunk is formed by poolint getId()
ChunkCreator.ChunkType getChunkType()
boolean isFromPool()
boolean isJumbo()
boolean isIndexChunk()
boolean isDataChunk()
public void init()
abstract void allocateDataBuffer()
void reset()
public int alloc(int size)
size
bytes from the chunk. If a chunk is tried to get allocated
before init() call, the thread doing the allocation will be in busy-wait state as it will keep
looping till the nextFreeOffset is set.ByteBuffer getData()
int getNextFreeOffset()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.