org.gridbus.broker.persistence.db
Class DBReader

java.lang.Object
  |
  +--org.gridbus.broker.persistence.db.DBReader
All Implemented Interfaces:
Reader

public class DBReader
extends java.lang.Object
implements Reader

Author:
krishna

Constructor Summary
DBReader()
           
DBReader(java.lang.String driver, java.lang.String connectionString, java.lang.String username, java.lang.String password)
          Constructor specifying the JDBC driver class name to use
 
Method Summary
 boolean connect()
          Sets up the database connection
 boolean disconnect()
          Closes the database connection
 State read(java.lang.Object brokerID)
          Reads all the data related to the invocation of the broker with the given brokerID from storage and returns the FarmingEngine as a State object.
 State readBrokerInstance(java.lang.Object brokerID)
          Same as the read method without an argument, but reads the instance with the given ID
 DataFile readDataFile(java.lang.Object datafileID, java.lang.Object brokerID)
          Reads the datafile from the store and returns a DataFile object with given ID and brokerID.
 boolean readDataFileHosts(java.util.Collection files, java.util.Collection hosts, java.lang.Object brokerID)
          Reads the DataHosts and DataFiles and sets the links between them
 java.util.Collection readDataFiles(java.lang.Object brokerID)
          Reads all the datafiles associated with the given brokerID and returns a collection of datafiles.
 DataHost readDataHost(java.lang.Object datahostID, java.lang.Object brokerID)
          Reads the datahost from the store and returns a DataHost object with given ID and brokerID.
 java.util.Collection readDataHosts(java.lang.Object brokerID)
          Reads all the datahosts associated with the given brokerID and returns a collection of datahosts.
 java.lang.Object readEvent(java.lang.Object eventID, java.lang.Object brokerID)
          Reads the event with the given eventID from the "history" table and returns a BrokerEvent object
 java.lang.Object readEvents(java.lang.Object brokerID)
          Reads the history of events and returns a collection of BrokerEvent objects
 Job readJob(java.lang.Object jobID, java.lang.Object brokerID)
          Reads the job with the given jobID and brokerID from the store, and returns a Job object
 long readJobCount(java.lang.Object brokerID)
           
 long readJobCount(java.lang.Object brokerID, int jobStatus)
           
 java.util.Collection readJobs(java.lang.Object brokerID)
          Returns the jobs collection read from the DB.
 java.util.Collection readJobs(java.lang.Object brokerID, int jobStatus)
          Reads jobs from the persistent storage with the given status, and returns a vector (collection) of jobs with the given brokerID
 boolean readJobVariables(java.util.Collection jobs, java.util.Collection variables, java.lang.Object brokerID)
          Reads the job-variable values, and sets up the links between them.
 java.util.Vector readNextNJobs(java.lang.Object brokerID, java.lang.String lastJobID, int n)
          Returns the next 'N' jobs in sequence from the persistent store, if available.
 java.util.Vector readNextNJobs(java.lang.Object brokerID, java.lang.String lastJobID, int n, int jobStatus)
          If a jobStatus of -999 is passed in, jobs with all statuses are retrieved.
 java.util.Vector readNextNServers(java.lang.String brokerID, java.lang.String lastServerID, int n)
          Returns the next 'N' servers in sequence from the persistent store, if available.
 java.util.Vector readNextNServers(java.lang.String brokerID, java.lang.String lastServerID, int n, int serverStatus)
          The status -999 is used to indicate "all" servers.
 ComputeServer readServer(java.lang.Object serverID, java.lang.Object brokerID)
          Returns the ComputeServer record read from the DB corresponding to the given serverID and brokerID
 long readServerCount(java.lang.Object brokerID)
           
 long readServerCount(java.lang.Object brokerID, int serverStatus)
           
 java.util.Collection readServers(java.lang.Object brokerID)
          Reads all the ComputeServers associated with the given brokerID and returns a collection of servers.
 java.util.Collection readServers(java.lang.Object brokerID, int serverStatus)
          Reads servers from the persistent storage, and returns a vector (collection) of computeservers with the given brokerID
 Task readTask(java.lang.Object taskID, java.lang.Object brokerID)
          Reads the task with the given taskID and returns a Task object
 java.util.Collection readTasks(java.lang.Object brokerID)
          Reads the tasks associated with the given brokerID
 Variable readVariable(java.lang.Object varID, java.lang.Object brokerID)
           
 java.util.Collection readVariables(java.lang.Object brokerID)
          Reads the variables associated with the given brokerID
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBReader

public DBReader()
         throws java.lang.Exception
Throws:
java.lang.Exception

DBReader

public DBReader(java.lang.String driver,
                java.lang.String connectionString,
                java.lang.String username,
                java.lang.String password)
         throws java.lang.Exception
Constructor specifying the JDBC driver class name to use

Parameters:
driver -
connectionString -
username -
password -
Throws:
java.lang.Exception
Method Detail

connect

public boolean connect()
                throws java.lang.Exception
Sets up the database connection

Specified by:
connect in interface Reader
Returns:
Throws:
java.lang.Exception

disconnect

public boolean disconnect()
                   throws java.lang.Exception
Closes the database connection

Specified by:
disconnect in interface Reader
Returns:
Throws:
java.lang.Exception

readBrokerInstance

public State readBrokerInstance(java.lang.Object brokerID)
                         throws java.lang.Exception
Description copied from interface: Reader
Same as the read method without an argument, but reads the instance with the given ID

Specified by:
readBrokerInstance in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readBrokerInstance(java.lang.Object)

readTasks

public java.util.Collection readTasks(java.lang.Object brokerID)
                               throws java.lang.Exception
Description copied from interface: Reader
Reads the tasks associated with the given brokerID

Specified by:
readTasks in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception

readVariables

public java.util.Collection readVariables(java.lang.Object brokerID)
                                   throws java.lang.Exception
Description copied from interface: Reader
Reads the variables associated with the given brokerID

Specified by:
readVariables in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readVariables(java.lang.Object)

readJobs

public java.util.Collection readJobs(java.lang.Object brokerID)
                              throws java.lang.Exception
Returns the jobs collection read from the DB.

Specified by:
readJobs in interface Reader
Parameters:
brokerID -
Returns:
collection of job objects (or objects of its subclasses)
Throws:
java.lang.Exception
See Also:
Reader.readJobs(java.lang.Object)

readEvent

public java.lang.Object readEvent(java.lang.Object eventID,
                                  java.lang.Object brokerID)
                           throws java.lang.Exception
Reads the event with the given eventID from the "history" table and returns a BrokerEvent object

Specified by:
readEvent in interface Reader
Parameters:
eventID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readEvent(java.lang.Object, java.lang.Object)

readEvents

public java.lang.Object readEvents(java.lang.Object brokerID)
                            throws java.lang.Exception
Reads the history of events and returns a collection of BrokerEvent objects

Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception

readJob

public Job readJob(java.lang.Object jobID,
                   java.lang.Object brokerID)
            throws java.lang.Exception
Reads the job with the given jobID and brokerID from the store, and returns a Job object

Specified by:
readJob in interface Reader
Parameters:
jobID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readJob(java.lang.Object, java.lang.Object)

readServer

public ComputeServer readServer(java.lang.Object serverID,
                                java.lang.Object brokerID)
                         throws java.lang.Exception
Returns the ComputeServer record read from the DB corresponding to the given serverID and brokerID

Specified by:
readServer in interface Reader
Parameters:
serverID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readServer(java.lang.Object, java.lang.Object)

readVariable

public Variable readVariable(java.lang.Object varID,
                             java.lang.Object brokerID)
                      throws java.lang.Exception
Specified by:
readVariable in interface Reader
Parameters:
varID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readVariable(java.lang.Object, java.lang.Object)

readServers

public java.util.Collection readServers(java.lang.Object brokerID)
                                 throws java.lang.Exception
Reads all the ComputeServers associated with the given brokerID and returns a collection of servers. The servers are not associated with jobs by this method, and the jobs have to be explicitly read and set by the caller.

Specified by:
readServers in interface Reader
Parameters:
brokerID -
Returns:
collection of computeserver objects (or objects of its subclasses)
Throws:
java.lang.Exception
See Also:
Reader.readServers(java.lang.Object)

readDataFiles

public java.util.Collection readDataFiles(java.lang.Object brokerID)
                                   throws java.lang.Exception
Reads all the datafiles associated with the given brokerID and returns a collection of datafiles. The datafiles are not associated with DataHosts by this method, and the DataHosts have to be explicitly read and set by the caller, by calling "readDataFileHosts"

Specified by:
readDataFiles in interface Reader
Parameters:
brokerID -
Returns:
collection of datafile objects
Throws:
java.lang.Exception
See Also:
Reader.readDataFiles(java.lang.Object)

readDataFileHosts

public boolean readDataFileHosts(java.util.Collection files,
                                 java.util.Collection hosts,
                                 java.lang.Object brokerID)
                          throws java.lang.Exception
Reads the DataHosts and DataFiles and sets the links between them

Parameters:
files -
hosts -
brokerID -
Returns:
Throws:
java.lang.Exception

readJobVariables

public boolean readJobVariables(java.util.Collection jobs,
                                java.util.Collection variables,
                                java.lang.Object brokerID)
                         throws java.lang.Exception
Reads the job-variable values, and sets up the links between them. Returns true if the operation is successful.

Parameters:
jobs -
variables -
brokerID -
Returns:
Throws:
java.lang.Exception

readDataFile

public DataFile readDataFile(java.lang.Object datafileID,
                             java.lang.Object brokerID)
                      throws java.lang.Exception
Reads the datafile from the store and returns a DataFile object with given ID and brokerID. The datafile is not associated with DataHosts, by this method, and the DataHosts have to be explicitly read and set by the caller by calling "readDataFileHosts"

Specified by:
readDataFile in interface Reader
Parameters:
datafileID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readDataFile(java.lang.Object, java.lang.Object)

readDataHosts

public java.util.Collection readDataHosts(java.lang.Object brokerID)
                                   throws java.lang.Exception
Reads all the datahosts associated with the given brokerID and returns a collection of datahosts. The datahosts are not associated with datafiles by this method, and the datafiles have to be explicitly read and set by the caller by calling readDataFileHosts

Specified by:
readDataHosts in interface Reader
Parameters:
brokerID -
Returns:
hashtable containing the datahost names as keys and datahost objects as values
Throws:
java.lang.Exception
See Also:
Reader.readDataHosts(java.lang.Object)

readDataHost

public DataHost readDataHost(java.lang.Object datahostID,
                             java.lang.Object brokerID)
                      throws java.lang.Exception
Reads the datahost from the store and returns a DataHost object with given ID and brokerID. The datahost is not associated with datafiles, by this method, and the datafiles have to be explicitly read and set by the caller, by calling "readDataFileHosts"

Specified by:
readDataHost in interface Reader
Parameters:
datahostID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readDataHost(java.lang.Object, java.lang.Object)

read

public State read(java.lang.Object brokerID)
           throws java.lang.Exception
Description copied from interface: Reader
Reads all the data related to the invocation of the broker with the given brokerID from storage and returns the FarmingEngine as a State object. It is the job of the caller to ensure that the objects are in a consistent state.

Specified by:
read in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.read(java.lang.Object)

readTask

public Task readTask(java.lang.Object taskID,
                     java.lang.Object brokerID)
              throws java.lang.Exception
Description copied from interface: Reader
Reads the task with the given taskID and returns a Task object

Specified by:
readTask in interface Reader
Parameters:
taskID -
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readTask(java.lang.Object, Object)

readJobCount

public long readJobCount(java.lang.Object brokerID)
                  throws java.lang.Exception
Specified by:
readJobCount in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readJobCount(Object)

readJobCount

public long readJobCount(java.lang.Object brokerID,
                         int jobStatus)
                  throws java.lang.Exception
Specified by:
readJobCount in interface Reader
Parameters:
brokerID -
jobStatus -
Returns:
the number of jobs with the given status
Throws:
java.lang.Exception
See Also:
Reader.readJobCount(java.lang.Object, int)

readJobs

public java.util.Collection readJobs(java.lang.Object brokerID,
                                     int jobStatus)
                              throws java.lang.Exception
Description copied from interface: Reader
Reads jobs from the persistent storage with the given status, and returns a vector (collection) of jobs with the given brokerID

Specified by:
readJobs in interface Reader
Parameters:
brokerID -
jobStatus -
Returns:
collection of job objects (or objects of its subclasses)
Throws:
java.lang.Exception
See Also:
Reader.readJobs(java.lang.Object, int)

readServers

public java.util.Collection readServers(java.lang.Object brokerID,
                                        int serverStatus)
                                 throws java.lang.Exception
Description copied from interface: Reader
Reads servers from the persistent storage, and returns a vector (collection) of computeservers with the given brokerID

Specified by:
readServers in interface Reader
Parameters:
brokerID -
serverStatus -
Returns:
collection of computeserver objects (or objects of its subclasses)
Throws:
java.lang.Exception
See Also:
Reader.readServers(java.lang.Object, int)

readServerCount

public long readServerCount(java.lang.Object brokerID)
                     throws java.lang.Exception
Specified by:
readServerCount in interface Reader
Parameters:
brokerID -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readServerCount(Object)

readServerCount

public long readServerCount(java.lang.Object brokerID,
                            int serverStatus)
                     throws java.lang.Exception
Specified by:
readServerCount in interface Reader
Parameters:
brokerID -
serverStatus -
Returns:
the number of servers with the given status
Throws:
java.lang.Exception
See Also:
Reader.readServerCount(Object,int)

readNextNJobs

public java.util.Vector readNextNJobs(java.lang.Object brokerID,
                                      java.lang.String lastJobID,
                                      int n)
                               throws java.lang.Exception
Description copied from interface: Reader
Returns the next 'N' jobs in sequence from the persistent store, if available. If no jobs are available, an empty vector is returned.

Specified by:
readNextNJobs in interface Reader
Parameters:
brokerID -
lastJobID - (the ID of the job that was most recently retrieved). If this is null, then it starts from the first job
n -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readNextNJobs(java.lang.Object, java.lang.String, int)

readNextNJobs

public java.util.Vector readNextNJobs(java.lang.Object brokerID,
                                      java.lang.String lastJobID,
                                      int n,
                                      int jobStatus)
                               throws java.lang.Exception
If a jobStatus of -999 is passed in, jobs with all statuses are retrieved.

Specified by:
readNextNJobs in interface Reader
Parameters:
brokerID -
lastJobID - (the ID of the job that was most recently retrieved). If this is null, then it starts from the first job
n -
jobStatus -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readNextNJobs(java.lang.Object, java.lang.String, int, int)

readNextNServers

public java.util.Vector readNextNServers(java.lang.String brokerID,
                                         java.lang.String lastServerID,
                                         int n)
                                  throws java.lang.Exception
Description copied from interface: Reader
Returns the next 'N' servers in sequence from the persistent store, if available. If no servers are available, an empty vector is returned.

Specified by:
readNextNServers in interface Reader
Parameters:
brokerID -
lastServerID -
n -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readNextNServers(java.lang.String, java.lang.String, int)

readNextNServers

public java.util.Vector readNextNServers(java.lang.String brokerID,
                                         java.lang.String lastServerID,
                                         int n,
                                         int serverStatus)
                                  throws java.lang.Exception
The status -999 is used to indicate "all" servers.

Specified by:
readNextNServers in interface Reader
Parameters:
brokerID -
lastServerID -
n -
serverStatus -
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readNextNServers(java.lang.String, java.lang.String, int, int)