org.opennms.bb.dp.common.components
Class RunnableConsumerThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.opennms.bb.dp.common.components.PollerThread
              |
              +--org.opennms.bb.dp.common.components.RunnableConsumerThread
All Implemented Interfaces:
Runnable

public final class RunnableConsumerThread
extends PollerThread

The RunnableConsumerThread class is an extension of the PollerThread class. The extension class is really just a consumer of objects that implement the Runnable interface. When the object is consumed from the input queue it's run() method is invoked. After the run() method on the consumed object returns, the Runnable object is enqueued on an output queue if any exist. If no output queue exists then the object is discarded by the RunnableConsumerThread.

Version:
$Revision: 1.2 $
Author:
Brian Weaver, OpenNMS
See Also:
Runnable

Field Summary
private  PCQueue m_input
          The Producer/Consumer Queue where Runnable Objects are dequeued and run by the run() method.
private  PCQueue m_output
          The Producer/Consumer Queue where the Runnable objects from the input queue are placed when their run() method returns.
static int STATUS_BUSY
          This defines the thread specific bits that mask the thread as busy when its status is STATUS_NORMAL.
static int STATUS_IDLE
          This defines the thread specific bits that mark the thread as idle when its status is STATUS_NORMAL.
 
Fields inherited from class org.opennms.bb.dp.common.components.PollerThread
m_curOpStatus, STATUS_MASK, STATUS_NORMAL, STATUS_PAUSED, STATUS_PAUSING, STATUS_RESUMING, STATUS_SHUTDOWN, STATUS_STARTING, STATUS_TERMINATING
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
RunnableConsumerThread(PCQueue input)
          Constructs a thread consumer of objects that implement the Runnable interface.
RunnableConsumerThread(PCQueue input, PCQueue output)
          Constructs a consumer of objects that implement the Runnable interface.
RunnableConsumerThread(String name, PCQueue input)
          Constructs a thread consumer of objects that implement the Runnable interface.
RunnableConsumerThread(String name, PCQueue input, PCQueue output)
          Constructs a consumer of objects that implement the Runnable interface.
RunnableConsumerThread(ThreadGroup grp, String name, PCQueue input)
          Constructs a thread consumer of objects that implement the Runnable interface.
RunnableConsumerThread(ThreadGroup grp, String name, PCQueue input, PCQueue output)
          Constructs a threadconsumer of objects that implement the Runnable interface.
 
Method Summary
 void run()
          The run() method is actually invoked by the Thread base class and calls the run() method for each Runnable object dequeued by the class.
 
Methods inherited from class org.opennms.bb.dp.common.components.PollerThread
getCtrlStatus, getOpStatus, pauseOperation, pauseThread, resumeOperation, resumeThread, setCtrlStatus, setOpStatus, setUserStatus, shutdown, shutdownThread
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_input

private PCQueue m_input

The Producer/Consumer Queue where Runnable Objects are dequeued and run by the run() method.


m_output

private PCQueue m_output

The Producer/Consumer Queue where the Runnable objects from the input queue are placed when their run() method returns. If the queue is null then the Runnable objects are discarded.


STATUS_IDLE

public static final int STATUS_IDLE

This defines the thread specific bits that mark the thread as idle when its status is STATUS_NORMAL.


STATUS_BUSY

public static final int STATUS_BUSY

This defines the thread specific bits that mask the thread as busy when its status is STATUS_NORMAL.

Constructor Detail

RunnableConsumerThread

public RunnableConsumerThread(PCQueue input)

Constructs a thread consumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor.

Parameters:
input - The source of the runnable objects.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

RunnableConsumerThread

public RunnableConsumerThread(PCQueue input,
                              PCQueue output)

Constructs a consumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor. Once the runnable objects have had their run() method invoked and return the objects are then enqueued on the output queue.

Parameters:
input - The source of the runnable objects.
output - The destination of the spent runnable objects.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.

RunnableConsumerThread

public RunnableConsumerThread(String name,
                              PCQueue input)

Constructs a thread consumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor. The name of the thread is specified in the constructor.

Parameters:
name - The thread name supplied to base class.
input - The source of the runnable objects.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

RunnableConsumerThread

public RunnableConsumerThread(String name,
                              PCQueue input,
                              PCQueue output)

Constructs a consumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor. Once the runnable objects have had their run() method invoked and return the objects are then enqueued on the output queue.

Parameters:
name - The thread name supplied to the base class.
input - The source of the runnable objects.
output - The destination of the spent runnable objects.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.

RunnableConsumerThread

public RunnableConsumerThread(ThreadGroup grp,
                              String name,
                              PCQueue input)

Constructs a thread consumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor. The actual thread is created as a member of the ThreadGroup grp.

Parameters:
grp - The thread group for the new thread.
name - The thread name to pass to the base class.
input - The source of the runnable objects.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

RunnableConsumerThread

public RunnableConsumerThread(ThreadGroup grp,
                              String name,
                              PCQueue input,
                              PCQueue output)

Constructs a threadconsumer of objects that implement the Runnable interface. The objects are consumed from the input queue specified in the constructor. Once the runnable objects have had their run() method invoked and return the objects are then enqueued on the output queue. The thread is created in the passed thread group with the passed name.

Parameters:
grp - The thread group for membership.
name - The name of the new thread.
input - The source of the runnable objects.
output - The destination of the spent runnable objects.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.
Method Detail

run

public void run()

The run() method is actually invoked by the Thread base class and calls the run() method for each Runnable object dequeued by the class. The method ensures that the status of the object is kept updated as it dequeues, runs, and enqueues the runnables.

If the thread is paused the run() method may not transition to paused until the current runnable object, if any, completes. Likewise the thread will not terminate until the current runnable returns control to the thread.

Overrides:
run in class Thread