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

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

public final class DBRunnableConsumerThread
extends PollerThread

The DBRunnableConsumerThread class is similar to RunnableConsumerThread. It creates or uses an existing database connection and deals with a queue of DBRunnable objects that are executed with the database connection.

Version:
$Revision: 1.2 $
Author:
Sowmya, Weave, OpenNMS

Field Summary
private  Connection m_dbConn
          The connection to the sql database.
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
DBRunnableConsumerThread(PCQueue input, Connection dbconn)
          Constructs a thread consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(PCQueue input, PCQueue output, Connection dbconn)
          Constructs a consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(PCQueue input, PCQueue output, String dbDriver, String url, String user, String passwd)
          Constructs a consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(PCQueue input, String dbDriver, String url, String user, String passwd)
          Constructs a thread consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(String name, PCQueue input, Connection dbconn)
          Constructs a thread consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(String name, PCQueue input, PCQueue output, Connection dbconn)
          Constructs a consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(String name, PCQueue input, PCQueue output, String dbDriver, String url, String user, String passwd)
          Constructs a consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(String name, PCQueue input, String dbDriver, String url, String user, String passwd)
          Constructs a thread consumer of objects that implement the DBRunnable interface.
DBRunnableConsumerThread(ThreadGroup grp, String name, PCQueue input, Connection dbconn)
          Constructs a thread consumer of objects that implement the Runnable interface.
DBRunnableConsumerThread(ThreadGroup grp, String name, PCQueue input, PCQueue output, Connection dbconn)
          Constructs a threadconsumer of objects that implement the Runnable interface.
DBRunnableConsumerThread(ThreadGroup grp, String name, PCQueue input, PCQueue output, String dbDriver, String url, String user, String passwd)
          Constructs a threadconsumer of objects that implement the Runnable interface.
DBRunnableConsumerThread(ThreadGroup grp, String name, PCQueue input, String dbDriver, String url, String user, String passwd)
          Constructs a thread consumer of objects that implement the Runnable interface.
 
Method Summary
private  void dbConnect(String dbDriver, String url, String user, String passwd)
          Called by the constructor for this class.
 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.


m_dbConn

private Connection m_dbConn

The connection to the sql database.


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

DBRunnableConsumerThread

public DBRunnableConsumerThread(PCQueue input,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

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

Parameters:
input - The source of the runnable objects.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(PCQueue input,
                                Connection dbconn)

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

Parameters:
input - The source of the runnable objects.
dbconn - An existing JDBC connection.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

DBRunnableConsumerThread

public DBRunnableConsumerThread(PCQueue input,
                                PCQueue output,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

Constructs a consumer of objects that implement the DBRunnable 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.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(PCQueue input,
                                PCQueue output,
                                Connection dbconn)

Constructs a consumer of objects that implement the DBRunnable 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.
dbconn - An existing JDBC connection.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.

DBRunnableConsumerThread

public DBRunnableConsumerThread(String name,
                                PCQueue input,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

Constructs a thread consumer of objects that implement the DBRunnable 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.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(String name,
                                PCQueue input,
                                Connection dbconn)

Constructs a thread consumer of objects that implement the DBRunnable 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.
dbconn - An existing JDBC conneciton.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

DBRunnableConsumerThread

public DBRunnableConsumerThread(String name,
                                PCQueue input,
                                PCQueue output,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

Constructs a consumer of objects that implement the DBRunnable 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.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(String name,
                                PCQueue input,
                                PCQueue output,
                                Connection dbconn)

Constructs a consumer of objects that implement the DBRunnable 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.
dbconn - An existing connection to the database.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.

DBRunnableConsumerThread

public DBRunnableConsumerThread(ThreadGroup grp,
                                String name,
                                PCQueue input,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

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.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(ThreadGroup grp,
                                String name,
                                PCQueue input,
                                Connection dbconn)

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.
dbconn - An existing connection to the database.
Throws:
IllegalArgumentException - Thrown if the input queue is not valid.

DBRunnableConsumerThread

public DBRunnableConsumerThread(ThreadGroup grp,
                                String name,
                                PCQueue input,
                                PCQueue output,
                                String dbDriver,
                                String url,
                                String user,
                                String passwd)
                         throws ClassNotFoundException,
                                SQLException

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.
dbDriver - The JDBC driver class name
url - The URL location of the database
user - The user for the connection
passwd - The password for the user.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.
ClassNotFoundException - Thrown if the driver class cannot be loaded.
SQLException - Thrown if an exception is generated in the SQL handing of the connect.

DBRunnableConsumerThread

public DBRunnableConsumerThread(ThreadGroup grp,
                                String name,
                                PCQueue input,
                                PCQueue output,
                                Connection dbconn)

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.
dbconn - An existing connection to the database.
Throws:
IllegalArgumentException - Thrown if the input or output queue are not valid.
Method Detail

dbConnect

private void dbConnect(String dbDriver,
                       String url,
                       String user,
                       String passwd)
                throws ClassNotFoundException,
                       SQLException

Called by the constructor for this class. It attempts to load the specified JDBC Driver class and allocate a connection to the database. The conection is opened at the specified URL using the passed user name/password combination.

Parameters:
dbDriver - The JDBC Driver class to load
url - The location of the database for the driver
user - The username for the database
passwd - The password for the user
Throws:
ClassNotFoundException - Thrown if the specified driver class cannot be found and loaded.
SQLException - Thrown by the driver if an sql error occurs.

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