OpenNMS API 1.2.3

org.opennms.core.concurrent
Class RunnableConsumerThreadPool

java.lang.Object
  extended byorg.opennms.core.concurrent.RunnableConsumerThreadPool
All Implemented Interfaces:
Fiber

public class RunnableConsumerThreadPool
extends java.lang.Object
implements Fiber


Nested Class Summary
private  class RunnableConsumerThreadPool.FiberThreadImpl
          This class implements the Fiber interface on top of a Java Threadinstance.
static interface RunnableConsumerThreadPool.RunnableCompletionListener
          This interface is used to define a listener for the thread pool that is notified when an enqueued runnable completes.
static interface RunnableConsumerThreadPool.RunnableErrorListener
          This interface is used to define a listerer for the thread pool that is notified if an error occurs processing a runnable.
private  class RunnableConsumerThreadPool.SizingFifoQueue
           This class is used to create a queue that auto adjust the number of threads in the pool.
 
Field Summary
private  java.util.List m_completedListeners
          The set of listeners to call when a Runnable completes successfully.
private  RunnableConsumerThreadPool.SizingFifoQueue m_delegateQ
          The queue where runnable objects are added.
private  java.util.List m_errorListeners
          The set of listeners to call when a Runnable fails to complete successfully.
private  Fiber[] m_fibers
          The list of running fibers in the pool.
private  float m_hiRatio
          The high water mark ratio for the pool.
private  java.lang.String m_log4jPrefix
          The log4j prefix used when starting up a new fiber!
private  float m_loRatio
          The low water mark ratio for the pool.
private  int m_maxSize
          The maximum size for the thread pool.
private  java.lang.String m_poolName
          The name of the pool.
private  int m_poolStatus
          The pool status
private  java.lang.ThreadGroup m_tGroup
          The thread group that all pool threads belong to.
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
RunnableConsumerThreadPool(java.lang.String name, float loMark, float hiMark, int max)
           Constructs a new instance of the thread pool class.
 
Method Summary
 void addCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
          Adds a listener that is notified upon completion of each runnable.
 void addErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
          Adds a listener that is notified of error from any runnable.
 java.lang.String getName()
          Returns the name of the thread pool.
 FifoQueue getRunQueue()
          Returns the input queue where Runnableobjects are enqueued.
 int getStatus()
          Returns the current status of the fiber.
private  int livingFiberCount()
          Returns the current number of living fibers in the pool.
 void removeCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
          Removes a previous register listener.
 void removeErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
          Removes a previous register listener.
 void start()
          Starts the thread pool.
 void stop()
          Begins the shutdown process of the thread pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_delegateQ

private RunnableConsumerThreadPool.SizingFifoQueue m_delegateQ
The queue where runnable objects are added.


m_fibers

private Fiber[] m_fibers
The list of running fibers in the pool. The list allows the size of the pool to vary.


m_poolName

private java.lang.String m_poolName
The name of the pool.


m_hiRatio

private float m_hiRatio
The high water mark ratio for the pool.


m_loRatio

private float m_loRatio
The low water mark ratio for the pool.


m_maxSize

private int m_maxSize
The maximum size for the thread pool.


m_log4jPrefix

private java.lang.String m_log4jPrefix
The log4j prefix used when starting up a new fiber!


m_poolStatus

private int m_poolStatus
The pool status


m_completedListeners

private java.util.List m_completedListeners
The set of listeners to call when a Runnable completes successfully.


m_tGroup

private java.lang.ThreadGroup m_tGroup
The thread group that all pool threads belong to.


m_errorListeners

private java.util.List m_errorListeners
The set of listeners to call when a Runnable fails to complete successfully.

Constructor Detail

RunnableConsumerThreadPool

public RunnableConsumerThreadPool(java.lang.String name,
                                  float loMark,
                                  float hiMark,
                                  int max)

Constructs a new instance of the thread pool class. The thread pool consumes Runnableinstances from the input queue, calling the run method as they are consumed.

The size of the thread pool is controlled by the low and high water marks, each water mark being the ratio of queue elements to threads. As the ratio grows past the high water mark more threads are added, up to the maximum amount. As the ratio drops past the low water mark the number of threads are reduced.

Parameters:
name - The name of the thread pool.
loMark - The lower ratio used to mark thread reduction.
hiMark - The high ration used to mark thread production.
max - The maximum number of threads in the pool.
Throws:
java.lang.IllegalArgumentException - Thrown if the low or high marks are invalid, or the maximum number of threads is invalid.
Method Detail

livingFiberCount

private int livingFiberCount()
Returns the current number of living fibers in the pool. A living fiber is any fiber that is not currently in a Stopped state. If the fiber is stopped then its entry will be removed from the internal array to allow for garbage collection.

Returns:
The number of non-stopped fibers

getRunQueue

public FifoQueue getRunQueue()
Returns the input queue where Runnableobjects are enqueued. Each runnable object will be executed in the order that it is entered.

Returns:
The Runnable input queue.

start

public void start()
Starts the thread pool. The first thread is delayed until at least one element is added to the input queue.

Specified by:
start in interface Fiber

stop

public void stop()
Begins the shutdown process of the thread pool. The status is set to stop pending and each thread is notified of the new status.

Specified by:
stop in interface Fiber

getStatus

public int getStatus()
Returns the current status of the fiber.

Specified by:
getStatus in interface Fiber
Returns:
The current pool status.

getName

public java.lang.String getName()
Returns the name of the thread pool.

Specified by:
getName in interface Fiber
Returns:
The name of the pool.

addCompletionListener

public void addCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
Adds a listener that is notified upon completion of each runnable.

Parameters:
listener - The listener notified on runnable completion.

removeCompletionListener

public void removeCompletionListener(RunnableConsumerThreadPool.RunnableCompletionListener listener)
Removes a previous register listener.

Parameters:
listener - The listener to remove from notification.

addErrorListener

public void addErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
Adds a listener that is notified of error from any runnable.

Parameters:
listener - The listener notified on runnable completion.

removeErrorListener

public void removeErrorListener(RunnableConsumerThreadPool.RunnableErrorListener listener)
Removes a previous register listener.

Parameters:
listener - The listener to remove from notification.

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.