LocalPool Class — netty Architecture
Architecture documentation for the LocalPool class in Recycler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 35ba43da_5a98_091e_3833_ccfc393fe9ff["LocalPool"] 92da7dba_a9f6_c802_c3c1_5a54e228e444["Recycler.java"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|defined in| 92da7dba_a9f6_c802_c3c1_5a54e228e444 32f03d18_b521_34c0_4e3d_4eb52b3d02ca["LocalPool()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 32f03d18_b521_34c0_4e3d_4eb52b3d02ca ce3244a6_1286_60c2_dc87_1b0d59a6e5c1["createExternalMcPool()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| ce3244a6_1286_60c2_dc87_1b0d59a6e5c1 7abe3ee7_1c1d_3f3c_5cef_5da576a66c18["createExternalScPool()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 7abe3ee7_1c1d_3f3c_5cef_5da576a66c18 a95d32ed_136e_1069_9bda_0d9a572af8d7["H()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| a95d32ed_136e_1069_9bda_0d9a572af8d7 9336dc88_2540_a5d2_ab54_05caa588e0a7["release()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 9336dc88_2540_a5d2_ab54_05caa588e0a7 740364ab_7b92_506a_a86c_da478e9fbb53["isTerminated()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 740364ab_7b92_506a_a86c_da478e9fbb53 8305b6dd_0c4d_d7b6_0746_85a931890f03["canAllocatePooled()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 8305b6dd_0c4d_d7b6_0746_85a931890f03 4c730ce9_8e72_58f6_9923_c50c88443fdb["T()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 4c730ce9_8e72_58f6_9923_c50c88443fdb 75c2be6e_1969_12cc_0654_6b76fe47981c["size()"] 35ba43da_5a98_091e_3833_ccfc393fe9ff -->|method| 75c2be6e_1969_12cc_0654_6b76fe47981c
Relationship Graph
Source Code
common/src/main/java/io/netty/util/Recycler.java lines 500–615
private abstract static class LocalPool<H, T> {
private final int ratioInterval;
private final H[] batch;
private int batchSize;
private Thread owner;
private MessagePassingQueue<H> pooledHandles;
private int ratioCounter;
LocalPool(int maxCapacity) {
// if there's no capacity, we need to never allocate pooled objects.
// if there's capacity, because there is a shared pool, we always pool them, since we cannot trust the
// thread unsafe ratio counter.
this.ratioInterval = maxCapacity == 0? -1 : 0;
this.owner = null;
batch = null;
batchSize = 0;
pooledHandles = createExternalMcPool(maxCapacity);
ratioCounter = 0;
}
@SuppressWarnings("unchecked")
LocalPool(Thread owner, int maxCapacity, int ratioInterval, int chunkSize) {
this.ratioInterval = ratioInterval;
this.owner = owner;
batch = owner != null? (H[]) new Object[chunkSize] : null;
batchSize = 0;
pooledHandles = createExternalScPool(chunkSize, maxCapacity);
ratioCounter = ratioInterval; // Start at interval so the first one will be recycled.
}
private static <H> MessagePassingQueue<H> createExternalMcPool(int maxCapacity) {
if (maxCapacity == 0) {
return null;
}
if (BLOCKING_POOL) {
return new BlockingMessageQueue<>(maxCapacity);
}
return (MessagePassingQueue<H>) newFixedMpmcQueue(maxCapacity);
}
private static <H> MessagePassingQueue<H> createExternalScPool(int chunkSize, int maxCapacity) {
if (maxCapacity == 0) {
return null;
}
if (BLOCKING_POOL) {
return new BlockingMessageQueue<>(maxCapacity);
}
return (MessagePassingQueue<H>) newMpscQueue(chunkSize, maxCapacity);
}
LocalPool(int maxCapacity, int ratioInterval, int chunkSize) {
this(!BATCH_FAST_TL_ONLY || FastThreadLocalThread.currentThreadHasFastThreadLocal()
? Thread.currentThread() : null, maxCapacity, ratioInterval, chunkSize);
}
protected final H acquire() {
int size = batchSize;
if (size == 0) {
// it's ok to be racy; at worst we reuse something that won't return back to the pool
final MessagePassingQueue<H> handles = pooledHandles;
if (handles == null) {
return null;
}
return handles.relaxedPoll();
}
int top = size - 1;
final H h = batch[top];
batchSize = top;
batch[top] = null;
return h;
}
protected final void release(H handle) {
Thread owner = this.owner;
if (owner != null && Thread.currentThread() == owner && batchSize < batch.length) {
batch[batchSize] = handle;
batchSize++;
} else if (owner != null && isTerminated(owner)) {
pooledHandles = null;
this.owner = null;
} else {
Source
Frequently Asked Questions
What is the LocalPool class?
LocalPool is a class in the netty codebase, defined in common/src/main/java/io/netty/util/Recycler.java.
Where is LocalPool defined?
LocalPool is defined in common/src/main/java/io/netty/util/Recycler.java at line 500.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free