org.apache.catalina.tribes.transport.nio
Class NioReplicationThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.catalina.tribes.transport.WorkerThread
          extended by org.apache.catalina.tribes.transport.nio.NioReplicationThread
All Implemented Interfaces:
java.lang.Runnable

public class NioReplicationThread
extends WorkerThread

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.

Version:
$Revision: 378050 $, $Date: 2006-02-15 12:30:02 -0600 (Wed, 15 Feb 2006) $
Author:
Filip Hanik

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class org.apache.catalina.tribes.transport.WorkerThread
OPTION_DIRECT_BUFFER, useBufferPool
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NioReplicationThread(ListenCallback callback, NioReceiver receiver)
           
 
Method Summary
protected  void drainChannel(java.nio.channels.SelectionKey key, ObjectReader reader)
          The actual code which drains the channel associated with the given key.
 int getRxBufSize()
           
protected  void registerForRead(java.nio.channels.SelectionKey key, ObjectReader reader)
           
 void run()
           
protected  void sendAck(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel channel, byte[] command)
          send a reply-acknowledgement (6,2,3)
 void serviceChannel(java.nio.channels.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.WorkerThread
close, getCallback, getOptions, getPool, getUseBufferPool, isDoRun, setCallback, setDoRun, setOptions, setPool, setUseBufferPool
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NioReplicationThread

public NioReplicationThread(ListenCallback callback,
                            NioReceiver receiver)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

serviceChannel

public void serviceChannel(java.nio.channels.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.


drainChannel

protected void drainChannel(java.nio.channels.SelectionKey key,
                            ObjectReader reader)
                     throws java.lang.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.

Throws:
java.lang.Exception

registerForRead

protected void registerForRead(java.nio.channels.SelectionKey key,
                               ObjectReader reader)

sendAck

protected void sendAck(java.nio.channels.SelectionKey key,
                       java.nio.channels.SocketChannel channel,
                       byte[] command)
send a reply-acknowledgement (6,2,3)

Parameters:
key -
channel -

setRxBufSize

public void setRxBufSize(int rxBufSize)

getRxBufSize

public int getRxBufSize()


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