Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/repository Repository.java,NONE,1
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-16 14:13:33
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/repository In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17379 Added Files: Repository.java Log Message: no message --- NEW FILE: Repository.java --- package org.jmonks.batchserver.framework.repository; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.*; import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.*; /** * <p> * Repository provides utility methods to access and use the repository maintained * by the framework. There could be differnt implementations of the repository. * Framework configuration defines which implementation should be used for this framework. * This povides utility methods to logs the job statistics and persist job controllers, * transfer some information between the jobs and transfer some management and monitor * information between framework and server. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class Repository { private static Logger logger=Logger.getLogger(Repository.class); /** * Protected constructor to make sure Repository cannot be instantiated * other than extending this class. */ protected Repository() { } /** * Factory method returns the specific implementation of repository based on the * repository configuration. * * @param repositoryConfig Repository configuration object. * * @throws ConfigurationException If repositoryClassName is missing or invalid * or it cannot be instantiated because of the lack of mandatory properties required * by the specific repository implementations. * @throws IllegalArgumentException If input repositoryConfig is null. */ public static Repository getRepository(FrameworkConfig.RepositoryConfig repositoryConfig) { logger.trace("Entering getRepository"); if(repositoryConfig==null) throw new IllegalArgumentException("repository configuration object cannot be null."); String repositoryClassName=repositoryConfig.getRepositoryClassName(); if(repositoryClassName==null || "".equals(repositoryClassName)) throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "repository class name is not defined in repository configuration"); logger.debug("repository class name = " + repositoryClassName); Repository repository=null; try { Class repositoryClass=Class.forName(repositoryClassName); Constructor repositoryConstructor=repositoryClass.getConstructor(new Class[]{Map.class}); repository=(Repository)repositoryConstructor.newInstance(new Object[]{repositoryConfig.getRepositoryConfigProperties()}); logger.debug("created the repository implemenation class"); } catch(ClassNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(NoSuchMethodException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(IllegalAccessException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } catch(InvocationTargetException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); } logger.trace("Exiting getRepository"); return repository; } /** * 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 * will be overriden. This could happen, if job forgot to unregister the * management and monitoring information. * * @param jobName Name of the job. * @param registrationInfo Information to be associated with this job name. * * @return Return true, if it could assosciate this information, false, otherwise. */ public abstract boolean registerJobMgmtMntrInfo(String jobName, Object registrationInfo); /** * Retrieves the management and monitoring information assosciated with this job. * * @param jobName Name of the job. * * @return Returns the registered information, null, if it doesnt find any information. */ public abstract Object lookupJobMgmtMntrInfo(String jobName); /** * Unregisters the job management and monitoring info assosciated with the given job name. * * @param jobName Name of the job. * * @return Return true, it it could unregister the information, false, otherwise. */ public abstract boolean unregisterJobMgmtMntrInfo(String jobName); /** * 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. * * @param jobName Name of the job for which statistics are required. * @return Returns the array of JobStatistics object, null, if it couldnt find any job with that name. */ public abstract JobStatistics[] getStatistics(String jobName); /** * Persist the controller in repository. This will be useful, when job wants to be restarted. * When controller receives stop signal from servier with restart flag, it persist itself into * the repository. * * @param jobName Name of the job * @param controller Controller object to be persisted. * * @return Returns true, if it could persist the controller, false, otherwise. */ public abstract boolean saveController(String jobName, JobController controller); /** * Loads the controller assosicated with this job name in the repsoitory. When controller starts * execution, always, it looks into the reposiotry for restart. This can be overriden by passing addition * configuration property. * * @param jobName Name of the job. * @return Returns the controller object, null, if it couldnt find any. */ public abstract JobController loadController(String jobName); /** * Releases the persistedcontroller object from repository. * * @param jobName Name of the job. * @return Returns true, if it could release the controller from repository, null, otherwise. */ public abstract boolean releaseController(String jobName); } |