Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework DefaultRepository.java,1.3,1.4 Jo
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-15 04:36:38
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18147 Modified Files: DefaultRepository.java JobStatistics.java Repository.java Log Message: no message Index: JobStatistics.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/JobStatistics.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JobStatistics.java 4 Mar 2006 04:48:52 -0000 1.2 --- JobStatistics.java 15 Mar 2006 04:36:32 -0000 1.3 *************** *** 12,27 **** public class JobStatistics { ! private Date startTime; ! private Date endTime; ! private int recordsProcessed; ! private int maxMemoryUsage; ! private String jobName; ! public JobStatistics() { } --- 12,42 ---- public class JobStatistics { ! /** ! * Starting time of the job. ! */ private Date startTime; ! /** ! * Ending time of the job. ! */ private Date endTime; ! /** ! * Number of records processed in this job. ! */ private int recordsProcessed; ! /** ! * Maximum memory usage of this job. ! */ private int maxMemoryUsage; ! /** ! * Name of the job. ! */ private String jobName; ! ! /** ! * Constructor takes the job name and build the skelton. ! */ ! public JobStatistics(String jobName) { + this.jobName=jobName; } *************** *** 33,36 **** --- 48,52 ---- public void setStartTime(Date startTime) { + this.startTime=startTime; } *************** *** 41,48 **** */ public void setEndTime(Date endTime) - { this.endTime = endTime; - } --- 57,62 ---- *************** *** 53,60 **** */ public void setRecordsProcessed(int recordCount) - { this.recordsProcessed = recordCount; - } --- 67,72 ---- *************** *** 66,69 **** --- 78,82 ---- public void setMaxMemeoryUsage(int memoryUsage) { + this.maxMemoryUsage=memoryUsage; } *************** *** 74,81 **** */ public Date getStartTime() - { ! return startTime; ! } --- 87,92 ---- */ public Date getStartTime() { ! return this.startTime; } *************** *** 86,93 **** */ public Date getEndTime() - { ! return endTime; ! } --- 97,102 ---- */ public Date getEndTime() { ! return this.endTime; } *************** *** 98,105 **** */ public int getRecordsProcessed() - { ! return recordsProcessed; ! } --- 107,112 ---- */ public int getRecordsProcessed() { ! return this.recordsProcessed; } *************** *** 110,117 **** */ public int getMaxMemoryUsage() - { ! return maxMemoryUsage; ! } --- 117,122 ---- */ public int getMaxMemoryUsage() { ! return this.maxMemoryUsage; } *************** *** 122,138 **** */ public String getJobname() - { ! return null; ! } ! /** ! * Sets the name of the job. ! * ! * @param jobName Name of the job. */ ! public void setJobname(String jobName) { ! } } --- 127,153 ---- */ public String getJobname() { ! return this.jobName; } ! /** ! * <p> ! * Returns the string representation of JobStatistics class in the format ! * <br> {JobStatistics [jobName = value] [startTime = value] [endTime = value]} ! * </p> ! * ! * @return Returns the string representation of JobStatistics. */ ! public String toString() { ! StringBuffer stringValue=new StringBuffer("{JobStatistics "); ! stringValue.append("[jobName = " + this.jobName + "]"); ! stringValue.append("[startTime = " + ((this.startTime!=null)?this.startTime.toString():"") + "]"); ! stringValue.append("[endTime = " + ((this.endTime!=null)?this.endTime.toString():"") + "]"); ! stringValue.append("[maxMemoryUsage = " + this.maxMemoryUsage + "]"); ! stringValue.append("[recordsProcessed = " + this.recordsProcessed + "]"); ! stringValue.append("}"); ! return stringValue.toString(); ! } ! } Index: Repository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/Repository.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Repository.java 14 Mar 2006 23:00:57 -0000 1.3 --- Repository.java 15 Mar 2006 04:36:32 -0000 1.4 *************** *** 103,145 **** /** ! * Logs the job statistics given in the form of JobStatistics object ! * in the repository for further use/reference. ! * ! * @param statistics Job Statistics object which holds all the statistics related to that job. ! * ! * @return Returns true if statistics can be logged into repository, false, otherwise. ! */ ! public abstract boolean logStatistics(JobStatistics statistics); ! ! /** ! * Data will be sent to the specified component of the specified ! * job behalf of the specific component from specific job. * * @param sourceJobName Name of the source job. - * @param sourceComponent Name of the source componenet. * @param targetJobName Name of the target job. - * @param targetComponent Name of the target component. * @param data Data that needs to be sent as the object. * * @return Returns true, if it could save the data to be sent to the next job. */ ! public abstract boolean sendDatatoNextJob(String sourceJobName, String sourceComponent, ! String targetJobName, String targetComponent, Object data); /** ! * Gets the data that has been sent to this component of this job from ! * specific component of specific job. * * @param sourceJobName Name of the source job. * @param sourceComponent Name of the source componenet. - * @param targetJobName Name of the target job. - * @param targetComponent Name of the target component. * * @return Returns the data, null, if it couldnt find any data. */ ! public abstract Object getDataFromPreviousJob(String sourceJobName, String sourceComponent, ! String targetJobName, String targetComponent); /** * Registers the job management and monitoring info with the given job name. * If there is an association with this job name existing, that information --- 103,146 ---- /** ! * Data will be sent to the specified target job. This data ! * will be marked with the data identifier. Target job ! * should use the data identifier to read the data. * + * @param dataIdentifier Identifier to be used to exchange the data between two jobs.. * @param sourceJobName Name of the source job. * @param targetJobName Name of the target job. * @param data Data that needs to be sent as the object. * * @return Returns true, if it could save the data to be sent to the next job. */ ! public abstract boolean sendDatatoNextJob(String dataIdentifier, String sourceJobName, ! String targetJobName, Object data); /** ! * Gets the data that has been sent to the target job from the source job ! * and identified by the given data identifier. * + * @param dataIdentifier Identifier tied to the data wants to be read. * @param sourceJobName Name of the source job. * @param sourceComponent Name of the source componenet. * * @return Returns the data, null, if it couldnt find any data. */ ! public abstract Object getDataFromPreviousJob(String dataIdentifer, String sourceJobName, ! String targetJobName); /** + * <p> + * Clears the data that has not been received by the target jobs. + * This method will clear all the data that has been put up by + * this job. Usually, this will be called by startp of framework, + * before kickoff the controller. + * </p> + * + * @param jobName Name of job that put up the data. + */ + public abstract boolean clearDataTransferredToNextJob(String jobName); + + /** * Registers the job management and monitoring info with the given job name. * If there is an association with this job name existing, that information *************** *** 173,176 **** --- 174,187 ---- /** + * Logs the job statistics given in the form of JobStatistics object + * in the repository for further use/reference. + * + * @param statistics Job Statistics object which holds all the statistics related to that job. + * + * @return Returns true if statistics can be logged into repository, false, otherwise. + */ + public abstract boolean logStatistics(JobStatistics statistics); + + /** * Gets the statistics related to that given job as a JobStatistics object array. * Index: DefaultRepository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/DefaultRepository.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DefaultRepository.java 14 Mar 2006 23:00:57 -0000 1.3 --- DefaultRepository.java 15 Mar 2006 04:36:32 -0000 1.4 *************** *** 1,7 **** --- 1,12 ---- package org.jmonks.batchserver.framework; + import com.db4o.Db4o; + import com.db4o.ObjectContainer; + import com.db4o.ObjectSet; + 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; *************** *** 10,26 **** * <p> * This implementation of repository uses the DB4O database as the repository. ! * It expects the two properties repository-location and repository-filename present in the repository configuration ! * in framework-cofig.xml file. * <br><br> * <pre> * <repository-config repository-class-name="org.jmonks.batchserver.framework.DefaultRepository"> * <property key="repository-location">/batchserver/repository</property> - * <property key="repository-filename">batchserver_repository.db</property> * </repository-config> * </pre> * <br><br> ! * Here repository-location defines where the DB4O database needs to be created and ! * repository-filename defines the name of the file to be used as the repository. ! * By default framework will be configured with the values shown in the above XML configuration snippet. * </p> * @author Suresh Pragada --- 15,31 ---- * <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.DefaultRepository"> * <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 *************** *** 30,72 **** public class DefaultRepository extends Repository { private Map repositoryConfigProperties=null; - - private static Logger logger=Logger.getLogger(DefaultRepository.class); - /** * */ public DefaultRepository(Map configProps) { this.repositoryConfigProperties=new HashMap(configProps); } /** ! * @see org.jmonks.batchserver.framework.Repository#logStatistics(org.jmonks.batchserver.framework.JobStatistics) */ ! public boolean logStatistics(org.jmonks.batchserver.framework.JobStatistics statistics) { ! return true; ! } /** ! * @see org.jmonks.batchserver.framework.Repository#sendDataToNextJob(String,String,String,String,Object) */ ! public boolean sendDatatoNextJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp, Object data) { ! return true; ! } ! /** ! * @see org.jmonks.batchserver.framework.Repository#getDataFromPreviousJob(String,String,String,String) ! */ ! public Object getDataFromPreviousJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp) { ! return null; ! } ! /** * @see org.jmonks.batchserver.framework.Repository#registerJobMgmtMntrInfo(String,Object) --- 35,167 ---- public class DefaultRepository extends Repository { + private static Logger logger=Logger.getLogger(DefaultRepository.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 DefaultRepository 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 DefaultRepository(Map configProps) { + logger.trace("Entering constructor"); this.repositoryConfigProperties=new HashMap(configProps); + String repositoryLocation=(String)this.repositoryConfigProperties.get(DefaultRepository.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+DefaultRepository.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(String dataIdentifer, String sourceJobName, String targetJobName, Object data) { ! boolean dataSaved=false; ! if(this.container==null) ! dataSaved=false; ! else ! { ! /** ! * Delete the entries exist with the identifier, source and target job names. ! */ ! JobDataTransfer dataTransferredQuery=new JobDataTransfer(dataIdentifer,sourceJobName,targetJobName,null); ! ObjectSet dataTransferredSet=container.get(dataTransferredQuery); ! while(dataTransferredSet.hasNext()) ! { ! JobDataTransfer dataTransferred=(JobDataTransfer)dataTransferredSet.next(); ! container.delete(dataTransferred); ! } ! container.commit(); ! ! /** ! * Add the new entry. ! */ ! JobDataTransfer dataTransfer=new JobDataTransfer(dataIdentifer, 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(String datIdentifier, String sourceJobName, String targetJobName) { ! if(container==null) ! return null; ! else ! { ! JobDataTransfer dataTransfer=new JobDataTransfer(datIdentifier, sourceJobName, targetJobName, null); ! ObjectSet dataTransferSet=container.get(dataTransfer); ! if(dataTransferSet.hasNext()) ! { ! return ((JobDataTransfer)dataTransferSet.next()).getData(); ! } ! else ! return null; ! } } ! public boolean clearDataTransferredToNextJob(String jobName) { ! boolean dataCleared=false; ! if(container==null) ! dataCleared=false; ! else ! { ! JobDataTransfer dataTransfer=new JobDataTransfer(null, jobName, null, null); ! container.delete(dataTransfer); ! dataCleared=true; ! } ! return dataCleared; } ! /** * @see org.jmonks.batchserver.framework.Repository#registerJobMgmtMntrInfo(String,Object) *************** *** 75,79 **** { return true; - } --- 170,173 ---- *************** *** 97,106 **** /** * @see org.jmonks.batchserver.framework.Repository#getStatistics(String) */ public JobStatistics[] getStatistics(String jobName) { ! return null; ! } --- 191,235 ---- /** + * + * @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(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 ! { ! JobStatistics statisticsQuery=new JobStatistics(jobName); ! ObjectSet statisticsSet=container.get(statisticsQuery); ! statistics=new JobStatistics[statisticsSet.size()]; ! for(int i=0;statisticsSet.hasNext();i++) ! statistics[i]=(JobStatistics)statisticsSet.next(); ! } ! return statistics; } *************** *** 111,115 **** { return true; - } --- 240,243 ---- *************** *** 120,124 **** { return null; - } --- 248,251 ---- *************** *** 129,168 **** { return true; - } ! /** ! * <p> ! * This is the inner class in the DefaultRepository class to hold the data being transferred between the jobs. This will not have any functionality except holding the data. ! * </p> ! * @author : Suresh Pragada ! * @version 1.0 ! */ ! public class JobDataTransfer ! { ! ! ! private String sourceJobName; ! ! ! private String sourceComponentName; ! ! ! private Object data; ! ! private int targetJobName; ! ! private int targetComponentName; ! public JobDataTransfer() ! { } - - - } - - - - } --- 256,353 ---- { return true; } ! ! /** ! * <p> ! * JobDataTransfer 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 ! */ ! private class JobDataTransfer { + /** + * 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. + */ + private JobDataTransfer(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 JobDataTransfer class in the format + * <br> {JobDataTransfer [dataIdentifier = value] [sourceJN = value] + * [targetJN = value] [data = value]} + * </p> + * + * @return Returns the string representation of JobDataTransfer. + */ + public String toString() + { + StringBuffer stringValue=new StringBuffer("{JobDataTransfer "); + 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(); + } } } |