batchserver-cvs Mailing List for Enterprise Batch Server (Page 7)
Brought to you by:
suresh_pragada
You can subscribe to this list here.
2006 |
Jan
|
Feb
(10) |
Mar
(159) |
Apr
(5) |
May
(52) |
Jun
(70) |
Jul
|
Aug
(28) |
Sep
(256) |
Oct
(38) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Suresh <sur...@us...> - 2006-09-15 20:06:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19890 Added Files: JobController.java Log Message: no message --- NEW FILE: JobController.java --- package org.jmonks.batch.framework.controller; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.jmonks.batch.framework.JobStatistics; import org.jmonks.batch.framework.LoggingManager; import org.jmonks.batch.framework.ErrorCode; import org.jmonks.batch.framework.JobContext; 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; /** * 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 available in job context and sets * this context to the controller. * </p> * * @param jobContext Job context going to be associated with the controller. * * @return Returns the defined implementation of the controller. */ public static JobController getJobController(JobContext jobContext) { logger.trace("Entering getJobController = " + jobContext.getJobName()); if(jobController==null) { 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); 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()); } } logger.trace("Exiting getJobController = " + jobContext.getJobName()); 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(); } |
From: Suresh <sur...@us...> - 2006-09-15 20:06:23
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19878 Added Files: XMLBasicJobControllerConfig.java XMLJobConfig.java XMLJobConfigFactory.java XMLJobControllerConfig.java XMLJobLoggingConfig.java XMLPoolJobControllerConfig.java Log Message: no message --- NEW FILE: XMLJobConfig.java --- /* * XMLJobConfig.java * * Created on March 2, 2006, 11:51 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * <p> * XMLJobConfig provides the implementation of JobConfig by reading the * job configuration from XML DOM element <job-config> configured in the * job configuration file. This reads and represents the following piece of XML * block from job configuration file. * <br><br> * <pre> * <job-config job-name="process_file_xyz"> * <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.basic.BasicJobController"> * <basic-job-processor basic-job-processor-class-name="com.mycompany.batch.processfilexyz.XyzProcessor" thread-count="1"> * <property key="basic-job-processor-config1">processor-value1</property> * </basic-job-processor> * <property key="basic-job-controller-config1">config-value1</property> * </job-controller> * <job-logging-config> * <logger-config logger-name="com.mycompany.batch" logger-level="ERROR"/> * </job-logging-config> * </job-config> * </pre> * </p> * * @author Suresh Pragada * @since 1.0 * @version 1.0 */ public class XMLJobConfig extends JobConfig { /** * Element name that identifies the job configuration which is <code>job-config</code>. */ public static final String JOB_CONFIG_ELEMENT_NAME = "job-config"; /** * Attribute name that identifies the job name which is <code>job-name</code>. */ public static final String JOB_NAME_ATTRIBUTE_NAME = "job-name"; /** * Attribute name that identifies the job status which is <code>job-status</code>. */ public static final String JOB_STATUS_ATTRIBUTE_NAME = "job-status"; private static Logger logger=Logger.getLogger(XMLJobConfig.class); /** * Loads the job name and controller configuration into the job configuration object. * * @param jobConfigElement XML DOM Element that represents the <job-confg> * element in batch job configuration file. * * @throws ConfigurationException If more than one job controllers are found in job configuration. */ XMLJobConfig(Element jobConfigElement) { logger.trace("Entering Constructor"); this.jobName=jobConfigElement.getAttribute(XMLJobConfig.JOB_NAME_ATTRIBUTE_NAME); logger.info("Job name = " + this.jobName); String jobStatusInStr=jobConfigElement.getAttribute(XMLJobConfig.JOB_STATUS_ATTRIBUTE_NAME); if(jobStatusInStr.equalsIgnoreCase("active")) { this.jobStatus=true; } else { this.jobStatus=false; } logger.info("Job status = " + this.jobStatus); NodeList jobLoggingConfigNodeList=jobConfigElement.getElementsByTagName(XMLJobLoggingConfig.JOB_LOGGING_CONFIG_ELEMENT_NAME); if(jobLoggingConfigNodeList.getLength()==1) { Element jobLoggingConfigElement=(Element)jobLoggingConfigNodeList.item(0); logger.trace("Creating the XML Job logging configuration object"); this.jobLoggingConfig=new XMLJobLoggingConfig(jobLoggingConfigElement); logger.info("Job logging configuration = " + this.jobLoggingConfig); } else throw new ConfigurationException(ConfigurationException.JOB_CONFIG, "Found " + jobLoggingConfigNodeList.getLength() + XMLJobLoggingConfig.JOB_LOGGING_CONFIG_ELEMENT_NAME + " element(s) in configuration of job " + jobName + "."); NodeList controllerConfigNodeList=jobConfigElement.getElementsByTagName(XMLJobControllerConfig.JOB_CONTROLLER_ELEMENT_NAME); if(controllerConfigNodeList.getLength()==1) { Element controllerConfigElement=(Element)controllerConfigNodeList.item(0); logger.trace("Requesting controller config factory to get the controller configuration object"); this.jobControllerConfig=XMLJobControllerConfig.getJobControllerConfig(controllerConfigElement); logger.info("Job controller configuration = " + this.jobControllerConfig); } else throw new ConfigurationException(ConfigurationException.JOB_CONFIG, "Found " + controllerConfigNodeList.getLength() + XMLJobControllerConfig.JOB_CONTROLLER_ELEMENT_NAME + " element(s) in configuration of job " + jobName + "."); logger.trace("Exiting Constructor"); } } --- NEW FILE: XMLJobLoggingConfig.java --- /* * XMLJobLoggingConfig.java * * Created on March 13, 2006, 7:27 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.JobLoggingConfig; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * Reads the job logging configuration from the XML job configuration file. * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class XMLJobLoggingConfig extends JobLoggingConfig { /** * Element name represents the job logging config which is <code>job-logging-config</code>. */ public static final String JOB_LOGGING_CONFIG_ELEMENT_NAME = "job-logging-config"; /** * Element name represents the job logger config which is <code>job-logger-config</code>. */ private static final String JOB_LOGGER_CONFIG_ELEMENT_NAME = "job-logger-config"; /** * Atrribute name represents the logger name in job logger config which is <code>logger-name</code>. */ private static final String LOGGER_NAME_ATTRIBUTE_NAME = "logger-name"; /** * Atrribute name represents the logger level in job logger config which is <code>logger-level</code>. */ private static final String LOGGER_LEVEL_ATTRIBUTE_NAME = "logger-level"; private static Logger logger=Logger.getLogger(XMLJobLoggingConfig.class); /** * <p> * Loads the job logging config object from the input element represents * job-logging-config element. This element represents the following XML block. * <br><br> * <pre> * <job-logging-config> * <job-logger-config logger-name="com.mycompany.batch.xyz" logger-level="DEBUG"/> * <job-logger-config logger-name="com.mycompany.batch.abc.processor" logger-level="ERROR"/> * </job-logging-config> * </pre> * </p> * * @param jobLoggingConfigElement XML DOM Element represents the job-logging-config element. */ public XMLJobLoggingConfig(Element jobLoggingConfigElement) { logger.trace("Entering constructor"); NodeList jobLoggerConfigNodeList=jobLoggingConfigElement.getElementsByTagName(XMLJobLoggingConfig.JOB_LOGGER_CONFIG_ELEMENT_NAME); for(int i=0;i<jobLoggerConfigNodeList.getLength();i++) { Element jobLoggerConfigElement=(Element)jobLoggerConfigNodeList.item(i); String loggerName=jobLoggerConfigElement.getAttribute(XMLJobLoggingConfig.LOGGER_NAME_ATTRIBUTE_NAME); String loggerLevel=jobLoggerConfigElement.getAttribute(XMLJobLoggingConfig.LOGGER_LEVEL_ATTRIBUTE_NAME); logger.trace("Adding the logger information = " + loggerName + " " + loggerLevel); this.addLogger(loggerName,loggerLevel); } logger.trace("Exiting constructor"); } } --- NEW FILE: XMLPoolJobControllerConfig.java --- /* * XMLPoolJobControllerConfig.java * * Created on March 2, 2006, 1:33 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.PoolJobControllerConfig; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * <p> * XMLPoolJobControllerConfig loads the controller configuration from XML Job controller * configuration. This reads the following XML block and loads the XMLPoolJobControllerConfig. * <br><br> * <pre> * <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.pool.PoolJobController"> * <pool-job-loader pool-job-loader-class-name="com.mycompany.batch.processfileabc.AbcJobLoader"> * <property key="pool-job-loader-key1">loader-value1</property> * </pool-job-loader> * <pool-job-processor pool-job-processor-class-name="com.mycompany.batch.processfileabc.AbcJobProcessor" thread-count="1"> * <property key="pool-job-processor-key1">processor-value1</property> * </pool-job-processor> * <job-pool job-pool-class-name="org.jmonks.batch.framework.controller.pool.DefaultJobPool"> * <property key="job-pool-size">50000</property> * </job-pool> * <property key="pool-job-controller-config1">config-value1</property> * </job-controller> * </pre> * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class XMLPoolJobControllerConfig extends PoolJobControllerConfig { /** * XML Element name defines the pool job loader configuration which is <code>pool-job-loader</code>. */ private static final String POOL_JOB_LOADER_ELEMENT_NAME = "pool-job-loader"; /** * XML Attribute name defines the pool job loader class name which is <code>pool-job-loader-class-name</code>. */ private static final String POOL_JOB_LOADER_CLASS_ATTRIBUTE_NAME = "pool-job-loader-class-name"; /** * XML Element name defines the job pool configuration which is <code>job-pool</code>. */ private static final String POOL_JOB_POOL_ELEMENT_NAME = "job-pool"; /** * XML Attribute name defines the job pool class name which is <code>job-pool-class-name</code>. */ private static final String POOL_JOB_POOL_CLASS_ATTRIBUTE_NAME = "job-pool-class-name"; /** * XML Element name defines the pool job processor configuration which is <code>pool-job-processor</code>. */ private static final String POOL_JOB_PROCESSOR_ELEMENT_NAME = "pool-job-processor"; /** * XML Attribute name defines the pool job processor class name which is <code>pool-job-processor-class-name</code>. */ private static final String POOL_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME = "pool-job-processor-class-name"; /** * XML Attribute name defines the thread count of the job processor which is <code>thread-count</code>. */ private static final String THREAD_COUNT_ATTRIBUTE_NAME = "thread-count"; private static Logger logger=Logger.getLogger(XMLPoolJobControllerConfig.class); /** * Loads the XMLPoolJobControllerConfig from XML DOM Element <job-controller> * * @param controllerConfigElement XML DOM Element represents the <job-controller> element. * * @throws ConfigurationException If controller class name not defined or required controller properties missing. */ public XMLPoolJobControllerConfig(Element controllerConfigElement) { logger.trace("Entering Constructor"); this.jobControllerClassName=controllerConfigElement.getAttribute(XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME); if(this.jobControllerClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); FrameworkUtil.loadPropertiesFromElementToMap(controllerConfigElement, this.jobControllerConfigProps); /** * Load pool job loader configuration. */ logger.trace("Started reading the pool job loader configuration"); NodeList xmlPoolJobLoaderNodeList=controllerConfigElement.getElementsByTagName(XMLPoolJobControllerConfig.POOL_JOB_LOADER_ELEMENT_NAME); if(xmlPoolJobLoaderNodeList.getLength()==1) { Element xmlPoolJobLoaderElement=(Element)xmlPoolJobLoaderNodeList.item(0); this.poolJobLoaderClassName=xmlPoolJobLoaderElement.getAttribute(XMLPoolJobControllerConfig.POOL_JOB_LOADER_CLASS_ATTRIBUTE_NAME); if(this.poolJobLoaderClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLPoolJobControllerConfig.POOL_JOB_LOADER_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); else { FrameworkUtil.loadPropertiesFromElementToMap(xmlPoolJobLoaderElement, this.poolJobLoaderConfigProps); } } else throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Found " + xmlPoolJobLoaderNodeList.getLength() + " element(s) in the pool job controller configuration."); logger.trace("Finished reading the pool job loader configuration"); /** * Load pool job procesor configuration. */ logger.trace("Started reading the pool job processor configuration"); NodeList xmlPoolJobProcessorNodeList=controllerConfigElement.getElementsByTagName(XMLPoolJobControllerConfig.POOL_JOB_PROCESSOR_ELEMENT_NAME); if(xmlPoolJobProcessorNodeList.getLength()==1) { Element xmlPoolJobProcessorElement=(Element)xmlPoolJobProcessorNodeList.item(0); this.poolJobProcessorClassName=xmlPoolJobProcessorElement.getAttribute(XMLPoolJobControllerConfig.POOL_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME); if(this.poolJobProcessorClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLPoolJobControllerConfig.POOL_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); else { this.poolJobProcessorThreadCount=Integer.parseInt(xmlPoolJobProcessorElement.getAttribute(XMLPoolJobControllerConfig.THREAD_COUNT_ATTRIBUTE_NAME)); FrameworkUtil.loadPropertiesFromElementToMap(xmlPoolJobProcessorElement, this.poolJobProcessorConfigProps); } } else throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Found " + xmlPoolJobProcessorNodeList.getLength() + " element(s) in the pool job controller configuration."); logger.trace("Finished reading the pool job processor configuration"); /** * Load job pool configuration. */ logger.trace("Started reading the job pool configuration"); NodeList xmlJobPoolNodeList=controllerConfigElement.getElementsByTagName(XMLPoolJobControllerConfig.POOL_JOB_POOL_ELEMENT_NAME); if(xmlJobPoolNodeList.getLength()==1) { Element xmlJobPoolElement=(Element)xmlJobPoolNodeList.item(0); this.poolClassName=xmlJobPoolElement.getAttribute(XMLPoolJobControllerConfig.POOL_JOB_POOL_CLASS_ATTRIBUTE_NAME); if(this.poolClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLPoolJobControllerConfig.POOL_JOB_POOL_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); else { FrameworkUtil.loadPropertiesFromElementToMap(xmlJobPoolElement, this.poolConfigProps); } } else throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Found " + xmlJobPoolNodeList.getLength() + " element(s) in the pool job controller configuration."); logger.trace("Finished reading the job pool configuration"); logger.trace("Exiting Constructor"); } } --- NEW FILE: XMLJobControllerConfig.java --- /* * XMLJobControllerConfig.java * * Created on March 2, 2006, 1:20 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobControllerConfig; import org.w3c.dom.Element; /** * XMLJobControllerConfig responsible to build the controller specific * JobControllerConfig objects from the given XML. Look at {@link #getJobControllerConfig(Element)} * to understand on how this is going to get the correct job controller config instance. * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class XMLJobControllerConfig extends JobControllerConfig { /** * Element name that identifies the job controller configuration which is <code>job-controller</code>. */ public static final String JOB_CONTROLLER_ELEMENT_NAME = "job-controller"; /** * Attribute name that identifies the job controller class name which is <code>job-controller-class-name</code>. */ public static final String JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME = "job-controller-class-name"; /** * Element name that identifies the job controller configuration class name which is <code>xml-factory-config-class-name</code>. */ public static final String JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME = "xml-factory-config-class-name"; private static Logger logger=Logger.getLogger(XMLJobControllerConfig.class); /** * <p> * Factory method creates and returns the controller specific controller config object * from the following XML block from the job configuration file. This looks for the * controller class name and tries to find specific controller config object for this controller * and defined for the XML factory in framework configuration file. * <br><br> * <pre> * <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.basic.BasicJobController"> * <property key="basic-job-controller-config1">config-value1</property> * </job-controller> * </pre> * </p> * * @return Returns the controller specific controller config object. * * @throws ConfigurationException If controller config class name is not defined or controller specific config object cannot be found * in framework controller configuration. */ public static JobControllerConfig getJobControllerConfig(Element controllerConfigElement) { logger.trace("Entering getJobControllerConfig"); JobControllerConfig controllerConfig=null; String controllerClassName=controllerConfigElement.getAttribute(XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME); logger.debug("Controller class name = " + controllerClassName); if(controllerClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); else { try { String controllerConfigClassName=FrameworkConfig.getInstance().getJobControllerConfig().getConfigClassName(controllerClassName, XMLJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME); logger.debug("Controller configuration class name = " + controllerConfigClassName); if(controllerConfigClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Could not found the controller config class for the controller type " + controllerClassName + " for the factory " + XMLJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME + "."); else { Class configClass=Class.forName(controllerConfigClassName); Constructor constructor=configClass.getConstructor(new Class[]{Element.class}); controllerConfig=(JobControllerConfig)constructor.newInstance(new Object[]{controllerConfigElement}); logger.debug("Got the controller configuration : " + controllerConfig); } } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(NoSuchMethodException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(ClassNotFoundException 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()); } catch(InvocationTargetException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } } logger.trace("Exiting getJobControllerConfig"); return controllerConfig; } } --- NEW FILE: XMLJobConfigFactory.java --- /* * XMLJobConfigFactory.java * * Created on March 2, 2006, 12:00 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; import org.jmonks.batch.framework.config.JobConfigFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** * <p> * XMLJobConfigFactory reads the job configuration from XML file to create the * configuration objects needed by the job. This factory looks for few properties * in the factory config properties map to identify the source of the XML file. The source of * the XML file can be defined as absolute path on the file system or resource on the * class path. * </p> * <p> * Following are the two properties, this factory looks to find the source. If it find * these two it will give priority to the physical absolute path location. * <table> * <tr><td><b>property key</b></td><td><b>property value</b></td></tr> * <tr><td>job-config-file-absolute-location</td><td>/batchserver/config/batch-config.xml</td></tr> * <tr><td>job-config-file-classpath-location</td><td>batch-config.xml</td></tr> * </table> * These properties can be configured using <property> attribute in the <job-config-factory-config> element * in the framework configuration file. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class XMLJobConfigFactory extends JobConfigFactory { /** * Constant defines the property name of config file absolute location which is <code>job-config-file-absolute-location</code>. */ private static final String PROPERTY_JOB_CONFIG_FILE_ABSOLUTE_LOCATION = "job-config-file-absolute-location"; /** * Constant defines the property name of config file classpath location which is <code>job-config-file-classpath-location</code>. */ private static final String PROPERTY_JOB_CONFIG_FILE_CLASSPATH_LOCATION = "job-config-file-classpath-location"; /** * Property map holds the properites required by this factory. */ private Map configFactoryProps=null; /** * batch-config element in the XML configuration file. */ private Element batchConfigElement=null; private static Logger logger=Logger.getLogger(XMLJobConfigFactory.class); /** *<p> * <i> * Do not use this constructor to instantiate XMLJobConfigFactory directly. Use * the factory method getJobConfigFactory in JobConfigFactory class to get the config factory * instance. This constructor has been provided to make sure this should be * instantiable and accessible to the JobConfigFactory class. * </i> * </p> */ public XMLJobConfigFactory() { } /** * This method initializes the factory by accepting the required properties * from the input map. If it doesnt find any required properties * to initialize the factory, throws ConfigurationException with the appropriate error message. * * @param configFactoryProps Map consists of all the properties defined for this factory. * * @throws ConfigurationException If required properties are missing. */ protected void init(Map configFactoryProps) { logger.trace("Entering init"); this.configFactoryProps=new HashMap(configFactoryProps); String absoluteLocation=(String)this.configFactoryProps.get(XMLJobConfigFactory.PROPERTY_JOB_CONFIG_FILE_ABSOLUTE_LOCATION); String classpathLocation=(String)this.configFactoryProps.get(XMLJobConfigFactory.PROPERTY_JOB_CONFIG_FILE_CLASSPATH_LOCATION); logger.debug("Absolute location : " + absoluteLocation + " classpath location : " + classpathLocation); if(absoluteLocation==null && classpathLocation==null) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "XML Job configuration location is not specified " + "using either absolute or classpath attribute."); else if(absoluteLocation!=null) { /** * Look for the absolute location property and load the stream. * If file is not found or the given entry is not a file throw configuration exception. */ try { File jobConfigFile=new File(absoluteLocation); if(jobConfigFile.exists() && jobConfigFile.isFile()) { InputStream inputStream=new FileInputStream(jobConfigFile); logger.debug("Would be able to read the configuration stream from absolute path " + absoluteLocation); if(!this.createBatchConfigElement(inputStream)) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "Error while parsing and locating root element batch-config in the XML " + "job configuration file " + absoluteLocation + "."); } else throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "XML job configuration file " + absoluteLocation + " is not exist or it could not be a file."); } catch(FileNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "XML job configuration file " + absoluteLocation + " cannot be found"); } } else if(classpathLocation!=null) { /** * Look for the classpath location property and load the file using classloader. * If we dont find this file on classpath, throw configuration exception. */ InputStream inputStream=XMLJobConfigFactory.class.getClassLoader().getResourceAsStream(classpathLocation); if(inputStream==null) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "XML job configuration file " + classpathLocation + " cannot be located on the classpath."); else { logger.debug("Would be able to read the configuration from class path location : " + classpathLocation); if(!this.createBatchConfigElement(inputStream)) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "Error while parsing and locating the batch-config element in the " + "XML Job configuration file " + classpathLocation + "."); } } logger.trace("Exiting init"); } /** * Returns the requested job configuration as JobConfig object. The requested job * name should be passed as a parameter. If it does not find the configuration of * the requested jobName in the job configuration file, it returns null. * * @param jobName Name of the job. * * @return Returns the job config object if found, null, otherwise. * * @throws IllegalArgumentException If jobName passed as parameter is null. * @throws IllegalStateException If factory is not initialized properly. */ public JobConfig getJobConfig(String jobName) { logger.trace("Entering getJobConfig " + jobName); JobConfig jobConfig=null; /** * Look for all the job-config elements and pass the element whose job-name * attribute matches the input jobName parameter to the XMLJobConfig. */ if(this.batchConfigElement==null) throw new IllegalStateException("Factory is not initialized properly. Batch config element is null."); if(jobName==null) throw new IllegalArgumentException("jobName cannot be null."); NodeList jobConfigNodeList=this.batchConfigElement.getElementsByTagName(XMLJobConfig.JOB_CONFIG_ELEMENT_NAME); logger.trace("Number of job-config elements found in job configuration file = " + jobConfigNodeList.getLength()); for(int i=0;i<jobConfigNodeList.getLength();i++) { Element jobConfigElement=(Element)jobConfigNodeList.item(i); String elementJobName=jobConfigElement.getAttribute(XMLJobConfig.JOB_NAME_ATTRIBUTE_NAME); if(jobName.equals(elementJobName)) { logger.trace("Found the job-config matching the job name"); jobConfig=new XMLJobConfig(jobConfigElement); break; } } logger.trace("Exiting getJobConfig"); return jobConfig; } /** * Creates the DOM Element represents the batch-config element from the given stream * and assigns it to the class instance varaibale batchConfigElement. * * @param jobConfigStream InputStream of XML job configuration file. * * @return Returns true, if it could load the element from the given inputstream, false, otherwise. */ private boolean createBatchConfigElement(InputStream jobConfigStream) { boolean created=false; try { DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(true); DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); Document document=documentBuilder.parse(jobConfigStream); this.batchConfigElement=document.getDocumentElement(); if(this.batchConfigElement!=null) created=true; } catch(ParserConfigurationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); } catch(SAXException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); } catch(IOException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); } return created; } /** * <p> * Returns the string representation of XMLJobConfigFactory class in the format * <br> {XMLJobConfigFactory [configProperties = value] [element = value]} * </p> * * @return Returns the string representation of XMLJobConfigFactory. */ public String toString() { StringBuffer stringValue=new StringBuffer("{XMLJobConfigFactory "); stringValue.append("[configProperties = " + this.configFactoryProps + "]"); stringValue.append("[element = " + this.batchConfigElement + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: XMLBasicJobControllerConfig.java --- /* * XMLBasicJobControllerConfig.java * * Created on March 2, 2006, 1:56 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.xml; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.BasicJobControllerConfig; import org.jmonks.batch.framework.config.ConfigurationException; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * <p> * XMLBasicJobControllerConfig loads the XML job controller configuration. This loads * the following XML block in <job-config> from job configuration file. * <br><br> * <pre> * <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.basic.BasicJobController"> * <basic-job-processor basic-job-processor-class-name="com.mycompany.batch.processfilexyz.XyzProcessor" thread-count="1"> * <property key="basic-job-processor-config1">processor-value1</property> * </basic-job-processor> * <property key="basic-job-controller-config1">config-value1</property> * </job-controller> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class XMLBasicJobControllerConfig extends BasicJobControllerConfig { /** * XML Element name defiens the basic job processor configuration which is <code>basic-job-processor</code>. */ private static final String BASIC_JOB_PROCESSOR_ELEMENT_NAME = "basic-job-processor"; /** * XML Attribute name defines the basic job processor class name which is <code>basic-job-processor-class-name</code>. */ private static final String BASIC_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME = "basic-job-processor-class-name"; /** * XML Attribute name defines the thread count of the job processor which is <code>thread-count</code>. */ private static final String THREAD_COUNT_ATTRIBUTE_NAME = "thread-count"; private static Logger logger=Logger.getLogger(XMLBasicJobControllerConfig.class); /** * Loads the XML job controller configuration into XMLBasicJobControllerConfig object. * * @param controllerConfigElement XML DOM Element represents the <job-controller> element; * * @throws ConfigurationException If controller class name or job processor name doest not found. */ public XMLBasicJobControllerConfig(Element controllerConfigElement) { logger.trace("Entering Constructor"); this.jobControllerClassName=controllerConfigElement.getAttribute(XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME); if(this.jobControllerClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLJobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); FrameworkUtil.loadPropertiesFromElementToMap(controllerConfigElement, this.jobControllerConfigProps); logger.trace("Started reading the basic job processor configuration"); NodeList xmlBasicJobProcessorNodeList=controllerConfigElement.getElementsByTagName(XMLBasicJobControllerConfig.BASIC_JOB_PROCESSOR_ELEMENT_NAME); if(xmlBasicJobProcessorNodeList.getLength()==1) { Element xmlBasicJobProcessorElement=(Element)xmlBasicJobProcessorNodeList.item(0); this.basicJobProcessorClassName=xmlBasicJobProcessorElement.getAttribute(XMLBasicJobControllerConfig.BASIC_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME); if(this.basicJobProcessorClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, XMLBasicJobControllerConfig.BASIC_JOB_PROCESSOR_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); else { this.basicJobProcessorThreadCount=Integer.parseInt(xmlBasicJobProcessorElement.getAttribute(XMLBasicJobControllerConfig.THREAD_COUNT_ATTRIBUTE_NAME)); FrameworkUtil.loadPropertiesFromElementToMap(xmlBasicJobProcessorElement, this.basicJobProcessorConfigProps); } } else throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Found " + xmlBasicJobProcessorNodeList.getLength() + " element(s) in the basic job controller configuration."); logger.trace("Finished reading the basic job processor configuration"); logger.trace("Exiting Constructor"); } } |
From: Suresh <sur...@us...> - 2006-09-15 20:06:13
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/db In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19840 Added Files: DBBasicJobControllerConfig.java DBJobConfig.java DBJobConfigFactory.java DBJobControllerConfig.java DBJobLoggingConfig.java DBPoolJobControllerConfig.java Log Message: no message --- NEW FILE: DBJobConfigFactory.java --- /* * DBJobConfigFactory.java * * Created on March 2, 2006, 12:07 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; import org.jmonks.batch.framework.config.JobConfigFactory; import org.jmonks.batch.framework.util.JdbcConnectionHelper; /** * <p> * DBJobConfigFactory reads the job configuration from defined database to create the * configuration objects needed by the job. This factory looks for few properties * in the factory config properties map to identify the database it needs to connect to. This * factory looks for the job configuration in the <b>job-config</b> table in the database. * Controller configuration will be defined in a seperate tables, and DBJobControllerConfig * is responsible to read the job controller configuration from the database. * </p> * * <p> * This factory looks for the properties "jdbc-driver-class-name","jdbc-url", * "username" and "password" in job config factory config in framework configuration to * establish the connection to read the job configuration. If any one of the properties * are missing, it throws ConfigurationException. Following example shows, how it can * be configured for Oracle database. * <br><br> * <pre> * <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.framework.config.db.DBJobConfigFactory"> * <property key="jdbc-driver-class-name">oracle.jdbc.driver.OracleDriver</property> * <property key="jdbc-url">jdbc:oracle:thin:@hostname:1521:instancename</property> * <property key="username">scott</property> * <property key="password">tiger</property> * </job-config-factory-config> * </pre> * <br>The user specified in the configuration should have read privileges to the following database table objects. * <table border="1"> * <tr><td>JOB_CONFIG</td></tr> * <tr><td>JOB_LOGGING_CONFIG</td></tr> * <tr><td>BASIC_JOB_CONTROLLER_CONFIG</td></tr> * <tr><td>POOL_JOB_CONTROLLER_CONFIG</td></tr> * </table> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBJobConfigFactory extends JobConfigFactory { /** * Property map holds the properites required by this factory. */ private Map configFactoryProps=null; /** * SQL Query to pull the job configuration. */ private static final String JOB_CONFIG_QUERY = "select 1 from job_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobConfigFactory.class); /** *<p> * <i> * Do not use this constructor to instantiate DBJobConfigFactory directly. Use * the factory method getJobConfigFactory in JobConfigFactory class to get the config factory * instance. This constructor has been provided to make sure this should be * instantiable and accessible to the JobConfigFactory class. * </i> * </p> */ public DBJobConfigFactory() { } /** * This method initializes the factory by accepting the required properties * as a map. If it doesnt find any required properties * and values are not valid to initialize the factory, * throws ConfigurationException with the appropriate error message. * * @param configFactoryProps Map consists of all the properties defined for this factory. * * @throws ConfigurationException If required properties are missing. */ protected void init(Map configFactoryProps) { logger.trace("Entering init"); this.configFactoryProps=new HashMap(configFactoryProps); /** * Do the basic validation like look for the required properites and make a connection * and close it to make sure property values are valid. */ Connection connection=JdbcConnectionHelper.getConnection(this.configFactoryProps); if(connection==null) throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, "Unable to establish the database " + "connection with the properties " + this.configFactoryProps +"."); else JdbcConnectionHelper.closeConnection(connection); logger.trace("Exiting init"); } /** * Returns the requested job configuration as JobConfig object. The requested job * name should be passed as a parameter. If it doesnt find the configuration of * the requested jobName in the table <b>job_config</b> in given database, it returns null. * * @param jobName Name of the job. * * @return Returns the job config object if found, null, otherwise. * * @throws IllegalArgumentException If jobName passed as parameter is null. * @throws IllegalStateException If factory is not initialized properly. */ public JobConfig getJobConfig(String jobName) { logger.trace("Entering getJobConfig " + jobName); JobConfig jobConfig=null; if(jobName==null) throw new IllegalArgumentException("Job name cannot be null."); Connection connection=JdbcConnectionHelper.getConnection(this.configFactoryProps); if(connection==null) throw new IllegalStateException("DBJobConfigFacotry not initialized properly. Unable to get the connection."); /** * Look up job configuration in table job_config and pass that information to DBJobConfig. */ try { PreparedStatement statement=connection.prepareStatement(DBJobConfigFactory.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { logger.debug("Job found in database configuration"); jobConfig=new DBJobConfig(jobName,connection); logger.trace("Would be able to read the job configuration from database"); } else { jobConfig=null; logger.error("Could not find an entry in table job_config with the job name " + jobName); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); } finally { try{ connection.close(); } catch(Exception exception){ exception.printStackTrace(); } } logger.trace("ExitinggetJobConfig"); return jobConfig; } } --- NEW FILE: DBJobConfig.java --- /* * DBJobConfig.java * * Created on March 2, 2006, 11:58 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobConfig; /** * <p> * DBJobConfig provides the implementation of JobConfig by reading the * job configuration from given connection. This reads the job configuration * from table <b>job_config</b>. Following is the schema of that table. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>JOB_STATUS</td><td>NUMBER</td><td>Status of the job. 1 - Active, 0 - Inactive</td></tr> * <tr><td>JOB_CONTROLLER_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Controller to be used for this job. For pool job controller "<code>org.jmonks.batch.framework.controller.pool.PoolJobController</code> and for basic job controller <code>org.jmonks.batch.framework.controller.basic.BasicJobController</code></td></tr> * <tr><td>JOB_CONTROLLER_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties for the controller. See the schema column comments for the format.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @since 1.0 * @version 1.0 */ public class DBJobConfig extends JobConfig { /** * Query to load the job configuration from job_config table. */ private static final String JOB_CONFIG_QUERY = "select job_status from job_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobConfig.class); /** * Loads the job name and controller configuration into the job configuration object. * * @param jobName Name of the job to be loaded. * @param connection Connection to the Database. * * @throws ConfigurationException If job or controllers are not configured properly. */ DBJobConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); this.jobName=jobName; logger.debug("Job Name = " + this.jobName); try { PreparedStatement statement=connection.prepareStatement(DBJobConfig.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { int status=resultSet.getInt(1); this.jobStatus=(status==1?true:false); logger.debug("Job Status = " + this.jobStatus); this.jobLoggingConfig=new DBJobLoggingConfig(jobName, connection); logger.debug("Job Logging configuration = " + this.jobLoggingConfig); this.jobControllerConfig=DBJobControllerConfig.getJobControllerConfig(jobName, connection); logger.debug("Job Controller configuration = " + this.jobControllerConfig); } else { /** * How can this is possible? Just now.. I could see this entry in job_config. */ logger.error("Could not find entry in job_config with job name " + jobName); throw new IllegalStateException("Surprisingly.. Could not find entry in job_config with job_name " + jobName); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBPoolJobControllerConfig.java --- /* * DBPoolJobControllerConfig.java * * Created on March 2, 2006, 1:41 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.PoolJobControllerConfig; /** * <p> * DBPoolJobControllerConfig loads the job controller configuration from the defined * database. This loads the pool controller configuration from the table <b>pool_job_controller_config</b>. * Following is the schema of that table defined in the database. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the processor class writes the business logic of consumer the data from the pool by implementing the PoolJobProcessor interface.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_THREAD_CNT</td><td>NUMBER</td><td>Number of processor instances (each instance will be run in its own thread) to be created while executing the job.</td></tr> * <tr><td>POOL_JOB_PROCESSOR_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job processor.</td></tr> * <tr><td>POOL_JOB_LOADER_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the loader class writes the business logic of loading the jobs into the pool by implemention the PoolJobLoader interface. This will be run in its own thread.</td></tr> * <tr><td>POOL_JOB_LOADER_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job loader.</td></tr> * <tr><td>JOB_POOL_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the class act as pool/channel/pipe between the loader and multiple processors. Multiple implementations will be available and can be chosen based on the need.</td></tr> * <tr><td>JOB_POOL_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the job pool.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBPoolJobControllerConfig extends PoolJobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites from job_config. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * SQL Query pulls the information pool_job_controller_config table. */ private static final String POOL_JOB_CONTROLLER_CONFIG_QUERY = "select pool_job_processor_class_name, " + "pool_job_processor_thread_cnt, pool_job_processor_props, pool_job_loader_class_name, " + "pool_job_loader_props, job_pool_class_name, job_pool_props from pool_job_controller_config " + "where job_name=?"; private static Logger logger=Logger.getLogger(DBPoolJobControllerConfig.class); /** * Loads the pool job controller configuration from table pool_job_controller_config * into DBPoolJobControllerConfig object. * * @param jobName Name of the job. * @param connection Connection to the defined database. * * @throws ConfigurationException If controller class name or job processor name doest not found. */ public DBPoolJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); try { PreparedStatement jobConfigStatement=connection.prepareStatement(DBPoolJobControllerConfig.JOB_CONFIG_QUERY); jobConfigStatement.setString(1, jobName); ResultSet jobConfigResultSet=jobConfigStatement.executeQuery(); if(jobConfigResultSet.next()) { this.jobControllerClassName=jobConfigResultSet.getString(1); String controllerConfigProps=jobConfigResultSet.getString(2); if(controllerConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(controllerConfigProps, this.jobControllerConfigProps); } else { /** * Surprising!!!!!!!!! */ logger.error("no controller configuration found"); } logger.trace("Started loading pool job controller configuration"); PreparedStatement controllerConfigStatement=connection.prepareStatement(DBPoolJobControllerConfig.POOL_JOB_CONTROLLER_CONFIG_QUERY); controllerConfigStatement.setString(1,jobName); ResultSet controllerConfigResultSet=controllerConfigStatement.executeQuery(); if(controllerConfigResultSet.next()) { this.poolJobProcessorClassName=controllerConfigResultSet.getString(1); this.poolJobProcessorThreadCount=controllerConfigResultSet.getInt(2); String processorConfigProps=controllerConfigResultSet.getString(3); if(processorConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(processorConfigProps,this.poolJobProcessorConfigProps); this.poolJobLoaderClassName=controllerConfigResultSet.getString(4); String loaderConfigProps=controllerConfigResultSet.getString(5); if(loaderConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(loaderConfigProps,this.poolJobLoaderConfigProps); this.poolClassName=controllerConfigResultSet.getString(6); String poolConfigProps=controllerConfigResultSet.getString(7); if(poolConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(poolConfigProps,this.poolConfigProps); } else { throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Controller configuration is not defined for the job " + jobName + "."); } logger.trace("Finished loading pool job controller configuration"); } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBJobControllerConfig.java --- /* * DBJobControllerConfig.java * * Created on March 2, 2006, 1:22 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobControllerConfig; /** * <p> * DBJobControllerConfig responsible to build the controller specific * JobControllerConfig objects from the given database. It looks for the * configured controller in <b>job_config.job_controller_class_name</b> column * and instantiates the appropriate JobControllerConfig instance and set the * controller configuration properties. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class DBJobControllerConfig extends JobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * Identifier used to request the Framework controller configuration for the specific controller config for this factory. */ public static final String JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME = "db-factory-config-class-name"; private static Logger logger=Logger.getLogger(DBJobControllerConfig.class); /** * <p> * Factory method creates and returns the controller specific controller config object * from the table job_config and controller specific tables. This looks for the * controller class name in job_config and tries to find specific controller config object for this controller * and defined for the DB factory in framework configuration file. * </p> * * @return Returns the controller specific controller config object. * * @throws ConfigurationException If controller config class name is not defined or controller specific config object cannot be found * in framework controller configuration. */ public static JobControllerConfig getJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering getJobControllerConfig " + jobName); JobControllerConfig controllerConfig=null; try { PreparedStatement statement=connection.prepareStatement(DBJobControllerConfig.JOB_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); if(resultSet.next()) { String controllerClassName=resultSet.getString(1); logger.debug("Controller class name = " + controllerClassName); try { String controllerConfigClassName=FrameworkConfig.getInstance().getJobControllerConfig().getConfigClassName(controllerClassName, DBJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME); logger.debug("Controller config class name = " + controllerConfigClassName); if(controllerConfigClassName==null) throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Could not found controller config class for the controller " + controllerClassName + " for the factory " + DBJobControllerConfig.JOB_CONTROLLER_CONFIG_FACTORY_CLASS_ATTRIBUTE_NAME + "."); else { Class configClass=Class.forName(controllerConfigClassName); Constructor constructor=configClass.getConstructor(new Class[]{String.class,Connection.class}); controllerConfig=(JobControllerConfig)constructor.newInstance(new Object[]{jobName,connection}); } } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(NoSuchMethodException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } catch(ClassNotFoundException 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()); } catch(InvocationTargetException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting getJobControllerConfig"); return controllerConfig; } } --- NEW FILE: DBBasicJobControllerConfig.java --- /* * DBBasicJobControllerConfig.java * * Created on March 2, 2006, 1:55 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.jmonks.batch.framework.config.BasicJobControllerConfig; import org.jmonks.batch.framework.config.ConfigurationException; /** * <p> * DBBasicJobControllerConfig loads the job controller configuration from the defined * database. This loads the basic controller configuration from the table <b>basic_job_controller_config</b>. * Following is the schema of that table defined in the database. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_CLASS_NAME</td><td>VARCHAR2(256)</td><td>Name of the processor class implements the business logic by extending the BasicJobProcessor class.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_THREAD_CNT</td><td>NUMBER</td><td>Number of processor instances(each instance will be executed in its own thread) to be created while executing the job.</td></tr> * <tr><td>BASIC_JOB_PROCESSOR_PROPS</td><td>VARCHAR2(1024)</td><td>Configuration properties required by the processor. These can be accessed through JobContext reference.</td></tr> * </table> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBBasicJobControllerConfig extends BasicJobControllerConfig { /** * SQL Query retrieves the job controller class name and controller properites from job_config. */ private static final String JOB_CONFIG_QUERY = "select job_controller_class_name,job_controller_props from job_config where job_name=?"; /** * SQL Query pulls the information basic_job_controller_config table. */ private static final String BASIC_JOB_CONTROLLER_CONFIG_QUERY = "select basic_job_processor_class_name, basic_job_processor_thread_cnt, basic_job_processor_props from basic_job_controller_config where job_name=?"; private static Logger logger=Logger.getLogger(DBBasicJobControllerConfig.class); /** * Loads the basic job controller configuration from table basic_job_controller_config * into DBBasicJobControllerConfig object. * * @param jobName Name of the job. * @param connection Connection to the defined database. * * @throws ConfigurationException If controller class name or job processor name doest not found. */ public DBBasicJobControllerConfig(String jobName,Connection connection) { logger.trace("Entering constructor " + jobName); try { PreparedStatement jobConfigStatement=connection.prepareStatement(DBBasicJobControllerConfig.JOB_CONFIG_QUERY); jobConfigStatement.setString(1, jobName); ResultSet jobConfigResultSet=jobConfigStatement.executeQuery(); if(jobConfigResultSet.next()) { this.jobControllerClassName=jobConfigResultSet.getString(1); String controllerConfigProps=jobConfigResultSet.getString(2); logger.debug("controller configuration props = " + controllerConfigProps); if(controllerConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(controllerConfigProps, this.jobControllerConfigProps); } else { /** * Surprising!!!!!!!!! */ logger.error("Job configuration not found with the name " + jobName); } logger.trace("Started loading basic job processor configuration"); PreparedStatement controllerConfigStatement=connection.prepareStatement(DBBasicJobControllerConfig.BASIC_JOB_CONTROLLER_CONFIG_QUERY); controllerConfigStatement.setString(1,jobName); ResultSet controllerConfigResultSet=controllerConfigStatement.executeQuery(); if(controllerConfigResultSet.next()) { this.basicJobProcessorClassName=controllerConfigResultSet.getString(1); this.basicJobProcessorThreadCount=controllerConfigResultSet.getInt(2); String processorConfigProps=controllerConfigResultSet.getString(3); if(processorConfigProps!=null) FrameworkUtil.loadPropertiesFromStringToMap(processorConfigProps,this.basicJobProcessorConfigProps); } else { throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, "Controller configuration is not defined for the job " + jobName); } logger.trace("Finished loading basic job processor configuration"); } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); throw new ConfigurationException(ConfigurationException.JOB_CONTROLLER_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } --- NEW FILE: DBJobLoggingConfig.java --- /* * DBJobLoggingConfig.java * * Created on March 13, 2006, 8:17 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config.db; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.JobLoggingConfig; /** * <p> * DBJobLoggingConfig reads the job logging configuration from the table <b>job_logging_config</b>. * Below is the schema of <b>job_logging_config</b> table. * <br><br> * <pre> * <table border="1"> * <tr><td><b>Column Name</b></td><td><b>Data Type</b></td><td><b>Purpose</b></td></tr> * <tr><td>JOB_NAME</td><td>VARCHAR2(64)</td><td>Name of the Job.</td></tr> * <tr><td>JOB_LOGGER_NAME</td><td>VARCHAR2(256)</td><td>Package name of the logger. Values will be like <code>com.mycompany.jobs.myjob</code></td></tr> * <tr><td>JOB_LOGGER_LEVEL</td><td>VARCHAR2(32)</td><td>Level of the logger. Values can be TRACE,DEBUG,INFO,WARN,ERROR,FATAL</td></tr> * </table> * </pre> * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class DBJobLoggingConfig extends JobLoggingConfig { private static final String JOB_LOGGING_CONFIG_QUERY="select job_logger_name,job_logger_level from job_logging_config where job_name=?"; private static Logger logger=Logger.getLogger(DBJobLoggingConfig.class); /** * Reads the configuration from the table <b>job_logging_config</b> and add * each record as JobLoggerConfig object. * * @param jobName Name of the job. * @param connection Database connection to the defined database. */ public DBJobLoggingConfig(String jobName,Connection connection) { logger.trace("Entering constructor"); try { PreparedStatement statement=connection.prepareStatement(DBJobLoggingConfig.JOB_LOGGING_CONFIG_QUERY); statement.setString(1, jobName); ResultSet resultSet=statement.executeQuery(); while(resultSet.next()) { String loggerName=resultSet.getString(1); String loggerLevel=resultSet.getString(2); this.addLogger(loggerName,loggerLevel); } } catch(SQLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG, exception.getMessage()); } logger.trace("Exiting constructor"); } } |
From: Suresh <sur...@us...> - 2006-09-15 20:06:01
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19495 Added Files: BasicJobControllerConfig.java ConfigurationException.java FrameworkConfig.java JobConfig.java JobConfigFactory.java JobControllerConfig.java JobLoggingConfig.java PoolJobControllerConfig.java Log Message: no message --- NEW FILE: JobConfig.java --- /* * JobConfig.java * * Created on March 2, 2006, 11:40 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.Map; /** * <p> * JobConfig represents the configuration needed to execute the job. This provides * interface to the different implementations of JobConfig. Each factory will read * the configuration from its source and creates JobConfig. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobConfig { /** * Name of the job this configuration belongs to. */ protected String jobName=null; /** * Variable holds the status of the job. True stands for active and flase stands inactive. */ protected boolean jobStatus = true; /** * Controller configuration of the job. */ protected JobControllerConfig jobControllerConfig; /** * Map holds the logger information. This will hold the logger */ protected JobLoggingConfig jobLoggingConfig=null; /** * Returns the Controller configuraiton of the job this JobConfig represents. * * @return Returns controller configuration of this job. */ public JobControllerConfig getJobControllerConfig() { return this.jobControllerConfig; } /** * Returns the name of the job. * * @return Returns the name of the job. */ public String getJobName() { return this.jobName; } /** * Returns whether the job is active or not. * This information will be found from the instance varaiable jobStatus. * JobStatus of true indicates active and false indicates inactive. * * @return Returns true, if job is active, false otherwise. */ public boolean getJobStatus() { return this.jobStatus; } /** * Returns job logging configuration. * Job Loggers can be found by using the getLoggers method of this config object. * * @return Returns job logging configuraiton. */ public JobLoggingConfig getJobLoggingConfig() { return this.jobLoggingConfig; } /** * <p> * Returns the string representation of JobConfig class in the format * <br> {JobConfig [name = value] [status = value] [controllerConfig = value]} * </p> * * @return Returns the string representation of JobConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobConfig "); stringValue.append("[name = " + this.jobName + "]"); stringValue.append("[status = " + this.jobStatus + "]"); stringValue.append("[controllerConfig = " + this.jobControllerConfig + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: BasicJobControllerConfig.java --- /* * BasicJobControllerConfig.java * * Created on March 2, 2006, 1:44 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; /** * <p> * BasicJobControllerConfig provides the configuration for the BasicJobController. * </p> * * <p> * BasicJobController holds the class name that extended the BasicJobProcessor and * number of instances(each instance run its own thread) to be created to run this * processor and configuration required by that processor. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class BasicJobControllerConfig extends JobControllerConfig { /** * Basic job processor class name. */ protected String basicJobProcessorClassName=null; /** * Map contains the properties required by the basic job processor. */ protected Map basicJobProcessorConfigProps=new HashMap(); /** * Holds the number of instances needs to be created. */ protected int basicJobProcessorThreadCount=1; private static Logger logger=Logger.getLogger(BasicJobControllerConfig.class); /** * Gets the basic job processor class name. * * @return Returns the basic job processor class name. */ public String getBasicJobProcessorClassName() { return this.basicJobProcessorClassName; } /** * Gets the unmodifiable map contains the properties required by basic job processor. * * @return Returns the map contains the properties required by basic job processor. */ public Map getBasicJobProcessorConfigProperties() { return Collections.unmodifiableMap(this.basicJobProcessorConfigProps); } /** * Returns the number of basic job processor instances needs to be run to process this job. * * @return Returns the number of threads. */ public int getBasicJobProcessThreadCount() { return this.basicJobProcessorThreadCount; } /** * <p> * Returns the string representation of BasicJobControllerConfig class in the format * <br> {BasicJobControllerConfig [controllerClassName = value] [controllerConfigProps = value] * [basicJobProcessorClassName = value] [basicJobProcessorConfigProps = value] * [basicJobProcessorThreadCount = value]} * </p> * * @return Returns the string representation of BasicJobControllerConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{BasicJobControllerConfig "); stringValue.append("[controllerClassName = " + this.jobControllerClassName + "]"); stringValue.append("[controllerConfigProps = " + this.jobControllerConfigProps + "]"); stringValue.append("[basicJobProcessorClassName = " + this.basicJobProcessorClassName + "]"); stringValue.append("[basicJobProcessorConfigProps = " + this.basicJobProcessorConfigProps + "]"); stringValue.append("[basicJobProcessorThreadCount = " + this.basicJobProcessorThreadCount + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: FrameworkConfig.java --- /* * FrameworkConfig.java * * Created on March 2, 2006, 11:21 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.io.IOException; import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; import org.jmonks.batch.framework.util.FrameworkUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * <p> * FrameworkConfig class is responsible to read the framework configuration from * <code>framework-config.xml</code> file and gives the configuration * in the form of configuration objects when needed. * This searches the classpath for the <code>framework-config.xml</code>. Place * this file in any directory and keep the directory in the classpath. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public final class FrameworkConfig { private static Logger logger=Logger.getLogger(FrameworkConfig.class); /** * FrameworkConfig singleton instance varaible. */ private static final FrameworkConfig frameworkConfig=new FrameworkConfig(); /** * Declaration of XML file holds the framework configuration which is <code>framework-config.xml</code>. */ private static final String FRAMEWORK_CONFIG_FILE = "framework-config.xml"; /** * Name of the tag represents the complete framework configuration which is <code>framework-config</code>. */ private static final String FRAMEWORK_CONFIG_TAG_NAME = "framework-confg"; /** * JobConfigFactoryConfig variable to hold the JobConfigFactoryObject object. */ private JobConfigFactoryConfig configFactoryConfig=null; /** * FrameworkLoggingConfig variable to hold the FrameworkLoggingConfig object. */ private FrameworkLoggingConfig frameworkLoggingConfig=null; /** * JobConnectorConfig variable to hold the JobConnectorConfig object. */ private JobConnectorConfig jobConnectorConfig=null; /** * RepositoryConfig variable to hold the RepositoryConfig object. */ private RepositoryConfig repositoryConfig=null; /** * JobControllerConfig varaible to hold JobControllerConfig object. */ private JobControllerConfig controllerConfig=null; /** * <p> * Private constructor to make sure FrameworkConfig cannot be instantiated. This will * read the framework configuration file and create the instances of of JobConfigFactoryConfig, * FrameworkLoggingConfig, JobConnectorConfig and RepositoryConfig by passing the correct DOM elements to their * constructors. In case of errors in the configuration it throws the ConfigurationException * with the correct error code. * </p> * * @throws ConfigurationException If configuration file could not be found. */ private FrameworkConfig() { logger.trace("Entering DefaultConstructor"); try { InputStream configFileStream=FrameworkConfig.class.getClassLoader().getResourceAsStream(FrameworkConfig.FRAMEWORK_CONFIG_FILE); if(configFileStream==null) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Framework configuration file " + FrameworkConfig.FRAMEWORK_CONFIG_FILE + " cannot be accessed from the classpath."); logger.debug("Framework configuration file has been accessed"); if(System.getProperty("javax.xml.parsers.DocumentBuilderFactory")==null) System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(true); /* Commenting out the validator for a while documentBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema"); InputStream xsdStream=FrameworkConfig.class.getClassLoader().getResourceAsStream("framework-config.xsd"); documentBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",xsdStream); */ DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); documentBuilder.setErrorHandler(new DefaultHandler()); Document document=documentBuilder.parse(configFileStream); logger.debug("Framework configuration file has been parsed."); Element frameworkConfigElement=document.getDocumentElement(); if(FrameworkConfig.FRAMEWORK_CONFIG_TAG_NAME.equals(frameworkConfigElement.getTagName())) { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Expected the root element of framework configuration to be " + FrameworkConfig.FRAMEWORK_CONFIG_TAG_NAME + ", but encountered the tag with the name " + frameworkConfigElement.getTagName() + " accessed from the location " + FrameworkConfig.FRAMEWORK_CONFIG_FILE + "."); } NodeList jobConfigFactoryConfigNodeList=frameworkConfigElement.getElementsByTagName(JobConfigFactoryConfig.TAG_NAME); if(jobConfigFactoryConfigNodeList.getLength()==1) { this.configFactoryConfig=new JobConfigFactoryConfig(((Element)jobConfigFactoryConfigNodeList.item(0))); } else { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Found " + jobConfigFactoryConfigNodeList.getLength() + " " + JobConfigFactoryConfig.TAG_NAME + " element(s) in the framework configuration, where only one such element is allowed."); } logger.debug("Job Config Factory configuration has been loaded and the configuration is : " + this.configFactoryConfig); NodeList loggingConfigNodeList=frameworkConfigElement.getElementsByTagName(FrameworkLoggingConfig.TAG_NAME); if(loggingConfigNodeList.getLength()==1) { this.frameworkLoggingConfig=new FrameworkLoggingConfig(((Element)loggingConfigNodeList.item(0))); } else { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Found " + loggingConfigNodeList.getLength() + " " + FrameworkLoggingConfig.TAG_NAME + " element(s) in the framework configuration, where only one such element is allowed."); } logger.debug("Logging configuration has been loaded and the configuration is : " + this.frameworkLoggingConfig); NodeList jobConnectorConfigNodeList=frameworkConfigElement.getElementsByTagName(JobConnectorConfig.TAG_NAME); if(jobConnectorConfigNodeList.getLength()==1) { this.jobConnectorConfig=new JobConnectorConfig(((Element)jobConnectorConfigNodeList.item(0))); } else { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Found " + jobConnectorConfigNodeList.getLength() + " " + JobConnectorConfig.TAG_NAME + " element(s) in the framework configuration, where only one such element is allowed."); } logger.debug("MgmtMntr configuration has been loaded and the configuration is : " + this.jobConnectorConfig); NodeList repositoryConfigNodeList=frameworkConfigElement.getElementsByTagName(RepositoryConfig.TAG_NAME); if(repositoryConfigNodeList.getLength()==1) { this.repositoryConfig=new RepositoryConfig(((Element)repositoryConfigNodeList.item(0))); } else { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Found " + repositoryConfigNodeList.getLength() + " " + RepositoryConfig.TAG_NAME + " element(s) in the framework configuration, where only one such element is allowed."); } logger.debug("Repository configuration has been loaded and the configuration is : " + this.repositoryConfig); NodeList controllerConfigNodeList=frameworkConfigElement.getElementsByTagName(JobControllerConfig.TAG_NAME); if(controllerConfigNodeList.getLength()==1) { this.controllerConfig=new JobControllerConfig(((Element)controllerConfigNodeList.item(0))); } else { throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, "Found " + controllerConfigNodeList.getLength() + " " + JobControllerConfig.TAG_NAME + " element(s) in the framework configuration, where only one such element is allowed."); } logger.debug("Job Controller configuration has been loaded and the configuration is : " + this.controllerConfig); } catch(IOException ioException) { ioException.printStackTrace(); logger.error(ioException.getMessage(),ioException); throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, ioException.getMessage()); } catch(ParserConfigurationException parserConfigException) { parserConfigException.printStackTrace(); logger.error(parserConfigException.getMessage(), parserConfigException); throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, parserConfigException.getMessage()); } catch(SAXException saxException) { saxException.printStackTrace(); logger.error(saxException.getMessage(), saxException); throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, saxException.getMessage()); } logger.trace("Exiting DefaultConstructor"); } /** * Returns the FrameworkConfig instance. * * @return Returns the FrameworkConfig instance. */ public static FrameworkConfig getInstance() { return frameworkConfig; } /** * Returns the job configuration factory configuration defined in framework configuration * as JobConfigFactoryConfig object. * * @return Returns the JobConfigFactoryConfig object. */ public JobConfigFactoryConfig getJobConfigFactoryConfig() { return this.configFactoryConfig; } /** * Returns the logging configuration defined in the framework configuration as a FrameworkLoggingConfig object. * * @return Returns the FrameworkLoggingConfig object. */ public FrameworkLoggingConfig getFrameworkLoggingConfig() { return this.frameworkLoggingConfig; } /** * Returns the mgmt&mntr configuration defines in the framework configuration as JobConnectorConfig object. * * @return Returns the JobConnectorConfig object. */ public JobConnectorConfig getJobConnectorConfig() { return this.jobConnectorConfig; } /** * Returns the repository configuration defined in framework configuration as a RepositoryConfig object. * * @return Returns the RepositoryConfig object. */ public RepositoryConfig getRepositoryConfig() { return this.repositoryConfig; } /** * Returns the job controller configuration defined in framework configuration as a JobControllerConfig object. * * @return Returns the JobControllerConfig object. */ public JobControllerConfig getJobControllerConfig() { return this.controllerConfig; } /** * <p> * JobConfigFactoryConfig class holds the configuration information required * by Job configuration factories. Factory would need some properties like source * of the job configuration, credentials to access the source * based on the factory type. This object provides the factory class name * and its supported property information. * </p> * <p> * This class will be accessible to all the classes in the framework and can be created * only by the FrameworkConfig class. * </p> * <p> * Holds the following configuration defined in the framework configuration file. * <br><br> * <pre> * <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.framework.config.xml.XMLJobConfigFactory"> * <property key="config-file-absolute-location">/batchserver/config/batch-config.xml</property> * <!-- * Following is the another way to configure the XML Job configuration. * <property key="config-file-classpath-location">org.jmonks.batch.framework.config.batch-config.xml</property> * --> * </job-config-factory-config> * </pre> * </p> */ public class JobConfigFactoryConfig { /** * Tag name represents the job config factory config in framework configuration file * which is <code>job-config-factory-config</code>. */ private static final String TAG_NAME = "job-config-factory-config"; /** * Attribute name represents the job config factory class name which is * <code>job-config-factory-class-name</code>. */ private static final String FACTORY_CLASS_ATTRIBUTE_NAME = "job-config-factory-class-name"; /** * Job config factory class name. */ private String jobConfigFactoryClassName=null; /** * Map holds the properites required by job config factory. */ private Map jobConfigFactoryProperties=new HashMap(); /** * This constructor will read the job configuration factory information from * the given DOM element which represents the tag <job-config-factory-config>. * Private constructor to make sure, it cannot be instantiated from outside of FrameworkConfig class. * * @param jobConfigFactoryElement DOM Element represents <job-config-factory-config> tag in framework configuration file. */ private JobConfigFactoryConfig(Element jobConfigFactoryElement) { logger.trace("Entering Constructor"); this.jobConfigFactoryClassName=jobConfigFactoryElement.getAttribute(JobConfigFactoryConfig.FACTORY_CLASS_ATTRIBUTE_NAME); if(this.jobConfigFactoryClassName==null || "".equals(this.jobConfigFactoryClassName)) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, JobConfigFactoryConfig.FACTORY_CLASS_ATTRIBUTE_NAME + " attribute value cannot be null."); FrameworkUtil.loadPropertiesFromElementToMap(jobConfigFactoryElement,jobConfigFactoryProperties); logger.trace("Exiting Constructor"); } /** * Returns the class name of the factory used to read the job configuration. * * @return Returns the factory class name. */ public String getJobConfigFactoryClassName() { return this.jobConfigFactoryClassName; } /** * Returns the unmodifiable properties map used by the factory class to read the job configuration. * * @returns Returns properties in a map. In case if there are no properties, it returns empty map. It doesnt return null. */ public Map getJobConfigFactoryProperties() { return Collections.unmodifiableMap(this.jobConfigFactoryProperties); } /** * <p> * Returns the string representation of JobConfigFactoryConfig class in the format * <br> {JobConfigFactoryConfig [configFactoryclassName = value] [properties = value]} * </p> * * @return Returns the string representation of JobConfigFactoryConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobConfigFactoryConfig "); stringValue.append("[configFactoryclassName = " + this.jobConfigFactoryClassName + "]"); stringValue.append("[properties = " + this.jobConfigFactoryProperties + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * FrameworkLoggingConfig class holds configuration required to enable the framework logging * by LoggingManager. This configuration would be like the directory needs to write * job log files and logging level of the framework logs & job logs and base package name * to be used to create the logging handlers. * This class can be accessed by all the classes in the framework * but cannot be instantiated outside of this class. * </p> * <p> * This class represents the following information for the framework configration file * <br><br> * <pre> * <framework-logging-config framework-logging-level="DEBUG" job-logging-direcotry="/batchserver/logs" * job-base-package-name="com.mycompany.batch" job-logging-level="DEBUG"/> * </pre> * </p> */ public class FrameworkLoggingConfig { /** * Tag name represents the logging config in framework configuration file which * is <code>framework-logging-config</code>. */ private static final String TAG_NAME = "framework-logging-config"; /** * Attribute name defines the framework logging level which is <code>framework-logging-level</code>. */ private static final String FRAMEWORK_LOGGING_LEVEL_ATTRIB_NAME = "framework-logging-level"; /** * Attribute name defines the job logging directory which is <code>job-logging-directory</code>. */ private static final String JOB_LOGGING_DIRECTORY_ATTRIB_NAME = "job-logging-directory"; /** * Attribute name defines the job logging level which is <code>job-logging-level</code>. */ private static final String JOB_LOGGING_LEVEL_ATTRIB_NAME = "job-logging-level"; /** * Attribute name defines the job base package name which is <code>job-base-package-name</code>. */ private static final String JOB_BASE_PACKAGE_ATTRIB_NAME = "job-base-package-name"; /** * Framework logging level. */ private String frameworkLoggingLevel="DEBUG"; /** * Direcotry where all the log files needs to be written. */ private String jobLoggingDirectory=null; /** * Job logging level. */ private String jobLoggingLevel="ERROR"; /** * Base package name of the application(job). */ private String jobBasePackageName=null; /** * This constructor will read the logging configuration from * the given DOM element which represents the tag <logging-config>. * Private constructor to make sure, it cannot be instantiated from outside of FrameworkConfig class. * * @param loggingConfigElement DOM Element represents <logging-config> tag in framework configuration file. */ private FrameworkLoggingConfig(Element loggingConfigElement) { logger.trace("Entering LoggingConfig Constructor"); this.jobLoggingDirectory=loggingConfigElement.getAttribute(FrameworkLoggingConfig.JOB_LOGGING_DIRECTORY_ATTRIB_NAME); if(jobLoggingDirectory==null || "".equals(jobLoggingDirectory)) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, FrameworkLoggingConfig.JOB_LOGGING_DIRECTORY_ATTRIB_NAME + " attribute value cannot be null."); this.frameworkLoggingLevel=loggingConfigElement.getAttribute(FrameworkLoggingConfig.FRAMEWORK_LOGGING_LEVEL_ATTRIB_NAME); if(this.frameworkLoggingLevel== null || "".equals(this.frameworkLoggingLevel)) this.frameworkLoggingLevel="DEBUG"; this.jobLoggingLevel=loggingConfigElement.getAttribute(FrameworkLoggingConfig.JOB_LOGGING_LEVEL_ATTRIB_NAME); if(this.jobLoggingLevel== null || "".equals(this.jobLoggingLevel)) this.jobLoggingLevel="ERROR"; this.jobBasePackageName=loggingConfigElement.getAttribute(FrameworkLoggingConfig.JOB_BASE_PACKAGE_ATTRIB_NAME); logger.trace("Exiting LoggingConfig Constructor"); } /** * Returns the job logging directory name, where to all the job logs needs to be written. * * @return Returns the logging directory name. */ public String getJobLoggingDirecotry() { return this.jobLoggingDirectory; } /** * Returns the framework log level to use for the logging. * * @return Returns the log level. */ public String getFrameworkLoggingLevel() { return this.frameworkLoggingLevel; } /** * Returns the job log level to use for the logging. * * @return Returns the log level. */ public String getJobLoggingLevel() { return this.jobLoggingLevel; } /** * Returns the base package name to be used for the logging. This base package is job * base package like com.mycompany.batch * * @return Returns the jobs base package name. */ public String getJobBasePackageName() { return this.jobBasePackageName; } /** * <p> * Returns the string representation of FrameworkLoggingConfig class in the format * <br> {FrameworkLoggingConfig [jobLoggingDirectory = value] [frameworkLoggingLevel = value] * [jobBasePackageName = value] [jobLoggingLevel = value]} * </p> * * @return Returns the string representation of FrameworkLoggingConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{LoggingConfig "); stringValue.append("[jobLoggingDirectory = " + this.jobLoggingDirectory + "]"); stringValue.append("[frameworkLoggingLevel = " + this.frameworkLoggingLevel + "]"); stringValue.append("[jobBasePackageName = " + this.jobBasePackageName + "]"); stringValue.append("[jobLoggingLevel = " + this.jobLoggingLevel + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * JobConnectorConfig class holds the configuration required to create the * JobConnectorHelper classes used in establishing the job management agent and clients. * This configuration defines the specialized job connector helper class name * and properties required by that helper class. * This class cannot be instantiated by any other classes outside this framework. * </p> * <p> * This class holds the following configuration from the framework configuration file. * <br><br> * <pre> * <job-connector-config job-connector-helper-class-name="org.jmonks.batch.framework.management.jmxmp.RepositoryJMXMPConnectorHelper"> * <property key="port-range">15000-20000</property> * </job-connector-config> * </pre> * </p> */ public class JobConnectorConfig { /** * Tag name represents the job connector config in framework configuration file * which is <code>job-connector-config</code>. */ private static final String TAG_NAME = "job-connector-config"; /** * Attribute name defines the job connector server helper class name * which is <code>job-connector-helper-class-name</code>. */ private static final String JOB_CONNECTOR_HELPER_CLASS_ATTRIB_NAME = "job-connector-helper-class-name"; /** * Job connector helper class name. */ private String jobConnectorHelperClassName=null; /** * Supporting properties for the defined helper class. */ private Map jobConnectorConfigProperties=new HashMap(); /** * This constructor loads the JobConnectorConfig object with the given * DOM Element represents the <job-connector-config> in the framework configuration file. * * @param jobConnectorConfigElement DOM Element represents the <job-connector-config> tag in framework configuration file. */ private JobConnectorConfig(Element jobConnectorConfigElement) { logger.trace("Entering JobConnectorConfig Constructor"); this.jobConnectorHelperClassName=jobConnectorConfigElement.getAttribute(JobConnectorConfig.JOB_CONNECTOR_HELPER_CLASS_ATTRIB_NAME); if(this.jobConnectorHelperClassName==null || "".equals(this.jobConnectorHelperClassName)) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, JobConnectorConfig.JOB_CONNECTOR_HELPER_CLASS_ATTRIB_NAME + " attribute value cannot be null."); FrameworkUtil.loadPropertiesFromElementToMap(jobConnectorConfigElement, this.jobConnectorConfigProperties); logger.trace("Exiting JobConnectorConfig Constructor"); } /** * Returns the defined job connector helper class name for the framework. * * @return Returns the job connector helper class name. */ public String getJobConnectorHelperClassName() { return this.jobConnectorHelperClassName; } /** * Returns the unmodifiable map consist of the properties needed by the defined job connectors. * * @return Returns the properties in a map. */ public Map getJobConnectorConfigProperties() { return Collections.unmodifiableMap(this.jobConnectorConfigProperties); } /** * <p> * Returns the string representation of JobConnectorConfig class in the format * <br> {JobConnectorConfig [jobConnectorHelperClassName = value] [properties = value]} * </p> * * @return Returns the string representation of JobConnectorConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobConnectorConfig "); stringValue.append("[jobConnectorHelperClassName = " + this.jobConnectorHelperClassName + "]"); stringValue.append("[properties = " + this.jobConnectorConfigProperties + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * RepositoryConfig class holds the configuration required to create the class * provides the interface to the framework repository and properties needed * to work with the repository. * </p> * <p> * This class represents the following configuration from framework configuration file. * <br><br> * <pre> * <repository-config repository-class-name="org.jmonks.batch.framework.repository.db4o.Db4oRepository"> * <property key="db4o-filename">/batchserver/repository/batchserver_repository.db</property> * </repository-config> * </pre> * </p> */ public class RepositoryConfig { /** * Tag name represents the repository config in framework configuration file * which is <code>repository-config</code>. */ private static final String TAG_NAME = "repository-config"; /** * Attribute name defines the repository class name which is <code>repository-class-name</code>. */ private static final String REPOSITORY_CLASS_ATTRIB_NAME = "repository-class-name"; /** * Repository implementation class name. */ private String repositoryClassName=null; /** * Map holds the required properties of the defined repository class. */ private Map repositoryConfigProperties=new HashMap(); /** * This constructor would read the configuration from the given DOM Element represents * the <repository-config> tag and creates * the object with that information. Private constructor to make sure, this class cannot * be instantiated from outside of this class. * * @param repositoryConfigElement DOM Element repsents the <repository-config> tag in framework configuration. */ private RepositoryConfig(Element repositoryConfigElement) { logger.trace("Entering RepositoryConfig Constructor"); this.repositoryClassName=repositoryConfigElement.getAttribute(RepositoryConfig.REPOSITORY_CLASS_ATTRIB_NAME); if(this.repositoryClassName==null || "".equals(this.repositoryClassName)) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, RepositoryConfig.REPOSITORY_CLASS_ATTRIB_NAME + " attribute value cannot be null."); FrameworkUtil.loadPropertiesFromElementToMap(repositoryConfigElement, this.repositoryConfigProperties); logger.trace("Exiting RepositoryConfig Constructor"); } /** * Returns the repository class name responsible to work with the repository. * * @return Returns the repository class name. **/ public String getRepositoryClassName() { return this.repositoryClassName; } /** * Returns all the properties required by the repository class to interact with the repsoitory in a unmodifiable map. * * @return Returns the properties required by repository class in a map. */ public Map getRepositoryConfigProperties() { return Collections.unmodifiableMap(this.repositoryConfigProperties); } /** * <p> * Returns the string representation of RepositoryConfig class in the format * <br> {RepositoryConfig [repositoryClassName = value] [properties = value]} * </p> * * @return Returns the string representation of RepositoryConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{RepositoryConfig "); stringValue.append("[repositoryClassName = " + this.repositoryClassName + "]"); stringValue.append("[properties = " + this.repositoryConfigProperties + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * ControllerConfig holds the configuration related to the controller components. * It holds the information like factory specific config objects related to each * controller componenet and other information. * </p> * <p> * It represents the following XML block in itself and provides the methods to access * those values. * <br><br> * <pre> * <job-controller-config> * <job-controller controller-class-name="org.jmonks.batch.framework.controller.pool.PoolJobController" * xml-factory-config-class-name="org.jmonks.batch.framework.config.xml.XMLPoolJobController" * db-factory-config-class-name="org.jmonks.batch.framework.config.xml.DBPoolJobController"/> * </job-controller-config> * </pre> * </p> */ public class JobControllerConfig { /** * Tag name represents the controller config in framework configuration file * which is <code>job-controller-config</code>. */ private static final String TAG_NAME = "job-controller-config"; /** * Tag name defines the each controller which is <code>job-controller</code>. */ private static final String JOB_CONTROLLER_TAG_NAME = "job-controller"; /** * Attribute name defines the controller class name which is <code>controller-class-name</code>. */ private static final String JOB_CONTROLLER_CLASS_ATTRIB_NAME = "controller-class-name"; /** * Map holds the controller configuration details. controller class name will be used * as a key to identify the properties related to that particular controller. */ private Map controllerProperties=new HashMap(); private JobControllerConfig(Element controllerConfigElement) { logger.trace("Entering JobControllerConfig Constructor"); NodeList controllerNodeList=controllerConfigElement.getElementsByTagName(JobControllerConfig.JOB_CONTROLLER_TAG_NAME); for(int i=0;i<controllerNodeList.getLength();i++) { Element controllerElement=(Element)controllerNodeList.item(i); String controllerClassName=controllerElement.getAttribute(JobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIB_NAME); if(controllerClassName==null || "".equals(controllerClassName)) throw new ConfigurationException(ConfigurationException.FRAMEWORK_CONFIG, JobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIB_NAME + " attribute value cannot be null."); else { Map controllerPropertyMap=new HashMap(); this.controllerProperties.put(controllerClassName, controllerPropertyMap); NamedNodeMap controllerAttributes=controllerElement.getAttributes(); for(int j=0;j<controllerAttributes.getLength();j++) { Node controllerAttribute=controllerAttributes.item(j); String attribName=controllerAttribute.getNodeName(); /** * Skip the controller-class-name attribute here. */ if(!JobControllerConfig.JOB_CONTROLLER_CLASS_ATTRIB_NAME.equals(attribName)) { controllerPropertyMap.put(attribName,controllerAttribute.getNodeValue()); } } } } logger.trace("Exiting JobControllerConfig Constructor"); } /** * Gets the controller configuration class name from the controller config related * to the requested factory. * * @param controllerClassName Complete class name of the controller. * @param factoryIdentier Name of the factory identifier attribute. * * @return Returns the controller configuration class name of that particular factory, null, if it couldnt found. */ public String getConfigClassName(String controllerClassName,String factoryIdentifier) { Map controllerMap=(Map)this.controllerProperties.get(controllerClassName); return (String)controllerMap.get(factoryIdentifier); } /** * <p> * Returns the string representation of JobControllerConfig class in the format * <br> {JobControllerConfig [controllerProperties = value]} * </p> * * @return Returns the string representation of JobControllerConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobControllerConfig "); stringValue.append("[controllerProperties = " + this.controllerProperties + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * Returns the string representation of FrameworkConfig class in the format * <br> {FrameworkConfig [jobConfigFactoryConfig = value] [frameworkLoggingConfig = value] * [jobConnectorConfig = value] [repositoryConfig = value][controllerConfig = value]} * </p> * * @return Returns the string representation of FrameworkConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{FrameworkConfig "); stringValue.append("[jobConfigFactoryConfig = " + this.configFactoryConfig + "]"); stringValue.append("[frameworkLoggingConfig = " + this.frameworkLoggingConfig + "]"); stringValue.append("[mgmtMntrConfig = " + this.jobConnectorConfig + "]"); stringValue.append("[repositoryConfig = " + this.repositoryConfig + "]"); stringValue.append("[controllerConfig = " + this.controllerConfig + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: JobConfigFactory.java --- /* * JobConfigFactory.java * * Created on March 2, 2006, 11:35 AM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.Map; import org.apache.log4j.Logger; /** * <p> * JobConfigFactory returns the factory class instance which in turn returns the job configuration * objects from the designated factory. This class determines the factory needs to * be returned is based on the configFactoryClassName defined JobConfigFactoryConfig * object passed as input parameter. * </p> * <p> * This will get the following XML block from framework configuration as JobConfigFactoryConfig * object. * <br><br> * <pre> * <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.framework.config.xml.XMLJobConfigFactory"> * <property key="job-config-file-absolute-location">/batchserver/config/batch-config.xml</property> * </job-config-factory-config> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobConfigFactory { private static Logger logger=Logger.getLogger(JobConfigFactory.class); /** * This factory method will return the appropriate job configuration factory based * on the input values in JobConfigFactoryConfig object. This looks for the factory class * name in the given object, instantiates and return that factory. * * @param factoryConfig Job configuration factory config object contains the details need to * create the factory. * * @return Returns the approproated JobConfigFactory object. * * @throws ConfigurationException If defined factory class is not a valid Job config factory and if any * required properties are missing for the factory. * @throws IllegalArgumentException If input factory configuration is null. */ public static JobConfigFactory getJobConfigFactory(FrameworkConfig.JobConfigFactoryConfig factoryConfig) { logger.trace("Entering getJobConfigFactory"); JobConfigFactory factoryObject=null; if(factoryConfig==null) throw new IllegalArgumentException("Input job config factory configuration cannot be null."); String factoryClassName=factoryConfig.getJobConfigFactoryClassName(); try { Class factoryClass=Class.forName(factoryClassName); if(JobConfigFactory.class.isAssignableFrom(factoryClass)) { factoryObject=(JobConfigFactory)factoryClass.newInstance(); factoryObject.init(factoryConfig.getJobConfigFactoryProperties()); } else throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, factoryClass + " is not assignable to the class " + JobConfigFactory.class.getName()); logger.debug("Job Configuration factory has been created."); } catch(ClassNotFoundException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, exception.getMessage()); } catch(InstantiationException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, exception.getMessage()); } catch(IllegalAccessException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); throw new ConfigurationException(ConfigurationException.JOB_CONFIG_FACTORY_CONFIG, exception.getMessage()); } logger.trace("Exiting getJobConfigFactory"); return factoryObject; } /** * Returns the requested JobConfig object from the defined factory. If requested * job configuration is not found in that factory, it returns null. * * @param jobName Name of the job whose configuration is needed. * * @return Returns the requested Job Configuration object if found, null otherwise. */ public abstract JobConfig getJobConfig(String jobName); /** * Method to initialize the factory using properies defined for this factory * in framework configuration file. All the properties defined for this * configuration factory will be passed as map to this method as soon as the * factory is instantiated. * * @param configFactoryProps Map consists of all the properties defined for this factory. * * @throws ConfigurationException If required properties by the factory are missing. */ protected abstract void init(Map configFactoryProps); } --- NEW FILE: JobControllerConfig.java --- /* * JobControllerConfig.java * * Created on March 2, 2006, 12:12 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.log4j.Logger; /** * <p> * JobControllerConfig represents the configuration needed for the Controller componenet. * There could be different implementations of the controller componenet available. Each controller * componenet can have different configurations. So, this class provides the basic features * required by all the controllers. Each controller will have specific controller config which * extends this base interface and provide the extra features required by that specific * controller implementation. * </p> * <p> * By specifying the controller class name, job defines the controller that it wants to use. * Each controller will take some additional parameters for their opertations. So * every controller will have the class name and properties. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobControllerConfig { /** * Class name that defines the kind of controller job wants to use. */ protected String jobControllerClassName=null; /** * Map holds the required properties support the specified controller. */ protected Map jobControllerConfigProps=new HashMap(); private static Logger logger=Logger.getLogger(JobControllerConfig.class); /** * Gets the job controller class name. * * @return Returns the controller class name. */ public String getJobControllerClasName() { return this.jobControllerClassName; } /** * Gets the unmodifiable map contains the properties required by the controller. * * @return Returns the properites in a map. */ public Map getJobControllerConfigProperties() { return Collections.unmodifiableMap(this.jobControllerConfigProps); } } --- NEW FILE: JobLoggingConfig.java --- /* * JobLoggingConfig.java * * Created on March 13, 2006, 7:01 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.ArrayList; import java.util.List; /** * <p> * JobLoggingConfig holds the list of loggers defined for this job. Each logger * will be represented by the JobLoggerConfig object. Implementation of this class * will be done by the classes defined in corresponding factories. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobLoggingConfig { /** * Holds the list of JobLoggerConfig objects. */ private List loggerList=new ArrayList(); /** * Gets the array of JobLoggerConfig objects defined for this job. * */ public JobLoggerConfig[] getLoggers() { JobLoggerConfig[] returnConfigs=new JobLoggerConfig[this.loggerList.size()]; return (JobLoggerConfig[])this.loggerList.toArray(returnConfigs); } protected void addLogger(String loggerName,String loggerLevel) { JobLoggerConfig loggerConfig=new JobLoggerConfig(loggerName,loggerLevel); this.loggerList.add(loggerConfig); } /** * JobLoggerConfig holds the information of each logger defined for the job. */ public class JobLoggerConfig { /** * Holds the logger name. */ private String loggerName=null; /** * Holds the logger level. */ private String loggerLevel=null; /** * Private constructor make sure only this class can create the instances of * JobLoggerConfig. Sub classes should use addLogger method JobLoggingConfig * to add the logger configuration. * * @param loggerName Logger name. * @param loggerLevel Logger level. */ private JobLoggerConfig(String loggerName,String loggerLevel) { this.loggerName=loggerName; this.loggerLevel=loggerLevel; } /** * Returns the logger name. */ public String getLoggerName() { return this.loggerName; } /** * Returns the logger level. */ public String getLoggerLevel() { return this.loggerLevel; } /** * <p> * Returns the string representation of JobLoggerConfig class in the format * <br> {JobLoggerConfig [loggerName = value] [loggerLevel = value]} * </p> * * @return Returns the string representation of JobLoggerConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobLoggerConfig "); stringValue.append("[loggerName = " + this.loggerName + "]"); stringValue.append("[loggerLevel = " + this.loggerLevel + "]"); stringValue.append("}"); return stringValue.toString(); } } /** * <p> * Returns the string representation of JobLoggingConfig class in the format * <br> {JobLoggingConfig [loggerList = value]} * </p> * * @return Returns the string representation of JobLoggingConfig. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobLoggingConfig "); stringValue.append("[loggerList = " + this.loggerList + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: PoolJobControllerConfig.java --- /* * PoolJobControllerConfig.java * * Created on March 2, 2006, 1:24 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework.config; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; /** * <p> * PoolJobControllerConfig represents the controller congiguration needed by * PoolJobController. * </p> * * <p> * PoolJobController holds the class names of the JobPool, PoolJobLoader & * PoolJobProcessor and configuration required by those classes processor. * </p> * * @author Suresh Pragada * @since 1.0 * @version 1.0 */ public abstract class PoolJobControllerConfig extends JobControllerConfig { /** * Pool job loader class name. */ protected String poolJobLoaderClassName=null; /** * Map contains the properties needed by pool job loader. */ protected Map poolJobLoaderConfigProps=new HashMap(); /** * Pool job processor class name. */ protected String poolJobProcessorClassName=null; /** * Map contains the properties needed by pool job processor. */ protected Map poolJobProcessorConfigProps=new HashMap(); /** * Holds the number of instances to be created. */ protected int poolJobProcessorThreadCount=1; /** * Pool class name. */ protected String poolClassName=null; private static Logger logger=Logger.getLogger(PoolJobControllerConfig.class); /** * Map contains the properties needed by pool class. */ protected Map poolConfigProps=new HashMap(); /** * Gets the pool job loader class name. * * @return Returns the pool job loader class name. */ public String getPoolJobLoaderClassName() { return this.poolJobLoaderClassName; } /** * Gets the unmodifiable map contains the properties needed by pool job loader. * * @return Returns the map contains the properties. */ public Map getPoolJobLoaderConfigProperties() { return Collections.unmodifiableMap(this.poolJobLoaderConfigProps); } /** * Gets the pool job processor class name. * * @return Returns the pool job processor class name. */ public String getPoolJobProcessorClassName() { return this.poolJobProcessorClassName; } /** * Gets the unmodifiable map contains the properties needed by pool job processor. * * @return Returns the map contains properties. */ public Map getPoolJobProcessorConfigProperties() { return Collections.unmodifiableMap(this.poolJobProcessorConfigProps); } /** * Gets the pool class name. * * @return Retruns the pool class name. */ public String getPoolClassName() { return this.poolClassName; } /** * Gets the unmodifiable map contains properties needed by the pool class. * * @return Returns the map contains properties. */ public Map getPoolConfigProperties() { ret... [truncated message content] |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19484 Added Files: ErrorCode.java JobContext.java JobStatistics.java LoggingManager.java Main.java Repository.java Log Message: no message --- NEW FILE: JobContext.java --- /* * JobContext.java * * Created on September 13, 2006, 1:18 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batch.framework; import java.util.Collections; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobConfig; /** * <p> * JobContext provides the references to the framework resources. * All the jobs will receives the JobContext reference either in their * initialize methods or process methods based on the controllers they choose to * implement the job. It exposes the resources like reference to repository (by * using which you can transfer the data between the jobs, saves the management & * monitoring information and job running statistics), running job configuration * (by using which you can refer the properties defined in the controller/processor * configuration), configuration provided to invoke the job (could be either command * line configuration or configuration provided to process method) and finally * framework configuration. All the configuration maps accessed through this job * context are unmodifiable. Framework creates the JobContext instance and passes * it to the controllers. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class JobContext { /** * Constant defines the parameter name to be used in the context parameters * map to pass the job configuration to create the job context. */ public static final String CONTEXT_PARAM_JOB_CONFIG="batch.framework.job.context.job.config"; /** * Constant defines the parameter name to be used in the context parameters * map to pass the job invoke configuration to create the job context. */ public static final String CONTEXT_PARAM_JOB_INVOKE_CONFIG="batch.framework.job.context.job.invoke.config"; /** * Constant defines the parameter name to be used in the context parameters * map to pass the repository instance to create the job context. */ public static final String CONTEXT_PARAM_REPOSITORY="batch.framework.job.context.repository"; /** * Holds the job configuration object reference. */ protected JobConfig jobConfig=null; /** * Holds the framework repository reference. */ protected Repository repository=null; /** * Holds the job invoke configuration reference. */ protected Map jobInvokeConfig=null; private static Logger logger=Logger.getLogger(JobContext.class); /** * <p> * Creates and Initializes the JobContext object by looking up the information * in the given context parameters map. It looks for all the required parameters * and then initializes the complete job context. It accepts the Main class * instance context creator reference to make sure this will not be created * by other than Main class. * </p> * * @param contextParams Map contains all the required information to initialize the job context. * @param contextCreator Main class instance to make sure nobody can instantiate the job context. * * @throws SecurityException If context creator is other than Main class. * @throws IllegalArgumentException If any of the required parameters are missing in the context params. * */ public JobContext(Map contextParams, Main contextCreator) { logger.trace("Entering JobContext init. params= " + contextParams + " creator = " + contextCreator); if(!(contextCreator instanceof Main)) throw new SecurityException("Not authorized to create the job context."); if(contextParams==null) throw new IllegalArgumentException("Context params to initialize the context cannot be null."); /** * Retrieve and add the invoke configuration map to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_JOB_INVOKE_CONFIG)) { Object objectInvokeConfig=contextParams.get(JobContext.CONTEXT_PARAM_JOB_INVOKE_CONFIG); if(objectInvokeConfig instanceof Map) this.jobInvokeConfig=(Map)objectInvokeConfig; else throw new IllegalArgumentException("Provided job invoke configuration object to initalize job context is not valid."); } else throw new IllegalArgumentException("Missing the required job invoke configuration map object in context params."); logger.debug("Added the invoke configuration to JobContext"); /** * Retrieve and add the job config instance to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_JOB_CONFIG)) { Object objectJobConfig=contextParams.get(JobContext.CONTEXT_PARAM_JOB_CONFIG); if(objectJobConfig instanceof JobConfig) this.jobConfig=(JobConfig)objectJobConfig; else throw new IllegalArgumentException("Provided job config object to initailize the job context is not valid."); } else throw new IllegalArgumentException("Missing the required job configuration object in context params."); logger.debug("Added the job config reference to JobContext"); /** * Retrieve and add the repository instance to the context. */ if(contextParams.containsKey(JobContext.CONTEXT_PARAM_REPOSITORY)) { Object objectRepository=contextParams.get(JobContext.CONTEXT_PARAM_REPOSITORY); if(objectRepository instanceof Repository) this.repository=(Repository)objectRepository; else throw new IllegalArgumentException("Provided repository object to initailize the job context is not valid."); } else throw new IllegalArgumentException("Missing the required repository object in context params."); logger.debug("Added the repository reference to JobContext"); logger.trace("Exiting JobContext init"); } /** * Gets the name of the job this context is associated with. * * @return Returns the name of the job. */ public String getJobName() { return this.jobConfig.getJobName(); } /** * Gets the repository reference configured for this framework. * * @return Gets the repository reference. */ public Repository getRepository() { return this.repository; } /** * Gets the job configuration object belongs to the running job. * * @return Returns the running job's configuration object. */ public JobConfig getJobConfig() { return this.jobConfig; } /** * Gets the configuration passed in the invocation to the framework. This * could be command line parameters, if job is invoked from command line or * config map if job is invoked through Main.process method. * * @return Returns the configuration provided at the invocation time. */ public Map getJobInvokeConfig() { return Collections.unmodifiableMap(this.jobInvokeConfig); } /** * Gets the reference to the framework configuration. * * @return Gets the framework configuration reference. */ public FrameworkConfig getFrameworkConfig() { return FrameworkConfig.getInstance(); } } --- NEW FILE: JobStatistics.java --- package org.jmonks.batch.framework; import java.util.Date; /** * <p> * JobStatistics holds the useful metrics and information of particular run of a job. * These statistics helpful in research of the periodic growth of the jobs. * Statistics it holds are start and end time of the run, records have been processed * in the run, memory has been utilized in the run and exit code of that run. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ 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 long recordsProcessed; /** * Maximum memory consumption in bytes. */ private long maxMemoryUsage; /** * Name of the job. */ private String jobName; /** * Exit code of the job. */ private ErrorCode exitCode=null; /** * Constructor takes the job name and build the skelton. */ public JobStatistics(String jobName) { this.jobName=jobName; this.startTime=null; this.endTime=null; this.maxMemoryUsage=0; this.recordsProcessed=0; this.exitCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; } /** * Sets the startime of the job. * * @param startTime Starting time of the job. */ public void setStartTime(Date startTime) { this.startTime=startTime; } /** * Sets the endtime of the job. * * @param endTime Ending time of the job. */ public void setEndTime(Date endTime) { this.endTime = endTime; } /** * Sets the number of the records processed in this job. * * @param recordCount Sets the number of records got processed. */ public void setRecordsProcessed(long recordCount) { this.recordsProcessed = recordCount; } /** * Sets the maximum memory used for the job in bytes. * * @param memoryUsaeg Sets the memory usage by the job. */ public void setMaxMemeoryUsage(long memoryUsage) { this.maxMemoryUsage=memoryUsage; } /** * Gets the start time of this job. * * @return Returns the starting time of this job. */ public Date getStartTime() { return this.startTime; } /** * Gets the ending time of this job. * * @return Gets the end time of this job. */ public Date getEndTime() { return this.endTime; } /** * Gets the number of records processed. * * @return Returns the number of records got processed. */ public long getRecordsProcessed() { return this.recordsProcessed; } /** * Gets the maximum memory used by this job in bytes. * * @return Returns the max memory used by this job. */ public long getMaxMemoryUsage() { return this.maxMemoryUsage; } /** * Gets the job name * * @return Returns the name of this job. */ public String getJobname() { return this.jobName; } /** * Sets the given error code as exit code. * * @param exitCode Error code controller is going to return to the framework. */ public void setExitCode(ErrorCode exitCode) { this.exitCode=exitCode; } /** * Gets the exit code. */ public ErrorCode getExitCode() { return this.exitCode; } /** * <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("[exitCode = " + this.exitCode.toString() + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: LoggingManager.java --- package org.jmonks.batch.framework; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import org.apache.log4j.Level; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.RollingFileAppender; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.FrameworkConfig.FrameworkLoggingConfig; import org.jmonks.batch.framework.config.JobLoggingConfig; /** * <p> * Logging Manager provides the logging services to the framework. * It defines the default logging mechanism at the framework level * which works for all the jobs and provide the facility to * use their own logging mechanism. * </p> * <p> * The default logging mechanism defined at the framework will * work like this. It reads the directory to create the log files from * the framework logging configuration <logging-config> and creates a directory * with the "job-name" and create the log files for each run. So, the format * will be * <br><br> * <directory-defined-in-config>/job-name/jobname_with_timestamp.log * <br><br> * </p> * <p> * If job developer would like to override this logging mechanism, they can * define their logging configuration in the element <job-logging-config> in * batch job configuration file or defining entries in job_logging_config table. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class LoggingManager { /** * Framework configuration file which is batch_framework.log. */ public static final String FRAMEWORK_LOGGING_FILE = "batch_framework.log"; /** * Standard pattern expression used for all the log files. */ public static final String DEFAULT_MESSAGE_PATTERN = "%5p [%d{ISO8601}] [%t - %C] %m%n"; /** * Tells whether framework logging has been already initailized or not. */ private static boolean isFrameworkLoggingInitialized=false; /** * Private constructor to make sure LoggingManager will not be instantiated. */ private LoggingManager() { } /** * <p> * This method accepts all the information available from framwork logging configuration * and job logging configuration and loads the required loggers appropriately. * This does the follwing steps. * <ul> * <li>Create the directory <directory name configured in logging config>/jobName * <li>Generates the logging file name jobName_yyyymmdd_hhmmss_ms.log * <li>Creates the Rolling File appender with the above created directory and logging file name. * <li>Remove all the existing appenders from the root logger. * <li>Attaches the above created appender to the root logger and set the log level to the defined in framework configuration. * <li>Access the defined loggers at job level and set the level for those loggers. * </ul> * * @param jobName Name of the job. * @param frameworkLoggingConfig Logging configuration defined at the framework. * @param jobLoggingFramework Logging configuration defined at the job level. * @param loggingInitalizer Main class instance which is authorized to initailze the job logging. * * @throws SecurityException If any class other than Main(framework) tried to initialize the job logging. * @throws ConfigurationException If logging file cannot be created at the configured directory. * </p> */ public static void initializeJobLogging(String jobName, FrameworkLoggingConfig frameworkLoggingConfig,JobLoggingConfig jobLoggingConfig, Main loggingInitalizer) { if(!(loggingInitalizer instanceof Main)) throw new SecurityException("Not authorized to initialize the job logging."); File loggingDirecotry=new File(frameworkLoggingConfig.getJobLoggingDirecotry()+File.separator+jobName); LoggingManager.createDirectory(loggingDirecotry); String completeFileName=loggingDirecotry.getAbsolutePath()+File.separator+ jobName+"_"+new SimpleDateFormat("yyyyMMdd_HHmmss_S").format(Calendar.getInstance().getTime())+".log"; PatternLayout layout=new PatternLayout(LoggingManager.DEFAULT_MESSAGE_PATTERN); RollingFileAppender fileAppender=null; try { fileAppender=new RollingFileAppender(layout,completeFileName); } catch(IOException exception) { exception.printStackTrace(); throw new ConfigurationException(ConfigurationException.LOGGING_CONFIG, exception.getMessage()); } fileAppender.setMaxFileSize("10MB"); fileAppender.activateOptions(); Logger rootLogger=LogManager.getRootLogger(); rootLogger.removeAllAppenders(); rootLogger.addAppender(fileAppender); rootLogger.setLevel(Level.toLevel(frameworkLoggingConfig.getJobLoggingLevel())); if(jobLoggingConfig!=null) { JobLoggingConfig.JobLoggerConfig jobLoggerConfigs[]=jobLoggingConfig.getLoggers(); for(int i=0;i<jobLoggerConfigs.length;i++) { Logger customLogger=Logger.getLogger(jobLoggerConfigs[i].getLoggerName()); if(customLogger!=null) customLogger.setLevel(Level.toLevel(jobLoggerConfigs[i].getLoggerLevel())); } } } /** * Initializes the logging of the framework in the directory defined in framework configuration. * After initialized the job logging framework logging will be send to the job and framwork * log files. * * @param frameworkLoggingConfig Framework logging configuration object. * @param loggingInitalizer Main class instance which is authorized to initailze the logging. * * @throws SecurityException If any class other than Main(framework) tried to initialize the framework logging. * @throws ConfigurationException If logging directory cannot be created. */ public static synchronized void initializeFrameworkLogging(FrameworkLoggingConfig frameworkLoggingConfig, Main loggingInitalizer) { if(!(loggingInitalizer instanceof Main)) throw new SecurityException("Not authorized to initialize the framework logging."); if(!isFrameworkLoggingInitialized) { File loggingDirecotry=new File(frameworkLoggingConfig.getJobLoggingDirecotry()); LoggingManager.createDirectory(loggingDirecotry); String completeFileName=loggingDirecotry.getAbsolutePath()+File.separator+LoggingManager.FRAMEWORK_LOGGING_FILE; PatternLayout layout=new PatternLayout(LoggingManager.DEFAULT_MESSAGE_PATTERN); RollingFileAppender fileAppender=null; try { fileAppender=new RollingFileAppender(layout,completeFileName,true); } catch(IOException exception) { exception.printStackTrace(); throw new ConfigurationException(ConfigurationException.LOGGING_CONFIG, exception.getMessage()); } fileAppender.setMaxFileSize("10MB"); fileAppender.activateOptions(); Logger rootLogger=LogManager.getRootLogger(); rootLogger.removeAllAppenders(); Logger frameworkLogger=Logger.getLogger("org.jmonks.batch.framework"); frameworkLogger.addAppender(fileAppender); frameworkLogger.setAdditivity(true); frameworkLogger.setLevel(Level.toLevel(frameworkLoggingConfig.getFrameworkLoggingLevel())); isFrameworkLoggingInitialized=true; } else { /** * Framework logging has been already initialized. Ignore this call. */ } } /** * Method to make sure given file entry exist. If it doenst exist, it will tries to create that * entry. */ private static void createDirectory(File loggingDirecotry) { if(loggingDirecotry.exists() && loggingDirecotry.isFile()) throw new ConfigurationException(ConfigurationException.LOGGING_CONFIG, "Logging directory " + loggingDirecotry.getAbsolutePath() + " defined in framework configuration is a file."); else if(!loggingDirecotry.exists()) { boolean created=loggingDirecotry.mkdirs(); if(!created) throw new ConfigurationException(ConfigurationException.LOGGING_CONFIG, "Logging directory " + loggingDirecotry.getAbsolutePath() + " defined in framework configuration cannot be created."); } } /** * 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 static Level getLogLevel(String loggerName) { Logger logger=Logger.getLogger(loggerName); if(logger==null) return null; else return logger.getLevel(); } /** * 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 static boolean changeLogLevel(String loggerName,Level newLogLevel) { boolean logLevelChanged=false; Logger logger=Logger.getLogger(loggerName); if(logger!=null) { logger.setLevel(newLogLevel); logLevelChanged=true; } return logLevelChanged; } } --- NEW FILE: Repository.java --- 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); /** * Variable to hold the singleton instance of repository implementation * defined in framework configuration. */ private static Repository repository=null; /** * 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 is restrict only framework can instantiate the repository. * * @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); 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); } --- NEW FILE: Main.java --- package org.jmonks.batch.framework; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.ConfigurationException; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobConfig; import org.jmonks.batch.framework.config.JobConfigFactory; import org.jmonks.batch.framework.controller.JobController; import org.jmonks.batch.framework.management.JobManagementAgent; /** * <p> * Main is the entry point to the batch framework. This provides * the methods to accept the information to identify the job and kicks off the job. * The framework can be executed either through command line as an independent * program or from any other java program. The information on how to kickoff using * these two methods available in {@link #main(String[])} and {@link #process(java.util.Map)} * methods of this class. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public final class Main { private static Logger logger=Logger.getLogger(Main.class); /** * Name of the parameter key holds the job name in configuration map which * is <code>job-name</code>. */ public static final String JOB_NAME_KEY_NAME = "job-name"; /** * Restrict the temptation of creating the instance of Main to create * any resources in the framework. */ private Main() { } /** * <p> * This method provides the interface to execute the job from another java * program. This accepts the job name and additional configuration information * relate to this job as a key value pairs in the map. Among these entries * in the map, there should be a <i>job-name</i> parameter key available to * identify the job to be executed. * <br><br> * <pre> * Map configMap=new HashMap(); * configMap.put("job-name","process_file_abc"); * configMap.put("config-name1","config-value1"); * configMap.put("config-name2","config-value2"); * * ErrorCode exitCode=Main.process(configMap); * System.out.println("Job exited with return code : " + exitCode.getCode()); * </pre> * <br><br> * Whatever the configuration passed here can be retrived from the JobContext * instance passed to all the jobs either through initialize methods or process * methods. * </p> * <br> * * @param configMap Map object consist of all the properties needed to kick off this batch job. * * @return Returns ErrorCode provides the status of the batch job. * * @throws IllegalArgumentException If input configMap is null. */ public static ErrorCode process(Map configMap) { if(configMap==null) throw new IllegalArgumentException("Argument configMap cannot be null."); ErrorCode returnCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; JobManagementAgent jobManagementAgent=null; JobContext jobContext=null; Main frameworkCreator=new Main(); String jobName=null; try { /** * Get the framework configuration and initialize the framework logging. */ logger.debug("Retrieving the framework configuration"); FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); LoggingManager.initializeFrameworkLogging( frameworkConfig.getFrameworkLoggingConfig(), frameworkCreator); /** * Get the job name from given configMap and start execution. */ logger.error("Received configuration map = " + configMap); jobName=(String)configMap.get(Main.JOB_NAME_KEY_NAME); logger.info("Job to be invoked = " + jobName); if(jobName!=null && !"".equals(jobName.trim())) { /** * Get the job configuration from the configuration factory. */ logger.debug("Retrieving the configuration factory"); JobConfigFactory jobConfigFactory=JobConfigFactory. getJobConfigFactory(frameworkConfig.getJobConfigFactoryConfig()); logger.debug("Retrieving the job configuration"); JobConfig jobConfig=jobConfigFactory.getJobConfig(jobName); if(jobConfig!=null) { /** * Initialize the job logging and kick off the controller after * registering it to the management agent. */ logger.debug("Initializing the job logging"); LoggingManager.initializeJobLogging(jobName,frameworkConfig. getFrameworkLoggingConfig(), jobConfig.getJobLoggingConfig(), frameworkCreator); logger.debug("Create the job context"); jobContext=createJobContext(jobConfig, configMap, frameworkCreator); logger.debug("Creating the job controller"); JobController jobController=JobController.getJobController(jobContext); logger.debug("Retrieving the management agent"); jobManagementAgent=JobManagementAgent.getJobManagementAgent(); logger.debug("Registering the controller with the management agent"); jobManagementAgent.start(jobContext, jobController, frameworkCreator); logger.error("Kicking off the controller"); returnCode=jobController.process(); /** * Save the statistics into repository */ JobStatistics jobStatistics=jobController.getJobStatistics(); logger.error(jobStatistics); jobContext.getRepository().logStatistics(jobStatistics); } else { logger.fatal("Unable to find the job configuration for the given job = " + jobName + " in the configured job configuration factory = " + jobConfigFactory.toString()); returnCode=ErrorCode.JOB_IS_NOT_CONFIGURED; } } else { logger.fatal("job-name parameter cannot be found in the configuration to kick " + "off the job . Received configuration = " + configMap); returnCode=ErrorCode.JOB_INVOKATION_CONFIGURAION_ERROR; } } catch(ConfigurationException exception) { exception.printStackTrace(); logger.fatal("Configuration Exception in the component " + exception.getExceptionComponent() + " while processing the job = " + jobName + " Message = " + exception.getMessage(),exception); returnCode=exception.getErrorCode(); } catch(Throwable exception) { exception.printStackTrace(); logger.fatal("Exception while processing the job = " + jobName + " Message = "+ exception.getMessage(),exception); returnCode=ErrorCode.JOB_COMPLETED_WITH_ERRORS.appendMessage(exception.getMessage()); } finally { logger.debug("Unregistering the controller with the management agent"); if(jobManagementAgent!=null && jobManagementAgent.isRunning()) jobManagementAgent.stop(jobContext, returnCode, frameworkCreator); } logger.error("Exiting process = " + returnCode); return returnCode; } /** * <p> * This method provides the interface to execute the jobs from command line. * This accepts the job name and additional configuration information related * to this job as a command line parameters. Each parameter passed through * command line should be in the format <i>name=value</i>. Among these, * <i>job-name=process_file_abc</i> property should exist to identify the job * to kick off. The ErrorCode's code value will be returned as exit code. * </p> * <p> * The format to invoke the job using this interface is as follows. <br> * java org.jmonks.batch.framework.Main job-name=process_file_abc config-name1=config-value1 config-name2=config-value2 * <br><br> * Whatever the configuration paremters passed here can be retrieved using * the JobContext reference passed to all the jobs either using their initialize * methods or process methods. * </p> * * @param args Configuration details in command line params as name=value format */ public static void main(String args[]) { ErrorCode exitCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; Main frameworkCreator=new Main(); try { /** * Get the framework configuration and initialize the framework logging. */ logger.debug("Retrieving the framework configuration"); FrameworkConfig frameworkConfig=FrameworkConfig.getInstance(); logger.debug("Initializing the framework logging"); LoggingManager.initializeFrameworkLogging(frameworkConfig. getFrameworkLoggingConfig(), frameworkCreator); /** * Translate the command line parameters into the configuration map. */ logger.info("Job processing has been started"); Map configMap=new HashMap(); for(int i=0;i<args.length;i++) { int index=args[i].indexOf("="); if(index>1) { configMap.put(args[i].substring(0, index), args[i].substring(index+1)); logger.info("Loaded the argument = " + args[i] + " into configuration map."); } else logger.info("Not loading the argument = " + args[i] + " into configuration map. " + "It is not following the name=value format."); } /** * Kick off the process by passing configuration map. */ exitCode=Main.process(configMap); } catch(ConfigurationException exception) { exception.printStackTrace(); logger.fatal("Configuration Exception in the component " + exception.getExceptionComponent() + " while processing the job. Message = " + exception.getMessage(),exception); exitCode=exception.getErrorCode(); } catch(Throwable exception) { exception.printStackTrace(); logger.fatal("Exception while processing the job. Message = "+ exception.getMessage(),exception); exitCode=ErrorCode.JOB_COMPLETED_WITH_ERRORS.appendMessage(exception.getMessage()); } logger.error("Job finishing with the exit code = " + exitCode.toString()); System.exit(exitCode.getCode()); } /** * Creates the map to be passed to create the JobContext and passes it to the * JobContext and returns the created JobContext object. * * @param jobConfig Job configuration object. * @param invokeConfig Configuration provided at invocation time. * @param frameworkCreator Authorized class to the create the job context. * * @return Returns the JobContext reference. */ private static JobContext createJobContext(JobConfig jobConfig, Map invokeConfig, Main frameworkCreator) { /** * Create the context params map to create the JobContext instance. */ Map contextParams=new HashMap(); contextParams.put(JobContext.CONTEXT_PARAM_JOB_CONFIG, jobConfig); contextParams.put(JobContext.CONTEXT_PARAM_JOB_INVOKE_CONFIG, invokeConfig); Repository repository=Repository.createRepository(jobConfig.getJobName(), FrameworkConfig.getInstance().getRepositoryConfig(), frameworkCreator); contextParams.put(JobContext.CONTEXT_PARAM_REPOSITORY, repository); /** * Create the JobContext and return it. */ JobContext jobContext=new JobContext(contextParams, frameworkCreator); return jobContext; } } --- NEW FILE: ErrorCode.java --- package org.jmonks.batch.framework; /** * <p> * The ErrorCode represents the error condition that can generate in the system. * It consists of the code which uniquely identifies the ErrorCode and message * which explains the error in the system. This is also used to represent the status code * for any processor/controller/job. This provides the flexibility to create * new custom ErrorCodes and append the message to the existing ErrorCode. * Codes ranging from 0 to 100 are reserved for framework purposes. Use the codes * above 100 to create the custom error codes. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public final class ErrorCode { /** * Code represents the error. */ private int code; /** * Message illustrates the code. */ private String message=null; /** * <p> * Private constructor to make sure no instances of ErrorCode will be created * from outside of this class and it is not extensible. * </p> * * @param code Code represents the error. * @param errorMsg Message explains the failure or success reason. */ private ErrorCode(int code, String errorMsg) { this.code=code; this.message=errorMsg; } /** * Returns the error code represents the error. * * @return Returns the error code represents the error. */ public int getCode() { return this.code; } /** * Returns the error message illustrates the exit code. * * @return Returns the error message. */ public String getMessage() { return this.message; } /** * Creates a new ErrorCode object with the same error code and appends the given * message to the existing message and returns new ErrorCode. * * @param messageToBeAppended Message that needs to be appended to the existing message. * * @return Returns a new error code contains the same error code and appended message. */ public ErrorCode appendMessage(String messageToBeAppended) { return new ErrorCode(this.code, this.message+" " + messageToBeAppended); } /** * Creates a new error code instance by accepting the code and message. The newMessage * should not be null or empty message. * * @param newCode Code to be used to construct the ErrorCode. * @param newMessage Mesage to be used to construct the ErrorCode. * * @throws java.lang.IllegalArgumentException If given message is null or empty. */ public static ErrorCode createErrorCode(int newCode, String newMessage) { if(newMessage!=null && !"".equals(newMessage.trim())) return new ErrorCode(newCode,newMessage); else throw new IllegalArgumentException("Message to create new ErrorCode should not be null or empty."); } /** * Equality will be based on the code the two ErrorCodes contains. * * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object errorCode) { return (errorCode!=null) && (this.getClass()==errorCode.getClass()) && (this.code==((ErrorCode)errorCode).getCode()); } /** * Code represented by ErrorCode will be returned as a hash code. * * @see java.lang.Object#hashCode() */ public int hashCode() { return this.code; } /** * <p> * Returns the string representation of ErrorCode class in the format * <br> {ErrorCode [code = value] [message = value]} * </p> * * @return Returns the string representation of ErrorCode. */ public String toString() { StringBuffer stringValue=new StringBuffer("{ErrorCode "); stringValue.append("[code = " + this.code + "]"); stringValue.append("[message = " + this.message + "]"); stringValue.append("}"); return stringValue.toString(); } /** * Represents job got completed successfully. Error code is 0. */ public static final ErrorCode JOB_COMPLETED_SUCCESSFULLY = new ErrorCode(0,"Job completed successfully."); /** * Represents job got completed with errors. This represents the partial success. Error code is 1. */ public static final ErrorCode JOB_COMPLETED_WITH_ERRORS = new ErrorCode(1, "Job completed with some errors."); /** * Represents the configuration error used to invoke the job. Error code is 10. */ public static final ErrorCode JOB_INVOKATION_CONFIGURAION_ERROR = new ErrorCode(10,"Error in configuraion passed to invoke job."); /** * Represents the framework configuration error. Error code is 11. */ public static final ErrorCode FRAMEWORK_CONFIGURATION_ERROR = new ErrorCode(11,"Error while accessing or parsing the framework configuration file."); /** * Represents the job config factory configuration error. Error code is 12. */ public static final ErrorCode JOB_CONFIG_FACTORY_CONFIGURATION_ERROR = new ErrorCode(12,"Job configuration factory cannot be created by the given factory configuration."); /** * Represents the job configuration error. Error code is 13. */ public static final ErrorCode JOB_CONFIGURATION_ERROR = new ErrorCode(13,"Error while loading the job configuration from the defined factory."); /** * Represents the job is not configured error. Error code is 14. */ public static final ErrorCode JOB_IS_NOT_CONFIGURED = new ErrorCode(14,"Job is not configured"); /** * Represents the job controller configuration error. Error code is 15. */ public static final ErrorCode JOB_CONTROLLER_CONFIGURATION_ERROR = new ErrorCode(15,"Job controller configuration is not defined properly."); /** * Represents the logging configuration error. Error code is 16. */ public static final ErrorCode JOB_LOGGING_CONFIGURATION_ERROR = new ErrorCode(16,"Job logging configuration is not defined properly."); /** * Represents the repository configuration error. Error code is 17. */ public static final ErrorCode JOB_REPOSITORY_CONFIGURATION_ERROR = new ErrorCode(17,"Repository configuration in framework configuration is not defined properly."); /** * Represents the connector configuration error. Error code is 18. */ public static final ErrorCode JOB_CONNECTOR_CONFIGURATION_ERROR = new ErrorCode(18,"Repository configuration in framework configuration is not defined properly."); /** * Represents the unknown configuration error. Error code is 19. */ public static final ErrorCode UNKNOWN_CONFIGURATION_ERROR = new ErrorCode(19,"Configuration error related to unknown component."); /** * Represents error because of the exception in basic job processor. Error code is 20. */ public static final ErrorCode BASIC_JOB_PROCESSOR_EXCEPTION = new ErrorCode(20,"Basic Job Controller caught exception while executing process method on basic job processor."); /** * Represents error because of the exception in pool job loader. Error code is 21. */ public static final ErrorCode POOL_JOB_LOADER_EXCEPTION = new ErrorCode(21,"Exception while executing the loader to load the pool."); /** * Represents error because of the exception in pool job processor. Error code is 22. */ public static final ErrorCode POOL_JOB_PROCESSOR_EXCEPTION = new ErrorCode(22,"Exception while executing the processor to process the pool."); } |
From: Suresh <sur...@us...> - 2006-09-15 20:01:53
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17853/xml Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io/xml added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 20:01:45
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17842/flat Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io/flat added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 20:01:06
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/jdbc In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17468/jdbc Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/jdbc added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 20:00:59
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/db4o In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17425/db4o Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository/db4o added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 20:00:09
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/jmxmp In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17179/jmxmp Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/jmxmp added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:59:37
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller/pool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16909/pool Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller/pool added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:59:28
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller/basic In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16899/basic Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller/basic added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:58:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16483/xml Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/xml added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:58:48
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/db In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16472/db Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config/db added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:58
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/util In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16064/util Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/util added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:43
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16050/repository Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/repository added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:29
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16030/management Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:21
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16017/controller Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/controller added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:13
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15993/config Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/config added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:57:02
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15611/io Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/io added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:56:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15593/framework Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:55:16
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15055/batch Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batch added to the repository |
From: Suresh <sur...@us...> - 2006-09-15 19:54:58
|
Update of /cvsroot/batchserver/batchserver In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14658 Modified Files: build_io.xml Log Message: no message Index: build_io.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/build_io.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** build_io.xml 24 Aug 2006 20:06:46 -0000 1.5 --- build_io.xml 15 Sep 2006 19:54:41 -0000 1.6 *************** *** 4,8 **** <property name="app.version" value="1.0"/> ! <property name="app.name" value="io"/> --- 4,8 ---- <property name="app.version" value="1.0"/> ! <property name="app.name" value="batch_io"/> *************** *** 55,59 **** <mkdir dir="${build.home}"/> <echo message="Classpath for compilation : ${compile.classpath}"/> ! <javac srcdir="${src.home}/org/jmonks/batchserver/io" destdir="${build.home}" debug="${compile.debug}" --- 55,59 ---- <mkdir dir="${build.home}"/> <echo message="Classpath for compilation : ${compile.classpath}"/> ! <javac srcdir="${src.home}/org/jmonks/batch/io" destdir="${build.home}" debug="${compile.debug}" *************** *** 65,69 **** <!-- Copy application resources --> <copy todir="${build.home}"> ! <fileset dir="${src.home}/org/jmonks/batchserver/io"> <patternset refid="app.resources"/> </fileset> --- 65,69 ---- <!-- Copy application resources --> <copy todir="${build.home}"> ! <fileset dir="${src.home}/org/jmonks/batch/io"> <patternset refid="app.resources"/> </fileset> *************** *** 100,115 **** <copy todir="${dist.home}/src"> <fileset dir="${src.home}"> ! <include name="org/jmonks/batchserver/io/*.java"/> ! <include name="org/jmonks/batchserver/io/flat/*.java"/> ! <include name="org/jmonks/batchserver/io/xml/*.java"/> ! <include name="org/jmonks/batchserver/io/flat/*.xml"/> ! <include name="org/jmonks/batchserver/io/xml/*.xml"/> ! <include name="org/jmonks/batchserver/io/flat/*.dat"/> ! <include name="org/jmonks/batchserver/io/xml/*.dat"/> </fileset> </copy> <!-- Create application JAR file --> ! <jar jarfile="${dist.home}/${app.name}-${app.version}.jar" basedir="${build.home}"> <manifest> --- 100,115 ---- <copy todir="${dist.home}/src"> <fileset dir="${src.home}"> ! <include name="org/jmonks/batch/io/*.java"/> ! <include name="org/jmonks/batch/io/flat/*.java"/> ! <include name="org/jmonks/batch/io/xml/*.java"/> ! <include name="org/jmonks/batch/io/flat/*.xml"/> ! <include name="org/jmonks/batch/io/xml/*.xml"/> ! <include name="org/jmonks/batch/io/flat/*.dat"/> ! <include name="org/jmonks/batch/io/xml/*.dat"/> </fileset> </copy> <!-- Create application JAR file --> ! <jar jarfile="${dist.home}/${app.name}_${app.version}.jar" basedir="${build.home}"> <manifest> *************** *** 128,132 **** <javadoc sourcepath="${src.home}" destdir="${docs.home}" ! packagenames="org/jmonks/batchserver/io,org/jmonks/batchserver/io/flat,org/jmonks/batchserver/io/xml" author="true" version="true" --- 128,132 ---- <javadoc sourcepath="${src.home}" destdir="${docs.home}" ! packagenames="org/jmonks/batch/io,org/jmonks/batch/io/flat,org/jmonks/batch/io/xml" author="true" version="true" |
From: Suresh <sur...@us...> - 2006-09-15 19:54:26
|
Update of /cvsroot/batchserver/batchserver/conf In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14632 Modified Files: batch-config.xml framework-config.xml Log Message: no message Index: framework-config.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/conf/framework-config.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** framework-config.xml 15 Sep 2006 06:22:16 -0000 1.2 --- framework-config.xml 15 Sep 2006 19:54:24 -0000 1.3 *************** *** 1,5 **** <?xml version="1.0" encoding="UTF-8"?> <framework-config> ! <job-config-factory-config job-config-factory-class-name="org.jmonks.batchserver.framework.config.xml.XMLJobConfigFactory"> <property key="job-config-file-classpath-location">batch-config.xml</property> </job-config-factory-config> --- 1,5 ---- <?xml version="1.0" encoding="UTF-8"?> <framework-config> ! <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.framework.config.xml.XMLJobConfigFactory"> <property key="job-config-file-classpath-location">batch-config.xml</property> </job-config-factory-config> *************** *** 7,11 **** Following is the sample configuration to read the job configuration from the database. ! <job-config-factory-config job-config-factory-class-name="org.jmonks.batchserver.framework.config.db.DBJobConfigFactory"> <property key="jdbc-driver-class-name">oracle.jdbc.driver.OracleDriver</property> <property key="jdbc-url">jdbc:oracle:thin:@hostname:1521:instancename</property> --- 7,11 ---- Following is the sample configuration to read the job configuration from the database. ! <job-config-factory-config job-config-factory-class-name="org.jmonks.batch.framework.config.db.DBJobConfigFactory"> <property key="jdbc-driver-class-name">oracle.jdbc.driver.OracleDriver</property> <property key="jdbc-url">jdbc:oracle:thin:@hostname:1521:instancename</property> *************** *** 14,31 **** </job-config-factory-config> --> ! <repository-config repository-class-name="org.jmonks.batchserver.framework.repository.db4o.Db4oRepository"> <property key="db4o-filename">/batchserver/repository/batchserver_repository.db</property> </repository-config> <framework-logging-config framework-logging-level="DEBUG" job-logging-directory="/batchserver/logs" job-base-package-name="com.mycompany.batch" job-logging-level="INFO"/> ! <job-connector-config job-connector-helper-class-name="org.jmonks.batchserver.framework.management.jmxmp.RepositoryJMXMPConnectorHelper"> </job-connector-config> <job-controller-config> ! <job-controller controller-class-name="org.jmonks.batchserver.framework.controller.pool.PoolJobController" ! xml-factory-config-class-name="org.jmonks.batchserver.framework.config.xml.XMLPoolJobControllerConfig" ! db-factory-config-class-name="org.jmonks.batchserver.framework.config.db.DBPoolJobControllerConfig"/> ! <job-controller controller-class-name="org.jmonks.batchserver.framework.controller.basic.BasicJobController" ! xml-factory-config-class-name="org.jmonks.batchserver.framework.config.xml.XMLBasicJobControllerConfig" ! db-factory-config-class-name="org.jmonks.batchserver.framework.config.db.DBBasicJobControllerConfig"/> </job-controller-config> </framework-config> \ No newline at end of file --- 14,31 ---- </job-config-factory-config> --> ! <repository-config repository-class-name="org.jmonks.batch.framework.repository.db4o.Db4oRepository"> <property key="db4o-filename">/batchserver/repository/batchserver_repository.db</property> </repository-config> <framework-logging-config framework-logging-level="DEBUG" job-logging-directory="/batchserver/logs" job-base-package-name="com.mycompany.batch" job-logging-level="INFO"/> ! <job-connector-config job-connector-helper-class-name="org.jmonks.batch.framework.management.jmxmp.RepositoryJMXMPConnectorHelper"> </job-connector-config> <job-controller-config> ! <job-controller controller-class-name="org.jmonks.batch.framework.controller.pool.PoolJobController" ! xml-factory-config-class-name="org.jmonks.batch.framework.config.xml.XMLPoolJobControllerConfig" ! db-factory-config-class-name="org.jmonks.batch.framework.config.db.DBPoolJobControllerConfig"/> ! <job-controller controller-class-name="org.jmonks.batch.framework.controller.basic.BasicJobController" ! xml-factory-config-class-name="org.jmonks.batch.framework.config.xml.XMLBasicJobControllerConfig" ! db-factory-config-class-name="org.jmonks.batch.framework.config.db.DBBasicJobControllerConfig"/> </job-controller-config> </framework-config> \ No newline at end of file Index: batch-config.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/conf/batch-config.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** batch-config.xml 15 Sep 2006 06:22:16 -0000 1.2 --- batch-config.xml 15 Sep 2006 19:54:23 -0000 1.3 *************** *** 2,6 **** <batch-config> <job-config job-name="process_file_abc" job-status="active"> ! <job-controller job-controller-class-name="org.jmonks.batchserver.framework.controller.pool.PoolJobController"> <pool-job-loader pool-job-loader-class-name="com.mycompany.batch.processfileabc.AbcJobLoader"> <property key="pool-job-loader-key1">loader-value1</property> --- 2,6 ---- <batch-config> <job-config job-name="process_file_abc" job-status="active"> ! <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.pool.PoolJobController"> <pool-job-loader pool-job-loader-class-name="com.mycompany.batch.processfileabc.AbcJobLoader"> <property key="pool-job-loader-key1">loader-value1</property> *************** *** 9,13 **** <property key="pool-job-processor-key1">processor-value1</property> </pool-job-processor> ! <job-pool job-pool-class-name="org.jmonks.batchserver.framework.controller.pool.DefaultJobPool"> <property key="job-pool-size">50000</property> </job-pool> --- 9,13 ---- <property key="pool-job-processor-key1">processor-value1</property> </pool-job-processor> ! <job-pool job-pool-class-name="org.jmonks.batch.framework.controller.pool.DefaultJobPool"> <property key="job-pool-size">50000</property> </job-pool> *************** *** 19,24 **** </job-config> <job-config job-name="process_file_xyz" job-status="active"> ! <job-controller job-controller-class-name="org.jmonks.batchserver.framework.controller.basic.BasicJobController"> ! <basic-job-processor basic-job-processor-class-name="org.jmonks.batchserver.framework.controller.basic.TestBasicJobProcessor" thread-count="5"> <property key="processor-config-key1">processor-config-value1</property> </basic-job-processor> --- 19,24 ---- </job-config> <job-config job-name="process_file_xyz" job-status="active"> ! <job-controller job-controller-class-name="org.jmonks.batch.framework.controller.basic.BasicJobController"> ! <basic-job-processor basic-job-processor-class-name="org.jmonks.batch.framework.controller.basic.TestBasicJobProcessor" thread-count="5"> <property key="processor-config-key1">processor-config-value1</property> </basic-job-processor> *************** *** 26,31 **** </job-controller> <job-logging-config> ! <job-logger-config logger-name="org.jmonks.batchserver.framework.controller.basic" logger-level="TRACE"/> ! <job-logger-config logger-name="org.jmonks.batchserver.framework" logger-level="ERROR"/> </job-logging-config> </job-config> --- 26,31 ---- </job-controller> <job-logging-config> ! <job-logger-config logger-name="org.jmonks.batch.framework.controller.basic" logger-level="TRACE"/> ! <job-logger-config logger-name="org.jmonks.batch.framework" logger-level="ERROR"/> </job-logging-config> </job-config> |
From: Suresh <sur...@us...> - 2006-09-15 06:22:22
|
Update of /cvsroot/batchserver/batchserver/conf In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17481 Modified Files: batch-config.xml framework-config.xml Log Message: no message Index: framework-config.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/conf/framework-config.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** framework-config.xml 14 Sep 2006 05:02:08 -0000 1.1 --- framework-config.xml 15 Sep 2006 06:22:16 -0000 1.2 *************** *** 15,19 **** <repository-config repository-class-name="org.jmonks.batchserver.framework.repository.db4o.Db4oRepository"> ! <property key="repository-location">/batchserver/repository</property> </repository-config> <framework-logging-config framework-logging-level="DEBUG" job-logging-directory="/batchserver/logs" --- 15,19 ---- <repository-config repository-class-name="org.jmonks.batchserver.framework.repository.db4o.Db4oRepository"> ! <property key="db4o-filename">/batchserver/repository/batchserver_repository.db</property> </repository-config> <framework-logging-config framework-logging-level="DEBUG" job-logging-directory="/batchserver/logs" Index: batch-config.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/conf/batch-config.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** batch-config.xml 14 Sep 2006 05:02:08 -0000 1.1 --- batch-config.xml 15 Sep 2006 06:22:16 -0000 1.2 *************** *** 6,10 **** <property key="pool-job-loader-key1">loader-value1</property> </pool-job-loader> ! <pool-job-processor pool-job-processor-class-name="com.mycompany.batch.processfileabc.AbcJobProcessor" thread-count="1"> <property key="pool-job-processor-key1">processor-value1</property> </pool-job-processor> --- 6,10 ---- <property key="pool-job-loader-key1">loader-value1</property> </pool-job-loader> ! <pool-job-processor pool-job-processor-class-name="com.mycompany.batch.processfileabc.AbcJobProcessor" thread-count="5"> <property key="pool-job-processor-key1">processor-value1</property> </pool-job-processor> *************** *** 21,27 **** <job-controller job-controller-class-name="org.jmonks.batchserver.framework.controller.basic.BasicJobController"> <basic-job-processor basic-job-processor-class-name="org.jmonks.batchserver.framework.controller.basic.TestBasicJobProcessor" thread-count="5"> ! <property key="basic-job-processor-key1">processor-value1</property> </basic-job-processor> ! <property key="basic-job-controller-restart">true</property> </job-controller> <job-logging-config> --- 21,27 ---- <job-controller job-controller-class-name="org.jmonks.batchserver.framework.controller.basic.BasicJobController"> <basic-job-processor basic-job-processor-class-name="org.jmonks.batchserver.framework.controller.basic.TestBasicJobProcessor" thread-count="5"> ! <property key="processor-config-key1">processor-config-value1</property> </basic-job-processor> ! <property key="controller-config-key1">controller-config-value1</property> </job-controller> <job-logging-config> |