NioReplicationTask (Apache Tomcat 8.5.57 API Documentation)

org.apache.catalina.tribes.transport.nio

## Class NioReplicationTask

- java.lang.Object
- - org.apache.catalina.tribes.transport.AbstractRxTask
  - - org.apache.catalina.tribes.transport.nio.NioReplicationTask

- All Implemented Interfaces:
    Runnable

      public class NioReplicationTask
      extends AbstractRxTask

  A worker thread class which can drain channels and echo-back the input. Each instance is constructed with a reference to the owning thread pool object. When started, the thread loops forever waiting to be awakened to service the channel associated with a SelectionKey object. The worker is tasked by calling its serviceChannel() method with a SelectionKey object. The serviceChannel() method stores the key reference in the thread object then calls notify() to wake it up. When the channel has been drained, the worker thread returns itself to its parent pool.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static StringManager` | `sm`

    - ### Fields inherited from class org.apache.catalina.tribes.transport.AbstractRxTask

      `OPTION_DIRECT_BUFFER, useBufferPool`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NioReplicationTask(ListenCallback callback, NioReceiver receiver)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `drainChannel(SelectionKey key, ObjectReader reader)` The actual code which drains the channel associated with the given key.
    `int` | `getRxBufSize()`
    `protected void` | `registerForRead(SelectionKey key, ObjectReader reader)`
    `void` | `run()`
    `protected void` | `sendAck(SelectionKey key, WritableByteChannel channel, byte[] command, SocketAddress udpaddr)` Send a reply-acknowledgement (6,2,3), sends it doing a busy write, the ACK is so small that it should always go to the buffer.
    `void` | `serviceChannel(SelectionKey key)` Called to initiate a unit of work by this worker thread on the provided SelectionKey object.
    `void` | `setRxBufSize(int rxBufSize)`

    - ### Methods inherited from class org.apache.catalina.tribes.transport.AbstractRxTask

      `close, getCallback, getOptions, getTaskPool, getUseBufferPool, isDoRun, setCallback, setDoRun, setOptions, setTaskPool, setUseBufferPool`

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

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

- - ### Field Detail

    - #### sm

          protected static final StringManager sm

  - ### Constructor Detail

    - #### NioReplicationTask

          public NioReplicationTask(ListenCallback callback,
                            NioReceiver receiver)

  - ### Method Detail

    - #### run

          public void run()

    - #### serviceChannel

          public void serviceChannel(SelectionKey key)

      Called to initiate a unit of work by this worker thread on the provided SelectionKey object. This method is synchronized, as is the run() method, so only one key can be serviced at a given time. Before waking the worker thread, and before returning to the main selection loop, this key's interest set is updated to remove OP_READ. This will cause the selector to ignore read-readiness for this channel while the worker thread is servicing it.
      Parameters:
        `key` - The key to process

    - #### drainChannel

          protected void drainChannel(SelectionKey key,
                          ObjectReader reader)
                               throws Exception

      The actual code which drains the channel associated with the given key. This method assumes the key has been modified prior to invocation to turn off selection interest in OP_READ. When this method completes it re-enables OP_READ and calls wakeup() on the selector so the selector will resume watching this channel.
      Parameters:
        `key` - The key to process
        `reader` - The reader
      Throws:
        `Exception` - IO error

    - #### registerForRead

          protected void registerForRead(SelectionKey key,
                             ObjectReader reader)

    - #### sendAck

          protected void sendAck(SelectionKey key,
                     WritableByteChannel channel,
                     byte[] command,
                     SocketAddress udpaddr)

      Send a reply-acknowledgement (6,2,3), sends it doing a busy write, the ACK is so small that it should always go to the buffer.
      Parameters:
        `key` - The key to use
        `channel` - The channel
        `command` - The command to write
        `udpaddr` - Target address

    - #### setRxBufSize

          public void setRxBufSize(int rxBufSize)

    - #### getRxBufSize

          public int getRxBufSize()

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.