Class ByteBufferPool
java.lang.Object
com.xpdustry.claj.common.util.ByteBufferPool
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intprotected final ConcurrentHashMap<Integer, Pool<ByteBuffer>> final intprotected final ConcurrentHashMap<Integer, Pool<ByteBuffer>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbucketOf(int size) voidclear()Clear all buffer buckets.voidclear(boolean direct) voidfill(int bucket) Fill abucketcompletely.voidfill(int bucket, int size) voidfill(int bucket, int size, boolean direct) Fill abucketwithsizenew buffers.static booleanfree(ByteBuffer buff) static ByteBufferPoolget()protected ConcurrentHashMap<Integer, Pool<ByteBuffer>> getBuckets(boolean direct) static ByteBuffergetDirect(int size) static ByteBuffergetHeap(int size) booleanhas(int bucket) booleanhas(int bucket, boolean direct) protected ByteBuffernewBuffer(boolean direct, int capacity) obtain(int size) obtain(int size, boolean direct) Get a buffer of the givensizefrom free pool, or a new one.booleanrelease(ByteBuffer buf) Double release protection not handled!intsize(int bucket) intsize(int bucket, boolean direct)
-
Field Details
-
heaps
-
directs
-
factor
public final int factor -
bucketCap
public final int bucketCap
-
-
Constructor Details
-
ByteBufferPool
-
ByteBufferPool
public ByteBufferPool(int factor, int bucketCap)
-
-
Method Details
-
get
-
getHeap
-
getDirect
-
free
-
getBuckets
-
newBuffer
-
bucketOf
public int bucketOf(int size) - Returns:
- the bucket fitting the given
sizeaccording to thefactor.
-
obtain
-
obtain
Get a buffer of the givensizefrom free pool, or a new one.
Capacity is rounded to the upperfactor, but limited to the givensize. -
release
Double release protection not handled!- Returns:
- whether the buffer was added to the free buffer pool.
A buffer might not be added for several reason: a
nullvalue, zero capacity, not at the definedfactor, or simply because the associated bucket is full.
-
fill
public void fill(int bucket) Fill abucketcompletely. -
fill
public void fill(int bucket, int size) -
fill
public void fill(int bucket, int size, boolean direct) Fill abucketwithsizenew buffers. -
clear
public void clear()Clear all buffer buckets. -
clear
public void clear(boolean direct) -
size
public int size(int bucket) -
size
public int size(int bucket, boolean direct) - Returns:
- the number of currently freed buffers in a bucket,
or
-1if no pool has been created for this bucket.
-
has
public boolean has(int bucket) -
has
public boolean has(int bucket, boolean direct) - Returns:
- whether a pool has been created for the specified
bucket.
-