org.opennms.core.concurrent
Class RunnableConsumerThreadPool

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

public class RunnableConsumerThreadPool
extends Object
implements Fiber

RunnableConsumerThreadPool class.

Version:
$Id: $
Author:
ranger

Nested Class Summary
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.
 
Field Summary
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
RunnableConsumerThreadPool(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.
 String getName()
          Returns the name of the thread pool.
 FifoQueue<Runnable> getRunQueue()
          Returns the input queue where Runnableobjects are enqueued.
 int getStatus()
          Returns the current status of the fiber.
 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
 

Constructor Detail

RunnableConsumerThreadPool

public RunnableConsumerThreadPool(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:
IllegalArgumentException - Thrown if the low or high marks are invalid, or the maximum number of threads is invalid.
Method Detail

getRunQueue

public FifoQueue<Runnable> 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 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.


Copyright © 2011. All Rights Reserved.