[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/repository/db4o Db4oJobController
Brought to you by:
suresh_pragada
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/repository/db4o In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18609 Added Files: Db4oJobControllerHolder.java Db4oJobDataTransfer.java Db4oMgmtMntrInfoHolder.java Db4oRepository.java Log Message: no message --- NEW FILE: Db4oMgmtMntrInfoHolder.java --- /* * Db4oMgmtMntrInfoHolder.java * * Created on March 15, 2006, 10:54 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.framework.repository.db4o; /** * Db4oMgmtMntrInfoHolder holds the job mgmt&mntr information and job name. * This will be used only by Db4oRepository. * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ class Db4oMgmtMntrInfoHolder { /** * Holds the job name */ private String jobName=null; /** * Holds the mgmtMntrInfo object */ private Object mgmtMntrInfo=null; /** * Constructor takes job name and mgmt & mntr info and constructs the object. */ Db4oMgmtMntrInfoHolder(String jobName,Object mgmtMntrInfo) { this.jobName=jobName; this.mgmtMntrInfo=mgmtMntrInfo; } /** * Returns the jobName. */ public String getJobName() { return this.jobName; } /** * Returns the mgmt & mntr object. */ public Object getMgmtMntrInfo() { return this.mgmtMntrInfo; } /** * <p> * Returns the string representation of Db4oMgmtMntrInfoHolder class in the format * <br> {Db4oMgmtMntrInfoHolder [jobName = value] [mgmtMntrInfo = value]} * </p> * * @return Returns the string representation of Db4oMgmtMntrInfoHolder. */ public String toString() { StringBuffer stringValue=new StringBuffer("{Db4oMgmtMntrInfoHolder "); stringValue.append("[jobName = " + this.jobName + "]"); stringValue.append("[mgmtMntrInfo = " + this.mgmtMntrInfo + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: Db4oJobDataTransfer.java --- /* * Db4oJobDataTransfer.java * * Created on March 15, 2006, 10:39 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.framework.repository.db4o; /** * <p> * Db4oJobDataTransfer holds the data being transferred between the jobs. * This will not have any functionality except holding the data and * this will be used to store in DB4O database. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ class Db4oJobDataTransfer { /** * Holds the identifier by which jobs will communicated. */ private String dataIdentifier; /** * Source job name. */ private String sourceJobName; /** * Target job name, where data to be sent. */ private String targetJobName; /** * Data object. */ private Object data; /** * Constructor with all the argument to make this class immutable, * once it got created. */ Db4oJobDataTransfer(String dataIdentifer,String sourceJobName,String targetJobName,Object data) { this.dataIdentifier=dataIdentifer; this.sourceJobName=sourceJobName; this.targetJobName=targetJobName; this.data=data; } /** * Returns the data identifier. */ public String getDataIdentifier() { return this.dataIdentifier; } /** * Returns the source job name. */ public String getSourceJobName() { return this.sourceJobName; } /** * Returns the target job name. */ public String getTargetJobName() { return this.targetJobName; } /** * Returns the job data. */ public Object getData() { return this.data; } /** * <p> * Returns the string representation of Db4oJobDataTransfer class in the format * <br> {Db4oJobDataTransfer [dataIdentifier = value] [sourceJN = value] * [targetJN = value] [data = value]} * </p> * * @return Returns the string representation of Db4oJobDataTransfer. */ public String toString() { StringBuffer stringValue=new StringBuffer("{Db4oJobDataTransfer "); stringValue.append("[dataIdentifier = " + this.dataIdentifier + "]"); stringValue.append("[sourceJobName = " + this.sourceJobName + "]"); stringValue.append("[targetJobName = " + this.targetJobName + "]"); stringValue.append("[Data = " + this.data + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: Db4oJobControllerHolder.java --- /* * Db4oJobControllerHolder.java * * Created on March 15, 2006, 10:52 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.framework.repository.db4o; import org.jmonks.batchserver.framework.controller.JobController; /** * Db4oJobControllerHolder holds the job controller object and job name. * This class will be accessed by only Db4oRepository. * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ class Db4oJobControllerHolder { /** * Holds the job name */ private String jobName=null; /** * Holds the job controller object */ private JobController jobController=null; /** * Constructor takes job name and job controller to constructs the object. */ Db4oJobControllerHolder(String jobName,JobController jobController) { this.jobName=jobName; this.jobController=jobController; } /** * Returns the jobName. */ public String getJobName() { return this.jobName; } /** * Returns the mgmt & mntr object. */ public JobController getJobController() { return this.jobController; } /** * <p> * Returns the string representation of Db4oJobControllerHolder class in the format * <br> {Db4oJobControllerHolder [jobName = value] [mgmtMntrInfo = value]} * </p> * * @return Returns the string representation of Db4oJobControllerHolder. */ public String toString() { StringBuffer stringValue=new StringBuffer("{Db4oJobControllerHolder "); stringValue.append("[jobName = " + this.jobName + "]"); stringValue.append("[jobController = " + this.jobController + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: Db4oRepository.java --- package org.jmonks.batchserver.framework.repository.db4o; import com.db4o.Db4o; import com.db4o.ObjectContainer; import com.db4o.ObjectSet; import com.db4o.query.Predicate; import java.io.File; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.repository.Repository; import org.jmonks.batchserver.framework.JobStatistics; /** * <p> * This implementation of repository uses the DB4O database as the repository. * It expects the property repository-location present in the repository configuration * in framework-cofig.xml file. The value of this property should be a valid directory name. * If directory doesnt exist, it will try to create directory with that path. * <br><br> * <pre> * <repository-config repository-class-name="org.jmonks.batchserver.framework.Db4oRepository"> * <property key="repository-location">/batchserver/repository</property> * </repository-config> * </pre> * <br><br> * Here repository-location defines where the DB4O database needs to create * the repository file. By default framework will be configured with the values * shown in the above XML configuration snippet. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class Db4oRepository extends Repository { private static Logger logger=Logger.getLogger(Db4oRepository.class); /** * Property identifies the repository location. */ private static final String PROPERTY_REPOSIOTRY_LOCATION = "repository-location"; /** * Name of the db40 datbase file used as the repository. */ private static final String REPOSITORY_FILENAME = "batchserver_repository.db"; /** * Map holds the configuration properties of repository. */ private Map repositoryConfigProperties=null; /** * Db4o container object. */ ObjectContainer container=null; /** * <p> * Creates the Db4oRepository by accepting the map consist of properties * needed to setup the repository. This make sure repository-location property * has been defined and the value defined for this property is valid. * </p> * @param configProps Map contains the configuration properties. * * @throws ConfigurationException If repository-location property is not defined and * the value specified is invalid. */ public Db4oRepository(Map configProps) { logger.trace("Entering constructor"); this.repositoryConfigProperties=new HashMap(configProps); String repositoryLocation=(String)this.repositoryConfigProperties.get(Db4oRepository.PROPERTY_REPOSIOTRY_LOCATION); if(repositoryLocation==null || "".equals(repositoryLocation)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "repository-location is required for DefaultReposiotry implementation."); else { File repositoryDirectory=new File(repositoryLocation); if(!repositoryDirectory.exists()) { boolean created=repositoryDirectory.mkdirs(); if(!created) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Attempt to create directory " + repositoryLocation + " is failed."); } else if(repositoryDirectory.isFile()) { throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Location " + repositoryLocation + " defined is a file. Directory name is expected."); } /** * Just to make sure, would be able to setup the repository. */ String completeRepositoryFileName=repositoryDirectory.getAbsolutePath()+File.separator+Db4oRepository.REPOSITORY_FILENAME; this.container=Db4o.openFile(completeRepositoryFileName); if(this.container==null) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Unable to create the file " + completeRepositoryFileName + " to setup repository."); } logger.trace("Exiting constructor"); } /** * @see org.jmonks.batchserver.framework.Repository#sendDataToNextJob(String,String,String,Object) */ public boolean sendDatatoNextJob(final String dataIdentifier, final String sourceJobName, final String targetJobName, final Object data) { if(dataIdentifier==null || sourceJobName==null || targetJobName==null || data==null) throw new IllegalArgumentException("No arguments cannot be null to the sendDataToNextJob method."); boolean dataSaved=false; if(this.container==null) dataSaved=false; else { /** * Delete the entries exist with the identifier, source and target job names. */ ObjectSet dataTransferredSet=container.query(new Predicate() { public boolean match(Db4oJobDataTransfer jobDataTransfer) { if(dataIdentifier.equals(jobDataTransfer.getDataIdentifier()) && sourceJobName.equals(jobDataTransfer.getSourceJobName()) && targetJobName.equals(jobDataTransfer.getTargetJobName())) return true; else return false; } }); while(dataTransferredSet.hasNext()) { container.delete(dataTransferredSet.next()); } container.commit(); /** * Add the new entry. */ Db4oJobDataTransfer dataTransfer=new Db4oJobDataTransfer(dataIdentifier, sourceJobName, targetJobName, data); container.set(dataTransfer); container.commit(); dataSaved=true; } return dataSaved; } /** * @see org.jmonks.batchserver.framework.Repository#getDataFromPreviousJob(String,String,String) */ public Object getDataFromPreviousJob(final String dataIdentifier, final String sourceJobName, final String targetJobName) { if(dataIdentifier==null || sourceJobName==null || targetJobName==null) throw new IllegalArgumentException("Data identifer, source job name and target job name cannot be null " + "to get the data from previous job."); if(container==null) return null; else { ObjectSet dataTransferResultSet=container.query(new Predicate() { public boolean match(Db4oJobDataTransfer jobDataTransfer) { if(dataIdentifier.equals(jobDataTransfer.getDataIdentifier()) && sourceJobName.equals(jobDataTransfer.getSourceJobName()) && targetJobName.equals(jobDataTransfer.getTargetJobName())) { return true; } else return false; } }); if(dataTransferResultSet.hasNext()) { return ((Db4oJobDataTransfer)dataTransferResultSet.next()).getData(); } else return null; } } public boolean clearDataTransferredToNextJob(final String jobName) { if(jobName==null) throw new IllegalArgumentException("job name cannot be null."); boolean dataCleared=false; if(container==null) dataCleared=false; else { ObjectSet dataTransferResultSet=container.query(new Predicate() { public boolean match(Db4oJobDataTransfer jobDataTransfer) { if(jobName.equals(jobDataTransfer.getSourceJobName())) { return true; } else return false; } }); while(dataTransferResultSet.hasNext()) container.delete(dataTransferResultSet.next()); container.commit(); dataCleared=true; } return dataCleared; } /** * @see org.jmonks.batchserver.framework.Repository#registerJobMgmtMntrInfo(String,Object) */ public boolean registerJobMgmtMntrInfo(String jobName, Object registrationInfo) { return true; } /** * @see org.jmonks.batchserver.framework.Repository#lookupJobMgmtMntrInfo(String) */ public Object lookupJobMgmtMntrInfo(String jobName) { return null; } /** * @see org.jmonks.batchserver.framework.Repository#unregisterJobMgmtMntrInfo(String) */ public boolean unregisterJobMgmtMntrInfo(String jobName) { return true; } /** * * @see org.jmonks.batchserver.framework.Repository#logStatistics(org.jmonks.batchserver.framework.JobStatistics) */ public boolean logStatistics(JobStatistics statistics) { if(statistics==null) throw new IllegalArgumentException("Null statistic objects will not be saved in repository"); boolean logged=false; if(container==null) logged=false; else { container.set(statistics); container.commit(); logged=true; } return logged; } /** * @see org.jmonks.batchserver.framework.Repository#getStatistics(String) */ public JobStatistics[] getStatistics(final String jobName) { if(jobName==null) throw new IllegalArgumentException("job name cannot be null for querying the job statistics."); JobStatistics[] statistics=null; if(container==null) statistics=new JobStatistics[0]; else { ObjectSet statisticsResultSet=container.query(new Predicate() { public boolean match(JobStatistics jobStatistics) { if(jobName.equals(jobStatistics.getJobname())) return true; else return false; } }); statistics=new JobStatistics[statisticsResultSet.size()]; for(int i=0;statisticsResultSet.hasNext();i++) statistics[i]=(JobStatistics)statisticsResultSet.next(); } return statistics; } /** * @see org.jmonks.batchserver.framework.Repository#saveController(org.jmonks.batchserver.framework.controller.JobController,String) */ public boolean saveController(String jobName, JobController controller) { return true; } /** * @see org.jmonks.batchserver.framework.Repository#loadController(String) */ public JobController loadController(String jobName) { return null; } /** * @see org.jmonks.batchserver.framework.Repository#releaseController(String) */ public boolean releaseController(String jobName) { return true; } } |