[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework JobController.java, NONE, 1.1
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-20 00:16:41
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8904 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(); } |