Class NioWorker
- java.lang.Object
-
- org.jboss.netty.channel.socket.nio.NioWorker
-
- All Implemented Interfaces:
Runnable
,NioSelector
,Worker
public class NioWorker extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static InternalLogger
logger
Internal Netty logger.protected Selector
selector
The NIOSelector
.protected org.jboss.netty.channel.socket.nio.SocketSendBufferPool
sendBufferPool
protected Thread
thread
If this worker has been started thread will be a reference to the thread used when starting.protected AtomicBoolean
wakenUp
Boolean that controls determines if a blocked Selector.select should break out of its selection process.
-
Constructor Summary
Constructors Constructor Description NioWorker(Executor executor)
NioWorker(Executor executor, ThreadNameDeterminer determiner)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
cleanUpCancelledKeys()
protected static void
cleanUpWriteBuffer(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
protected void
clearOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
protected void
close(SelectionKey k)
protected void
close(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel, ChannelFuture future)
protected Runnable
createRegisterTask(Channel channel, ChannelFuture future)
void
executeInIoThread(Runnable task)
Execute the givenRunnable
in the IO-Thread.void
executeInIoThread(Runnable task, boolean alwaysAsync)
Execute theRunnable
in a IO-Threadprotected void
increaseCancelledKeys()
protected boolean
isIoThread()
protected ThreadRenamingRunnable
newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner)
protected void
process(Selector selector)
protected boolean
read(SelectionKey k)
Read is called when a Selector has been notified that the underlying channel was something to be read.void
rebuildSelector()
void
register(Channel channel, ChannelFuture future)
protected void
registerTask(Runnable task)
void
run()
protected boolean
scheduleWriteIfNecessary(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
protected int
select(Selector selector)
protected void
setOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
void
shutdown()
protected void
write0(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
-
-
Field Detail
-
sendBufferPool
protected final org.jboss.netty.channel.socket.nio.SocketSendBufferPool sendBufferPool
-
logger
protected static final InternalLogger logger
Internal Netty logger.
-
thread
protected volatile 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.
-
wakenUp
protected final 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.
-
-
Constructor Detail
-
NioWorker
public NioWorker(Executor executor)
-
NioWorker
public NioWorker(Executor executor, ThreadNameDeterminer determiner)
-
-
Method Detail
-
read
protected boolean read(SelectionKey k)
Read is called when a Selector has been notified that the underlying channel was something to be read. The channel would previously have registered its interest in read operations.- Parameters:
k
- The selection key which contains the Selector registration information.
-
scheduleWriteIfNecessary
protected boolean scheduleWriteIfNecessary(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
createRegisterTask
protected Runnable createRegisterTask(Channel channel, ChannelFuture future)
-
executeInIoThread
public void executeInIoThread(Runnable task)
Description copied from interface:Worker
Execute the givenRunnable
in the IO-Thread. This may be now or later once the IO-Thread do some other work.- Specified by:
executeInIoThread
in interfaceWorker
- Parameters:
task
- theRunnable
to execute
-
executeInIoThread
public void executeInIoThread(Runnable task, boolean alwaysAsync)
Execute theRunnable
in a IO-Thread
-
close
protected void close(SelectionKey k)
-
newThreadRenamingRunnable
protected ThreadRenamingRunnable newThreadRenamingRunnable(int id, ThreadNameDeterminer determiner)
-
process
protected void process(Selector selector) throws IOException
- Throws:
IOException
-
write0
protected void write0(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
setOpWrite
protected void setOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
clearOpWrite
protected void clearOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
close
protected void close(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel, ChannelFuture future)
-
cleanUpWriteBuffer
protected static void cleanUpWriteBuffer(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
-
register
public void register(Channel channel, ChannelFuture future)
- Specified by:
register
in interfaceNioSelector
-
registerTask
protected final void registerTask(Runnable task)
-
isIoThread
protected final boolean isIoThread()
-
rebuildSelector
public void rebuildSelector()
Description copied from interface:NioSelector
- Specified by:
rebuildSelector
in interfaceNioSelector
-
increaseCancelledKeys
protected final void increaseCancelledKeys()
-
cleanUpCancelledKeys
protected final boolean cleanUpCancelledKeys() throws IOException
- Throws:
IOException
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceNioSelector
-
select
protected int select(Selector selector) throws IOException
- Throws:
IOException
-
-