Thread: [Batchserver-cvs] JobController.java, NONE, 1.1 Repository.java, 1.1, 1.2
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-19 22:51:32
|
Update of /cvsroot/batchserver In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3112 Modified Files: Repository.java Added Files: JobController.java Log Message: no message --- NEW FILE: JobController.java --- package org.jmonks.batch.framework; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.management.JobMonitorMBean; import org.jmonks.batch.framework.management.JobManagerMBean; /** * <p> * Job Controller is the important component, which actually creates and drives * the execution of the job. This defines the logic and the flow, how the user components * needs to be written and how they would be driven while executing the job. * Framework provides two controllers called as BasicJobController and PoolJobController * which defines their own way of executing the job. * </p> * * <p> * JobController provides a factory method which returns the appropriate controller component * based on the provided controller config object. This implements the management and * monitoring interfaces to make sure all the controller implementations are manageable * and monitorable. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobController implements JobMonitorMBean, JobManagerMBean { /** * JobContext associated to this controller. */ protected JobContext jobContext=null; private static Logger logger=Logger.getLogger(JobController.class); /** * <p> * This factory method creates required implementation of the controller * based on the controller configuration available in job context and sets * the job context to the controller. * </p> * * @param jobContext Job context going to be associated with the controller. * @param controllerCreator Main instance which is allowed to create the controller. This is to restrict only framework can instantiate the Controller. * * @return Returns the defined implementation of the controller. * * @throws SecurityException If an attempt is made to create the controller by other than the Main class(framework). * @throws ConfigurationException If required properties are missing in the controller configuration or the values are invalid. */ public static JobController createJobController(JobContext jobContext, Main controllerCreator) { logger.trace("Entering getJobController = " + jobContext.getJobName()); if(!(controllerCreator instanceof Main)) throw new SecurityException("Not authorized to create the controller."); String jobControllerClassName=jobContext.getJobConfig().getJobControllerConfig().getJobControllerClasName(); if(jobControllerClassName==null || "".equals(jobControllerClassName)) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "job controller class name is not defined in job controller configuration"); logger.debug("job controller class name = " + jobControllerClassName); JobController jobController=null; try { jobController=(JobController)Class.forName(jobControllerClassName).newInstance(); jobController.jobContext=jobContext; logger.debug("created the job controller implemenation class"); } catch(ClassNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(IllegalAccessException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } return jobController; } /** * Gets the log level of the given logger name. * * @param loggerName Name of the logger wants to find the log level. * * @return Returns the log level, null, if the given logger could not be found. */ public Level getLogLevel(String loggerName) { return LoggingManager.getLogLevel(loggerName); } /** * Changes the log level for the requested logger name with the given log level. * * @param loggerName Logger name needs to be modified. * @param newLogLevel new logging level. * * @return Returns true, if log level could be changed, false, otherwise. */ public boolean changeLogLevel(String loggerName, Level level) { return LoggingManager.changeLogLevel(loggerName, level); } /** * This method will be called by the Main to process the job. This returns the * ErrorCode explaining whether the process has been failed or succeeded. * * @return Returns the ErrorCode as exit status of the job. */ public abstract ErrorCode process(); /** * Returns the statistics of this job. Statistics will be queried only * after the completion of controller processing. Querying before the completion * of processing always returns null. * * @return Returns the statistics of this job. */ public abstract JobStatistics getJobStatistics(); } Index: Repository.java =================================================================== RCS file: /cvsroot/batchserver/Repository.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Repository.java 3 Mar 2006 04:19:56 -0000 1.1 --- Repository.java 19 Sep 2006 22:51:29 -0000 1.2 *************** *** 1,128 **** ! package org.jmonks.batchserver.framework; - import org.jmonks.batchserver.framework.config.*; - import org.jmonks.batchserver.framework.controller.*; /** * <p> ! * This interface provides utility methods to access and use the repository. ! * 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 any objects, ! * transfer some information between the jobs and transfer some management and monitor ! * information between framework and server. * </p> ! * @author : Suresh Pragada * @version 1.0 */ public abstract class Repository { ! ! private Repository() ! { ! } ! public static void getRepository(org.jmonks.batchserver.framework.config.RepositoryConfig config) ! { ! } /** ! * This method logs the job statistics given in the form JobStatistics object ! * in the repository for further use. ! * ! * @param statistics Job Statistics object which holds all the statistics related to that job. ! * ! * @return Returns true if statistics can be logged, false, otherwise. */ ! public abstract boolean logStatistics(org.jmonks.batchserver.framework.JobStatistics statistics); ! /** ! * Given data will be sent to the specified job behalf of this job. ! * ! * @param srcJN Name of the source job. ! * @param srcCmp Name of the source componenet. ! * @param tgtJN Name of the target job. ! * @param tgtCmp 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 srcJN, String srcCmp, String tgtJN, String tgtCmp, Object data); ! /** ! * Gets the data that has been sent to this job. ! * ! * @param srcJN Name of the source job. ! * @param srcCmp Name of the source componenet. ! * @param tgtJN Name of the target job. ! * @param tgtCmp Name of the target component. ! * ! * @return Returns the data, null, it it couldnt find any data. */ ! public abstract Object getDataFromPreviousJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp); ! /** ! * Registers the job management and monitoring info with the given job name. ! * ! * @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); /** ! * 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 org.jmonks.batchserver.framework.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(org.jmonks.batchserver.framework.controller.JobController controller, String jobName); /** ! * 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 org.jmonks.batchserver.framework.controller.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); } --- 1,206 ---- ! package org.jmonks.batch.framework; ! import java.util.Map; ! import org.apache.log4j.Logger; ! import org.jmonks.batch.framework.config.ConfigurationException; ! import org.jmonks.batch.framework.config.FrameworkConfig.RepositoryConfig; ! ! /** * <p> ! * Repository class provides utility methods to access and use the repository maintained ! * by the framework. The repository could be any data store from files to databases, useful ! * to save and retrieve the data. So, there could be different implementations available of ! * this Repository class. Framework configuration defines which implementation should ! * be used for the framework. * </p> ! * <p> ! * This povides utility methods to log the job statistics and transfer data between the jobs ! * and register & unregister management and monitoring information. Framework creates the ! * repository at the startup and provides this reference through the JobContext to all the jobs. ! * When the repository get created, it will be associated with the job beign run and all the ! * operations will be performed with respect to that job only. The job being run will be taken ! * as source job in all the operations. ! * </p> ! * <p> ! * Default framework configuration uses Db4o database as repository for its simplicity. ! * There is a JdbcRepository implementation by using which we can use any database that ! * can be used JDBC can be configured to use as repository. If anyone wish to use tools ! * provided to manage and monitor the applications, consider of using the JdbcRepository ! * implementation. ! * </p> ! * ! * @author Suresh Pragada * @version 1.0 + * @since 1.0 */ public abstract class Repository { ! private static Logger logger=Logger.getLogger(Repository.class); /** ! * Name of the job associated with the repository. */ ! protected String jobName=null; ! /** ! * <p> ! * Method to initialize the repository implementation by using the properties ! * defined in the framework configuration. This method will be called immediately ! * after instantiating the implementation class. ! * </p> ! * ! * @param configProps Configuration properties defined in <repository-config> element ! * in framework configuration file. ! * ! * @throws ConfigurationException If required configuration properties are missing or the values ! * are invalid. */ ! protected abstract void init(Map configProps); ! /** ! * <p> ! * Factory method creates the repository instance based on the given repository configuration and associate ! * this repository instance with the given job. So, all the repository operations performed ! * using this repository instance will be associated with that job and taken that job as source ! * job in all operations. This method will be called by the framework to create the repository and ! * places the reference in JobContext object. ! * </p> ! * ! * @param jobName Name of the job this repository will be associated with. ! * @param repositoryConfig Repository configuration defined in framework configuration. ! * @param repositoryCreator Creator of the repository. This is to restrict only framework can instantiate the repository. ! * ! * @return Returns the repository instances associated with the given job. ! * ! * @throws SecurityException If an attempt is made to create the repository by other than the Main class(framework). ! * @throws IllegalArgumentException If jobName is null to create the repository instance. ! * @throws ConfigurationException If required properties are missing in the repository configuration or the values are invalid. */ ! public static Repository createRepository(String jobName, RepositoryConfig repositoryConfig, Main repositoryCreator) ! { ! logger.trace("Entering createRepository"); ! ! if(!(repositoryCreator instanceof Main)) ! throw new SecurityException("Not authorized to create the repository."); ! ! if(repositoryConfig==null) ! throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "Repository configuration is not defined in framework configuration"); ! ! if(jobName==null || "".equals(jobName)) ! throw new IllegalArgumentException("Job Name cannot be null or empty to create repository instance."); ! 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 + { + repository=(Repository)Class.forName(repositoryClassName).newInstance(); + repository.jobName=jobName; + repository.init(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(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()); + } + logger.trace("Exiting createRepository " + (repository!=null)); + return repository; + } + /** ! * <p> ! * Data will be send to the specified next job and will be identified with the ! * given identifier. By using different identifiers, multiple data objects ! * can be send to the same next job. Next job should use the data identifier ! * and this (source) job name to read the data. If there is any data with this ! * identifier from this job to the next job, it will be overriden. ! * </p> * ! * @param dataIdentifier Identifier to be used to exchange the data between two jobs. ! * @param nextJobName Name of the next job this data to be send. ! * @param data Data that needs to be send as the object. * ! * @return Returns true, if it could save the data to be send to the next job. ! * ! * @throws IllegalArgumentException If any one of the incoming values are null. */ ! public abstract boolean sendDataToNextJob(String dataIdentifier, String nextJobName, ! final Object data); /** ! * Gets the data that has been sent by the previous job with the given data identifier. * ! * @param dataIdentifier Identifier tied to the data that has been sent. ! * @param previousJobName Name of the previous job sent the data to this job. * ! * @return Returns the data, null, if it couldnt find any data from the previous job with that identifier. ! * ! * @throws IllegalArgumentException If any one of the input values are null. */ ! public abstract Object getDataFromPreviousJob(String dataIdentifier, String previousJobName); /** ! * <p> ! * This method will clear all the data that has been sent by this job to all the next jobs. ! * </p> ! * ! * @return Returns true if it could clear all the data, false, otherwise. * */ ! public abstract boolean clearDataTransferredFromThisJob(); ! /** ! * <p> ! * Registers the given job management and monitoring information to this job. ! * If there is any information already associated with this job, it ! * will be overriden. ! * </p> ! * ! * @param registrationInfo Information to be associated with the job. * ! * @return Return true, if it could assosciate this information, false, otherwise. ! * ! * @throws IllegalArgumentException If input argument registration information ! * value is null. */ ! public abstract boolean registerJobMgmtMntrInfo(final Object registrationInfo); /** ! * Unregisters the job management and monitoring information assosciated with this job. * ! * @return Return true, it it could unregister the information, false, otherwise. */ ! public abstract boolean unregisterJobMgmtMntrInfo(); ! /** ! * <p> ! * Logs the job statistics given in the form of JobStatistics object ! * in the repository for further use/references. ! * </p> ! * @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. ! * ! * @throws IllegalArgumentException If input argument job statistics is null. */ ! public abstract boolean logStatistics(final JobStatistics statistics); } |