public class RetainableByteBuffer extends java.lang.Object implements Retainable
Acquires a ByteBuffer from a ByteBufferPool
and maintains a reference count that is
initially 1, incremented with retain()
and decremented with release()
. The buffer
is released to the pool when the reference count is decremented to 0.
Modifier and Type | Field and Description |
---|---|
private java.nio.ByteBuffer |
buffer |
private ByteBufferPool |
pool |
private java.util.concurrent.atomic.AtomicInteger |
references |
Constructor and Description |
---|
RetainableByteBuffer(ByteBufferPool pool,
int size) |
RetainableByteBuffer(ByteBufferPool pool,
int size,
boolean direct) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
java.nio.ByteBuffer |
getBuffer() |
int |
getReferences() |
boolean |
hasRemaining() |
boolean |
isEmpty() |
int |
release() |
int |
remaining() |
void |
retain() |
java.lang.String |
toString() |
private final ByteBufferPool pool
private final java.nio.ByteBuffer buffer
private final java.util.concurrent.atomic.AtomicInteger references
public RetainableByteBuffer(ByteBufferPool pool, int size)
public RetainableByteBuffer(ByteBufferPool pool, int size, boolean direct)
public java.nio.ByteBuffer getBuffer()
public int getReferences()
public void retain()
retain
in interface Retainable
public int release()
public int remaining()
public boolean hasRemaining()
public boolean isEmpty()
public void clear()
public java.lang.String toString()
toString
in class java.lang.Object