org.gridbus.broker.persistence.db
Class DBWriter

java.lang.Object
  extended by org.gridbus.broker.persistence.db.DBWriter
All Implemented Interfaces:
Writer

public final class DBWriter
extends java.lang.Object
implements Writer

Author:
krishna This class implements the Writer class to provide persistence, using a RDBMS. It uses JDBC, so that any database can be used with the broker. All the "save*" methods assume there is a valid open connection to the database, and the private field s "state" object is set. To set the state The connect method needs to be called to connect before saving anything. The methods which need transactions should explicitly use transactions on the connection used.

Constructor Summary
DBWriter()
          Default constructor for this class, Assumes the following default values: Database driver: mySQL Database name: gridbusbroker Server: localhost.
DBWriter(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, if it is not already set up.
 boolean disconnect()
          Closes the database connection
 void save(GridbusFarmingEngine gfe)
          Saves the entire broker state to persistent storage.
 void saveBrokerInstance(GridbusFarmingEngine gfe)
          Saves the global broker properties and broker instance state to persistent storage.
 void saveDataFile(DataFile df, java.lang.Object brokerID)
          Saves a datafile to persistent storage.
 void saveDataFiles(java.util.Collection datafiles, java.lang.Object brokerID)
          Saves a collection of datafile to persistent storage.
 void saveDataHost(DataHost dh, java.lang.Object brokerID)
          Saves a datahost to persistent storage
 void saveDataHosts(java.util.Collection datahosts, java.lang.Object brokerID)
          Saves a collection of datahosts to persistent storage
 void saveEvent(GridbusFarmingEngine gfe, java.lang.Object eventID, java.lang.Object sourceID, java.lang.Object brokerID)
          Saves this event to the state table, which keeps track of event history
 void saveJob(Job j, java.lang.Object brokerID)
          Saves a job to persistent storage
 void saveJobs(java.util.Collection jobs, java.lang.Object brokerID)
          Saves a collection of jobs to persistent storage
 void saveServer(ComputeServer cs, java.lang.Object brokerID)
          Saves a compute server to persistent storage
 void saveServers(java.util.Collection servers, java.lang.Object brokerID)
          Saves a collection of computeServers to persistent storage
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBWriter

public DBWriter()
         throws java.lang.Exception
Default constructor for this class, Assumes the following default values: Database driver: mySQL Database name: gridbusbroker Server: localhost. Username: brokeruser, password: gridbus It is always better to use the constructor which takes the driver and connectionString parameters.

Throws:
java.lang.Exception

DBWriter

public DBWriter(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

saveDataHost

public void saveDataHost(DataHost dh,
                         java.lang.Object brokerID)
                  throws java.lang.Exception
Description copied from interface: Writer
Saves a datahost to persistent storage

Specified by:
saveDataHost in interface Writer
Parameters:
dh -
brokerID -
Throws:
java.lang.Exception
See Also:
Writer.saveDataHost(org.gridbus.broker.farming.common.data.DataHost, Object)

saveDataFile

public void saveDataFile(DataFile df,
                         java.lang.Object brokerID)
                  throws java.lang.Exception
Description copied from interface: Writer
Saves a datafile to persistent storage.

Specified by:
saveDataFile in interface Writer
Parameters:
df -
brokerID -
Throws:
java.lang.Exception
See Also:
Writer.saveDataFile(org.gridbus.broker.farming.common.data.DataFile, Object)

saveJob

public void saveJob(Job j,
                    java.lang.Object brokerID)
             throws java.lang.Exception
Description copied from interface: Writer
Saves a job to persistent storage

Specified by:
saveJob in interface Writer
Parameters:
j -
Throws:
java.lang.Exception
See Also:
Writer.saveJob(org.gridbus.broker.farming.common.Job, Object)

saveServer

public void saveServer(ComputeServer cs,
                       java.lang.Object brokerID)
                throws java.lang.Exception
Description copied from interface: Writer
Saves a compute server to persistent storage

Specified by:
saveServer in interface Writer
Parameters:
cs -
Throws:
java.lang.Exception
See Also:
Writer.saveServer(org.gridbus.broker.farming.common.ComputeServer, Object)

saveBrokerInstance

public void saveBrokerInstance(GridbusFarmingEngine gfe)
                        throws java.lang.Exception
Description copied from interface: Writer
Saves the global broker properties and broker instance state to persistent storage. This method just saves the broker instance itself, and not the objects contained in / linked with the broker. For saving the entire state, use the save(State) method.

Specified by:
saveBrokerInstance in interface Writer
Parameters:
gfe -
Throws:
java.lang.Exception

connect

public boolean connect()
                throws java.lang.Exception
Sets up the database connection, if it is not already set up. So, an existing connection is always re-used, if possible.

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

disconnect

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

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

saveEvent

public void saveEvent(GridbusFarmingEngine gfe,
                      java.lang.Object eventID,
                      java.lang.Object sourceID,
                      java.lang.Object brokerID)
               throws java.lang.Exception
Saves this event to the state table, which keeps track of event history

Specified by:
saveEvent in interface Writer
Parameters:
gfe -
eventID -
sourceID -
brokerID -
Throws:
java.lang.Exception

save

public void save(GridbusFarmingEngine gfe)
          throws java.lang.Exception
Description copied from interface: Writer
Saves the entire broker state to persistent storage. All the save methods assume there is an open connecction to persistent storage, whether it is a database, or the file system or a network socket etc..

Specified by:
save in interface Writer
Parameters:
gfe -
Throws:
java.lang.Exception

saveDataHosts

public void saveDataHosts(java.util.Collection datahosts,
                          java.lang.Object brokerID)
                   throws java.lang.Exception
Description copied from interface: Writer
Saves a collection of datahosts to persistent storage

Specified by:
saveDataHosts in interface Writer
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Writer#saveDataHosts(java.util.Vector, Object)

saveDataFiles

public void saveDataFiles(java.util.Collection datafiles,
                          java.lang.Object brokerID)
                   throws java.lang.Exception
Description copied from interface: Writer
Saves a collection of datafile to persistent storage.

Specified by:
saveDataFiles in interface Writer
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Writer#saveDataFiles(java.util.Vector, Object)

saveJobs

public void saveJobs(java.util.Collection jobs,
                     java.lang.Object brokerID)
              throws java.lang.Exception
Description copied from interface: Writer
Saves a collection of jobs to persistent storage

Specified by:
saveJobs in interface Writer
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Writer#saveJobs(java.util.Vector, Object)

saveServers

public void saveServers(java.util.Collection servers,
                        java.lang.Object brokerID)
                 throws java.lang.Exception
Description copied from interface: Writer
Saves a collection of computeServers to persistent storage

Specified by:
saveServers in interface Writer
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Writer#saveServers(java.util.Vector, Object)