Class AbstractNioWorkerPool<E extends AbstractNioWorker>
- java.lang.Object
-
- org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool<E>
-
- All Implemented Interfaces:
NioSelectorPool,WorkerPool<E>,ExternalResourceReleasable
- Direct Known Subclasses:
NioDatagramWorkerPool,NioWorkerPool
public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> extends java.lang.Object implements WorkerPool<E>, ExternalResourceReleasable
Abstract base class forWorkerPoolimplementations that create theWorker's up-front and return them in a "fair" fashion when callingnextWorker()
-
-
Field Summary
Fields Modifier and Type Field Description private static intINITIALIZATION_TIMEOUTThe worker pool raises an exception unless all worker threads start and run within this timeout (in seconds.)private java.util.concurrent.atomic.AtomicBooleaninitializedprivate static InternalLoggerloggerprivate java.util.concurrent.ExecutorworkerExecutorprivate java.util.concurrent.atomic.AtomicIntegerworkerIndexprivate AbstractNioWorker[]workers
-
Constructor Summary
Constructors Constructor Description AbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor, int workerCount)Create a new instanceAbstractNioWorkerPool(java.util.concurrent.Executor workerExecutor, int workerCount, boolean autoInit)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidinit()protected abstract EnewWorker(java.util.concurrent.Executor executor)Create a newWorkerwhich uses the givenExecutorto service IO.EnextWorker()Return the nextWorkerto usevoidrebuildSelectors()Replaces the currentSelectors of theBosses with newSelectors to work around the infamous epoll 100% CPU bug.voidreleaseExternalResources()Releases the external resources that this object depends on.voidshutdown()Shutdown theNioSelectorPooland all internal created resourcesprivate voidwaitForWorkerThreads()
-
-
-
Field Detail
-
INITIALIZATION_TIMEOUT
private static final int INITIALIZATION_TIMEOUT
The worker pool raises an exception unless all worker threads start and run within this timeout (in seconds.)- See Also:
- Constant Field Values
-
logger
private static final InternalLogger logger
-
workers
private final AbstractNioWorker[] workers
-
workerIndex
private final java.util.concurrent.atomic.AtomicInteger workerIndex
-
workerExecutor
private final java.util.concurrent.Executor workerExecutor
-
initialized
private final java.util.concurrent.atomic.AtomicBoolean initialized
-
-
Method Detail
-
init
protected void init()
-
waitForWorkerThreads
private void waitForWorkerThreads()
-
newWorker
protected abstract E newWorker(java.util.concurrent.Executor executor)
Create a newWorkerwhich uses the givenExecutorto service IO.- Parameters:
executor- theExecutorto use- Returns:
- worker the new
Worker
-
nextWorker
public E nextWorker()
Description copied from interface:WorkerPoolReturn the nextWorkerto use- Specified by:
nextWorkerin interfaceWorkerPool<E extends AbstractNioWorker>- Returns:
- worker
-
rebuildSelectors
public void rebuildSelectors()
Description copied from interface:NioSelectorPoolReplaces the currentSelectors of theBosses with newSelectors to work around the infamous epoll 100% CPU bug.- Specified by:
rebuildSelectorsin interfaceNioSelectorPool
-
releaseExternalResources
public void releaseExternalResources()
Description copied from interface:ExternalResourceReleasableReleases the external resources that this object depends on. You should not call this method if the external resources (e.g. thread pool) are in use by other objects.- Specified by:
releaseExternalResourcesin interfaceExternalResourceReleasable
-
shutdown
public void shutdown()
Description copied from interface:NioSelectorPoolShutdown theNioSelectorPooland all internal created resources- Specified by:
shutdownin interfaceNioSelectorPool
-
-