org.gridbus.broker.persistence.db
Class DBWriter

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

public 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(State s)
          Saves the entire broker state to persistent storage.
 void saveBrokerInstance(State s)
          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(State s, 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
 void saveTask(Task t, java.lang.Object brokerID)
          Saves a task to persistent storage
 void saveVariable(Variable v, java.lang.Object brokerID)
          Saves a variable to persistent storage
 void saveVariables(java.util.Collection variables, java.lang.Object brokerID)
          Saves a collection of variables 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 -
brokerID -
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 -
brokerID -
Throws:
java.lang.Exception
See Also:
Writer.saveServer(org.gridbus.broker.farming.common.ComputeServer, Object)

saveTask

public void saveTask(Task t,
                     java.lang.Object brokerID)
              throws java.lang.Exception
Description copied from interface: Writer
Saves a task to persistent storage

Specified by:
saveTask in interface Writer
Parameters:
t -
brokerID -
Throws:
java.lang.Exception
See Also:
Writer.saveTask(org.gridbus.broker.runfile.Task, Object)

saveVariable

public void saveVariable(Variable v,
                         java.lang.Object brokerID)
                  throws java.lang.Exception
Description copied from interface: Writer
Saves a variable to persistent storage

Specified by:
saveVariable in interface Writer
Parameters:
v -
brokerID -
Throws:
java.lang.Exception

saveBrokerInstance

public void saveBrokerInstance(State s)
                        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:
s -
Throws:
java.lang.Exception
See Also:
Writer.saveBrokerInstance(org.gridbus.broker.persistence.State)

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(State s,
                      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:
s -
eventID -
sourceID -
brokerID -
Throws:
java.lang.Exception
See Also:
Writer.saveEvent(org.gridbus.broker.persistence.State, Object, Object, Object)

save

public void save(State s)
          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:
s -
Throws:
java.lang.Exception
See Also:
Writer.save(org.gridbus.broker.persistence.State)

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
Parameters:
datahosts -
brokerID -
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
Parameters:
datafiles -
brokerID -
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
Parameters:
jobs -
brokerID -
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
Parameters:
servers -
brokerID -
Throws:
java.lang.Exception
See Also:
org.gridbus.broker.persistence.Writer#saveServers(java.util.Vector, Object)

saveVariables

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

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