org.jboss.netty.channel.socket.nio

## Class NioDatagramWorker

- java.lang.Object
- - org.jboss.netty.channel.socket.nio.NioDatagramWorker

- All Implemented Interfaces:
    Runnable, Worker

      public class NioDatagramWorker
      extends Object

  A class responsible for registering channels with `Selector`. It also implements the `Selector` loop.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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. i.e. the current thread when the run method is executed.
    `protected AtomicBoolean` | `wakenUp` Boolean that controls determines if a blocked Selector.select should break out of its selection process.
    `protected Queue<Runnable>` | `writeTaskQueue` Queue of WriteTasks

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `cleanUpWriteBuffer(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`
    `protected void` | `clearOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`
    `protected Runnable` | `createRegisterTask(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel, ChannelFuture future)` Create a new `Runnable` which will register the `AbstractNioWorker` with the `Channel`
    `void` | `executeInIoThread(Runnable task)` Execute the given `Runnable` in the IO-Thread.
    `void` | `executeInIoThread(Runnable task, boolean alwaysAsync)` Execute the `Runnable` in a IO-Thread
    `protected boolean` | `read(SelectionKey key)` Read is called when a Selector has been notified that the underlying channel was something to be read.
    `void` | `run()`
    `protected boolean` | `scheduleWriteIfNecessary(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`
    `protected void` | `setOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`
    `protected void` | `write0(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`
    `void` | `writeFromUserCode(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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.

    - #### writeTaskQueue

          protected final Queue<Runnable> writeTaskQueue

      Queue of WriteTasks

    - #### sendBufferPool

          protected final org.jboss.netty.channel.socket.nio.SocketSendBufferPool sendBufferPool

  - ### Method Detail

    - #### 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(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel,
                                    ChannelFuture future)

      Create a new `Runnable` which will register the `AbstractNioWorker` with the `Channel`
      Returns:
        task

    - #### 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

    - #### setOpWrite

          protected void setOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)

    - #### clearOpWrite

          protected void clearOpWrite(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)

    - #### cleanUpWriteBuffer

          protected void cleanUpWriteBuffer(org.jboss.netty.channel.socket.nio.AbstractNioChannel<?> channel)

Copyright © 2008-2012 The Netty Project. All Rights Reserved.