Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/controller JobController.java,1.4
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-28 04:54:07
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/controller In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1098 Modified Files: JobController.java Log Message: no message Index: JobController.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/controller/JobController.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JobController.java 25 Mar 2006 19:31:20 -0000 1.4 --- JobController.java 28 Mar 2006 04:53:58 -0000 1.5 *************** *** 1,14 **** package org.jmonks.batchserver.framework.controller; import org.jmonks.batchserver.framework.config.*; import org.jmonks.batchserver.framework.*; import org.jmonks.batchserver.framework.management.JobMonitorMBean; - import org.jmonks.batchserver.framework.mgmtmntr.*; - import org.jmonks.batchserver.framework.common.*; import org.jmonks.batchserver.framework.management.JobManagerMBean; /** * <p> ! * Job Controller is the important component, which actually creates and starts the proper components to process the job. Controller can defines its own logic (architecture) to process the jobs. This creates and manages the complete architecture it defines to process the job. ! * This 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> * --- 1,25 ---- package org.jmonks.batchserver.framework.controller; + import java.io.ObjectInputStream; + import java.io.ObjectOutputStream; + import org.apache.log4j.Level; + import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.*; import org.jmonks.batchserver.framework.*; + import org.jmonks.batchserver.framework.common.ErrorCode; import org.jmonks.batchserver.framework.management.JobMonitorMBean; import org.jmonks.batchserver.framework.management.JobManagerMBean; /** * <p> ! * Job Controller is the important component, which actually creates and starts ! * the proper components to process the job. Controller can defines its own ! * logic (architecture) to process the jobs. This creates and manages the complete ! * architecture it defines to process the job. ! * </p> ! * <p> ! * This 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> * *************** *** 18,108 **** */ public abstract class JobController implements JobMonitorMBean, JobManagerMBean ! { ! ! private Main mMain; ! protected JobController() ! { ! } ! /** * <p> ! * This factory method loads the required implementation of the controller based on the controllerConfig received. First it tries to look for the existence of controller with this jobName in repository (If job is stopped in middle through MgmtMntrManager using restart=true flag, this controller will be stopped and persisted in the repository). By default, if job is stopped in the middle it will be restarted. To override this behaviour special property needs to be sent as "job-controller-restart=false" in the additional configuration. If it is false, it calls the releaseController method on repository to clear its current state and create a new controller using the configuration defined in controllerConfig. ! * * @param jobName Name of the job to be started. * @param controllerConfig configuration object represents controller configuration. * * @return Returns the correct implementation of the controller. - * </p> */ ! public static org.jmonks.batchserver.framework.controller.JobController getJobController(String jobName, org.jmonks.batchserver.framework.config.JobControllerConfig config) { ! return null; ! } /** ! * Returns the controller configuration object. ! * ! * @return Returns the controller configuration object. */ ! public JobControllerConfig getControllerConfig() { ! return null; } ! ! /** ! * This method will be called by Main to process the job. This returns the exit status of the job, which will be communicate to everyone. ! * ! * @return Returns the exit status of the job. ! */ ! public abstract org.jmonks.batchserver.framework.common.StatusCode process(); ! /** ! * Returns the job name. ! * ! * @return Returns the job name. */ ! public String getJobname() ! { ! return null; ! } - public abstract int getExpectedRecordsCount(); - /** ! * @see org.jmonks.batchserver.framework.JobMonitorMBean#getProcessedRecords() ! */ ! public abstract int getProcessedRecordsCount(); ! ! /** ! * @see org.jmonks.batchserver.framework.JobMonitorMBean#getThreadCount() ! */ ! public abstract String[] getThreadIDList(); ! ! /** ! * @see org.jmonks.batchserver.framework.JobMonitorMBean#getThreadState(int) ! */ ! public abstract org.jmonks.batchserver.framework.management.ThreadState getThreadState(String threadID); ! ! /** ! * @see org.jmonks.batchserver.framework.JobManagerMBean#getJobStatus() ! */ ! public abstract org.jmonks.batchserver.framework.management.JobStatus getJobStatus(); ! ! /** ! * @see org.jmonks.batchserver.framework.JobManagerMBean#stop(boolean) ! */ ! public abstract boolean stop(boolean restart); /** ! * @see org.jmonks.batchserver.framework.JobManagerMBean#suspend ! */ ! public abstract boolean suspend(); ! /** ! * @see org.jmonks.batchserver.framework.JobManagerMBean#resume */ ! public abstract boolean resume(); /** --- 29,162 ---- */ public abstract class JobController implements JobMonitorMBean, JobManagerMBean ! { ! protected static final String JOB_CONTROLLER_RESTART_PROPERTY_NAME = "job-controller-restart"; ! /** ! * Name of the job this controller belongs to. ! */ ! private String jobName=null; ! /** ! * Job controller configuration this controller is going to use. ! */ ! private JobControllerConfig jobControllerConfig=null; ! /** ! * Singletone instance of job controller. ! */ ! private static JobController jobController=null; ! ! private static Logger logger=Logger.getLogger(JobController.class); /** * <p> ! * This factory method loads the required implementation of the controller ! * based on the controller configuration received. First it tries to look for the ! * existence of controller with this jobName in repository (If job is stopped ! * in middle through job management agent using restart=true flag, ! * this controller will be stopped and persisted in the repository). ! * By default, if job is stopped in the middle it will be restarted. ! * To override this behaviour special property needs to be sent as ! * "job-controller-restart=false" in the additional configuration. ! * If it is false, it calls the releaseController method on repository to ! * clear its current state and create a new controller using the configuration ! * defined in controllerConfig. ! * </p> * @param jobName Name of the job to be started. * @param controllerConfig configuration object represents controller configuration. * * @return Returns the correct implementation of the controller. */ ! public static synchronized JobController getJobController(String jobName, JobControllerConfig jobControllerConfig) { ! if(jobController==null) ! { ! if(jobName==null) ! throw new IllegalArgumentException("job name cannot be null to create the job controller."); ! if(jobControllerConfig==null) ! throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "job controller configuration is not defined in framework configuration"); + /** + * TODO :: Check for the restart flag all over and take necessary actions before actually instantiating the + * job controller. + */ + String jobControllerClassName=jobControllerConfig.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); + + try + { + jobController=(JobController)Class.forName(jobControllerClassName).newInstance(); + jobController.jobName=jobName; + jobController.jobControllerConfig=jobControllerConfig; + 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; + } + + /** ! * Returns the job name. */ ! public String getJobName() { ! return this.jobName; } ! /** ! * Returns the job controller configuration defined in job configuration. */ ! public JobControllerConfig getJobControllerConfig() { ! return this.jobControllerConfig; } /** ! * 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 Main to process the job. This returns the exit status of the job, which will be communicate to everyone. ! * ! * @return Returns the exit status of the job. */ ! public abstract ErrorCode process(); /** *************** *** 111,115 **** * @param inputStream Stream from which the controller needs to be recovered. */ ! public abstract void readObject(java.io.ObjectInputStream inputStream); /** --- 165,169 ---- * @param inputStream Stream from which the controller needs to be recovered. */ ! public abstract void readObject(ObjectInputStream inputStream); /** *************** *** 118,121 **** * @param outputStream Persist/Serialize the state of the controller. */ ! public abstract void writeObject(java.io.ObjectOutputStream outputStream); } --- 172,184 ---- * @param outputStream Persist/Serialize the state of the controller. */ ! public abstract void writeObject(ObjectOutputStream outputStream); ! ! /** ! * Tells whether this controller can be restartable. Specialized controllers ! * collect this information from the specialized jobs. ! * ! * @return Returns true, if controller can be restarted, false, otherwise. ! */ ! public abstract boolean isRestartable(); ! } |