org.gridbus.broker.persistence.db
Class DBReader

java.lang.Object
  extended by org.gridbus.broker.persistence.db.DBReader
All Implemented Interfaces:
Reader

public final 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
 GridbusFarmingEngine 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.
 GridbusFarmingEngine 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)
           
 long readJobCount(java.lang.String brokerID, int status, java.lang.String serverID)
           
 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
 java.util.Vector readJobs(java.lang.Object brokerID, int pageNumber, int pageSize, int jobStatus)
          Reads a page of jobs with the given status.
 java.util.Vector readNextNJobs(java.lang.Object brokerID, int n)
          Reads and returns 'n' jobs from the persistent store.
 java.util.Vector readNextNJobs(java.lang.Object brokerID, int n, int jobStatus)
          If a jobStatus of Job.ALL is passed in, jobs with all statuses are retrieved.
 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
 
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 GridbusFarmingEngine 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
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readBrokerInstance(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
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
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
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
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readServer(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
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
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

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
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
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
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readDataHost(java.lang.Object, java.lang.Object)

read

public GridbusFarmingEngine 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
Returns:
Throws:
java.lang.Exception
See Also:
Reader.read(java.lang.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
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
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
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
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,
                                      int n)
                               throws java.lang.Exception
Reads and returns 'n' jobs from the persistent store.

Specified by:
readNextNJobs in interface Reader
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readNextNJobs(java.lang.Object, int)

readNextNJobs

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

Specified by:
readNextNJobs in interface Reader
Returns:
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Reader#readNextNJobs(java.lang.Object, java.lang.String, int, int)

readJobCount

public long readJobCount(java.lang.String brokerID,
                         int status,
                         java.lang.String serverID)
                  throws java.lang.Exception
Specified by:
readJobCount in interface Reader
Returns:
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Reader#readJobCount(java.lang.String, int, org.gridbus.broker.farming.common.ComputeServer)

readJobs

public java.util.Vector readJobs(java.lang.Object brokerID,
                                 int pageNumber,
                                 int pageSize,
                                 int jobStatus)
                          throws java.lang.Exception
Description copied from interface: Reader
Reads a page of jobs with the given status. Returns an empty collection if there are no jobs corresponding to the given page number / size.

Specified by:
readJobs in interface Reader
Returns:
Throws:
java.lang.Exception
See Also:
Reader.readJobs(java.lang.Object, int, int, int)