Class NioDatagramWorker

java.lang.Object
org.jboss.netty.channel.socket.nio.NioDatagramWorker
All Implemented Interfaces:
Runnable, NioSelector, Worker

public class NioDatagramWorker extends Object
A class responsible for registering channels with Selector. It also implements the Selector loop.
  • Field Details

    • 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.
    • selector

      protected volatile Selector selector
      The NIO Selector.
    • 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.
  • Method Details

    • read

      protected boolean read(SelectionKey key)
      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:
      key - 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)
    • writeFromUserCode

      public void writeFromUserCode(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
    • write0

      protected void write0(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • executeInIoThread

      public void executeInIoThread(Runnable task)
      Description copied from interface: Worker
      Execute the given Runnable in the IO-Thread. This may be now or later once the IO-Thread do some other work.
      Specified by:
      executeInIoThread in interface Worker
      Parameters:
      task - the Runnable to execute
    • executeInIoThread

      public void executeInIoThread(Runnable task, boolean alwaysAsync)
      Execute the Runnable in a IO-Thread
      Parameters:
      task - the Runnable to execute
      alwaysAsync - true if the Runnable should be executed in an async fashion even if the current Thread == 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
    • 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 interface NioSelector
    • registerTask

      protected final void registerTask(Runnable task)
    • isIoThread

      protected final boolean isIoThread()
    • rebuildSelector

      public void rebuildSelector()
      Description copied from interface: NioSelector
      Replaces the current Selector with a new Selector to work around the infamous epoll 100% CPU bug.
      Specified by:
      rebuildSelector in interface NioSelector
    • increaseCancelledKeys

      protected final void increaseCancelledKeys()
    • cleanUpCancelledKeys

      protected final boolean cleanUpCancelledKeys() throws IOException
      Throws:
      IOException
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface NioSelector
    • select

      protected int select(Selector selector) throws IOException
      Throws:
      IOException