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 int
cancelledKeys
private static int
CLEANUP_INTERVAL
private java.util.concurrent.Executor
executor
Executor used to executeRunnable
s such as channel registration task.private int
id
protected static InternalLogger
logger
Internal Netty logger.private static java.util.concurrent.atomic.AtomicInteger
nextId
protected java.nio.channels.Selector
selector
The NIOSelector
.private boolean
shutdown
private java.util.concurrent.CountDownLatch
shutdownLatch
(package private) java.util.concurrent.CountDownLatch
startupLatch
Count down to 0 when the I/O thread starts andthread
is set to non-null.private java.util.Queue<java.lang.Runnable>
taskQueue
protected java.lang.Thread
thread
If this worker has been started thread will be a reference to the thread used when starting.protected java.util.concurrent.atomic.AtomicBoolean
wakenUp
Boolean 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 boolean
cleanUpCancelledKeys()
protected abstract void
close(java.nio.channels.SelectionKey k)
protected abstract java.lang.Runnable
createRegisterTask(Channel channel, ChannelFuture future)
protected void
increaseCancelledKeys()
protected boolean
isIoThread()
protected abstract ThreadRenamingRunnable
newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner)
private void
openSelector(ThreadNameDeterminer determiner)
Start theAbstractNioWorker
and return theSelector
that will be used for theAbstractNioChannel
's when they get registeredprotected abstract void
process(java.nio.channels.Selector selector)
private void
processTaskQueue()
void
rebuildSelector()
Replaces the currentSelector
with a newSelector
to work around the infamous epoll 100% CPU bug.void
register(Channel channel, ChannelFuture future)
protected void
registerTask(java.lang.Runnable task)
void
run()
protected int
select(java.nio.channels.Selector selector)
void
shutdown()
-
-
-
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 executeRunnable
s 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 andthread
is 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:
register
in interfaceNioSelector
-
registerTask
protected final void registerTask(java.lang.Runnable task)
-
isIoThread
protected final boolean isIoThread()
-
rebuildSelector
public void rebuildSelector()
Description copied from interface:NioSelector
Replaces the currentSelector
with a newSelector
to work around the infamous epoll 100% CPU bug.- Specified by:
rebuildSelector
in interfaceNioSelector
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
openSelector
private void openSelector(ThreadNameDeterminer determiner)
Start theAbstractNioWorker
and return theSelector
that 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:
shutdown
in 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)
-
-