public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> extends java.lang.Object implements WorkerPool<E>, ExternalResourceReleasable
WorkerPool implementations that create the Worker's
up-front and return them in a "fair" fashion when calling nextWorker()| Modifier and Type | Field and Description |
|---|---|
private static int |
INITIALIZATION_TIMEOUT
The worker pool raises an exception unless all worker threads start and run within this timeout (in seconds.)
|
private java.util.concurrent.atomic.AtomicBoolean |
initialized |
private static InternalLogger |
logger |
private java.util.concurrent.Executor |
workerExecutor |
private java.util.concurrent.atomic.AtomicInteger |
workerIndex |
private AbstractNioWorker[] |
workers |
| Constructor and Description |
|---|
AbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor,
int workerCount)
Create a new instance
|
AbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor,
int workerCount,
boolean autoInit) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
init() |
protected abstract E |
newWorker(java.util.concurrent.Executor executor)
Create a new
Worker which uses the given Executor to service IO. |
E |
nextWorker()
Return the next
Worker to use |
void |
rebuildSelectors()
Replaces the current
Selectors of the Bosses with new Selectors to work around the
infamous epoll 100% CPU bug. |
void |
releaseExternalResources()
Releases the external resources that this object depends on.
|
void |
shutdown()
Shutdown the
NioSelectorPool and all internal created resources |
private void |
waitForWorkerThreads() |
private static final int INITIALIZATION_TIMEOUT
private static final InternalLogger logger
private final AbstractNioWorker[] workers
private final java.util.concurrent.atomic.AtomicInteger workerIndex
private final java.util.concurrent.Executor workerExecutor
private final java.util.concurrent.atomic.AtomicBoolean initialized
AbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor,
int workerCount)
AbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor,
int workerCount,
boolean autoInit)
protected void init()
private void waitForWorkerThreads()
protected abstract E newWorker(java.util.concurrent.Executor executor)
Worker which uses the given Executor to service IO.executor - the Executor to useWorkerpublic E nextWorker()
WorkerPoolWorker to usenextWorker in interface WorkerPool<E extends AbstractNioWorker>public void rebuildSelectors()
NioSelectorPoolSelectors of the Bosses with new Selectors to work around the
infamous epoll 100% CPU bug.rebuildSelectors in interface NioSelectorPoolpublic void releaseExternalResources()
ExternalResourceReleasablereleaseExternalResources in interface ExternalResourceReleasablepublic void shutdown()
NioSelectorPoolNioSelectorPool and all internal created resourcesshutdown in interface NioSelectorPool