java.lang.Object
java.lang.Thread
net.i2p.client.streaming.impl.PacketDispatcher.Worker
- All Implemented Interfaces:
Runnable
- Enclosing class:
PacketDispatcher
One worker drains its own bounded queue; started in the dispatcher ctor.
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandlerField Summary
FieldsModifier and TypeFieldDescription(package private) intEntries currently inside process(); read by resize to prove idle.private final I2PAppContextThe app context.private final PacketDispatcher.PacketProcessorThe processor handling the packets.private final LinkedBlockingQueue<PacketDispatcher.Entry> The packets waiting for this worker.private booleanSet by retire() before it drains, under the same monitor as offer(), so a handoff either lands before the drain (and is freed by it) or is refused - never accepted into a queue nothing will ever drain again.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsConstructorDescriptionWorker(int shard, int queueCapacity, PacketDispatcher.PacketProcessor processor, I2PAppContext context) A shard's worker, not started here - the dispatcher starts the whole array at once so a resize can swap the shards over as a unit.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) voidWait until this shard has nothing queued and nothing in process(), so retiring it cannot drop an entry that was already accepted.(package private) booleanHand an entry to this worker, refusing it if the worker has been retired, so a handoff racing with a resize or shutdown cannot park the entry in a queue nothing will drain again.(package private) voidretire()Interrupt the worker and free any queued-but-unprocessed entries.voidrun()Methods inherited from class Thread
activeCount, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, threadId, toString, yield
Field Details
_queue
The packets waiting for this worker._processor
The processor handling the packets._context
The app context._busy
volatile int _busyEntries currently inside process(); read by resize to prove idle._retired
private boolean _retiredSet by retire() before it drains, under the same monitor as offer(), so a handoff either lands before the drain (and is freed by it) or is refused - never accepted into a queue nothing will ever drain again.
Constructor Details
Worker
Worker(int shard, int queueCapacity, PacketDispatcher.PacketProcessor processor, I2PAppContext context) A shard's worker, not started here - the dispatcher starts the whole array at once so a resize can swap the shards over as a unit.- Parameters:
shard- shard index, used only to name the threadqueueCapacity- entries this shard holds before producers waitprocessor- how to process an entry, from the dispatchercontext- for the backlog and queue-depth rates, null in tests
Method Details
offer
Hand an entry to this worker, refusing it if the worker has been retired, so a handoff racing with a resize or shutdown cannot park the entry in a queue nothing will drain again.- Parameters:
e- the entry to enqueue- Returns:
- true if the entry was queued and will be processed
awaitIdle
Wait until this shard has nothing queued and nothing in process(), so retiring it cannot drop an entry that was already accepted.- Throws:
InterruptedException- if interrupted while waiting
retire
void retire()Interrupt the worker and free any queued-but-unprocessed entries.run