java.lang.Object
net.i2p.data.i2np.GarlicClovePool
Pool for reusing GarlicClove instances across message parsing. Reduces per-clove allocation in the hot garlic message loop.
Cloves are acquired, populated via setters, used, then released back to the pool for reuse. The pool expands dynamically when empty.
Thread-safe for single-producer/single-consumer use (typical garlic message parsing pattern). Not safe for concurrent acquire/release.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intHow many clove objects are ready.private final I2PAppContextSupplies the pool's configuration.private final GarlicClove[]The clove objects held for reuse.Constructor Summary
ConstructorsConstructorDescriptionGarlicClovePool(I2PAppContext context) Create a pool with default capacity (4).GarlicClovePool(I2PAppContext context, int initialCapacity) Create a pool with the specified initial capacity.Method Summary
All MethodsModifier and TypeMethodDescriptionacquire()Acquire a clove from the pool.intCurrent number of available cloves in the pool.intcapacity()Maximum capacity of the pool.voidrelease(GarlicClove clove) Release a clove back to the pool for reuse.
Field Details
pool
The clove objects held for reuse.available
private int availableHow many clove objects are ready.context
Supplies the pool's configuration.
Constructor Details
GarlicClovePool
Create a pool with the specified initial capacity.- Parameters:
context- the router/app context for creating new clovesinitialCapacity- the number of cloves to pre-allocate
GarlicClovePool
Create a pool with default capacity (4).- Parameters:
context- the router/app context
Method Details
acquire
Acquire a clove from the pool. If the pool is empty, a new clove is allocated. The returned clove is in its initial state (cloveId = -1, no data, no certificate) ready for population.- Returns:
- a GarlicClove instance, never null
release
Release a clove back to the pool for reuse. The clove is not cleared — callers should ensure they no longer hold references to the released clove.- Parameters:
clove- the clove to release
available
public int available()Current number of available cloves in the pool.- Returns:
- the number of cloves the pool can currently hand out
capacity
public int capacity()Maximum capacity of the pool.- Returns:
- the most cloves the pool can hold at once