Class AbstractNioSelector
- java.lang.Object
-
- org.jboss.netty.channel.socket.nio.AbstractNioSelector
-
- All Implemented Interfaces:
java.lang.Runnable,NioSelector
- Direct Known Subclasses:
AbstractNioWorker,NioClientBoss,NioServerBoss
abstract class AbstractNioSelector extends java.lang.Object implements NioSelector
-
-
Field Summary
Fields Modifier and Type Field Description private intcancelledKeysprivate static intCLEANUP_INTERVALprivate java.util.concurrent.ExecutorexecutorExecutor used to executeRunnables such as channel registration task.private intidprotected static InternalLoggerloggerInternal Netty logger.private static java.util.concurrent.atomic.AtomicIntegernextIdprotected java.nio.channels.SelectorselectorThe NIOSelector.private booleanshutdownprivate java.util.concurrent.CountDownLatchshutdownLatch(package private) java.util.concurrent.CountDownLatchstartupLatchCount down to 0 when the I/O thread starts andthreadis set to non-null.private java.util.Queue<java.lang.Runnable>taskQueueprotected java.lang.ThreadthreadIf this worker has been started thread will be a reference to the thread used when starting.protected java.util.concurrent.atomic.AtomicBooleanwakenUpBoolean that controls determines if a blocked Selector.select should break out of its selection process.
-
Constructor Summary
Constructors Constructor Description AbstractNioSelector(java.util.concurrent.Executor executor)AbstractNioSelector(java.util.concurrent.Executor executor, ThreadNameDeterminer determiner)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancleanUpCancelledKeys()protected abstract voidclose(java.nio.channels.SelectionKey k)protected abstract java.lang.RunnablecreateRegisterTask(Channel channel, ChannelFuture future)protected voidincreaseCancelledKeys()protected booleanisIoThread()protected abstract ThreadRenamingRunnablenewThreadRenamingRunnable(int id, ThreadNameDeterminer determiner)private voidopenSelector(ThreadNameDeterminer determiner)Start theAbstractNioWorkerand return theSelectorthat will be used for theAbstractNioChannel's when they get registeredprotected abstract voidprocess(java.nio.channels.Selector selector)private voidprocessTaskQueue()voidrebuildSelector()Replaces the currentSelectorwith a newSelectorto work around the infamous epoll 100% CPU bug.voidregister(Channel channel, ChannelFuture future)protected voidregisterTask(java.lang.Runnable task)voidrun()protected intselect(java.nio.channels.Selector selector)voidshutdown()
-
-
-
Field Detail
-
nextId
private static final java.util.concurrent.atomic.AtomicInteger nextId
-
id
private final int id
-
logger
protected static final InternalLogger logger
Internal Netty logger.
-
CLEANUP_INTERVAL
private static final int CLEANUP_INTERVAL
- See Also:
- Constant Field Values
-
executor
private final java.util.concurrent.Executor executor
Executor used to executeRunnables such as channel registration task.
-
thread
protected volatile java.lang.Thread thread
If this worker has been started thread will be a reference to the thread used when starting. i.e. the current thread when the run method is executed.
-
startupLatch
final java.util.concurrent.CountDownLatch startupLatch
Count down to 0 when the I/O thread starts andthreadis set to non-null.
-
selector
protected volatile java.nio.channels.Selector selector
The NIOSelector.
-
wakenUp
protected final java.util.concurrent.atomic.AtomicBoolean wakenUp
Boolean that controls determines if a blocked Selector.select should break out of its selection process. In our case we use a timeone for the select method and the select method will block for that time unless waken up.
-
taskQueue
private final java.util.Queue<java.lang.Runnable> taskQueue
-
cancelledKeys
private volatile int cancelledKeys
-
shutdownLatch
private final java.util.concurrent.CountDownLatch shutdownLatch
-
shutdown
private volatile boolean shutdown
-
-
Constructor Detail
-
AbstractNioSelector
AbstractNioSelector(java.util.concurrent.Executor executor)
-
AbstractNioSelector
AbstractNioSelector(java.util.concurrent.Executor executor, ThreadNameDeterminer determiner)
-
-
Method Detail
-
register
public void register(Channel channel, ChannelFuture future)
- Specified by:
registerin interfaceNioSelector
-
registerTask
protected final void registerTask(java.lang.Runnable task)
-
isIoThread
protected final boolean isIoThread()
-
rebuildSelector
public void rebuildSelector()
Description copied from interface:NioSelectorReplaces the currentSelectorwith a newSelectorto work around the infamous epoll 100% CPU bug.- Specified by:
rebuildSelectorin interfaceNioSelector
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
openSelector
private void openSelector(ThreadNameDeterminer determiner)
Start theAbstractNioWorkerand return theSelectorthat will be used for theAbstractNioChannel's when they get registered
-
processTaskQueue
private void processTaskQueue()
-
increaseCancelledKeys
protected final void increaseCancelledKeys()
-
cleanUpCancelledKeys
protected final boolean cleanUpCancelledKeys() throws java.io.IOException- Throws:
java.io.IOException
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfaceNioSelector
-
process
protected abstract void process(java.nio.channels.Selector selector) throws java.io.IOException- Throws:
java.io.IOException
-
select
protected int select(java.nio.channels.Selector selector) throws java.io.IOException- Throws:
java.io.IOException
-
close
protected abstract void close(java.nio.channels.SelectionKey k)
-
newThreadRenamingRunnable
protected abstract ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner)
-
createRegisterTask
protected abstract java.lang.Runnable createRegisterTask(Channel channel, ChannelFuture future)
-
-