[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework/config BasicJobControllerConfig.java,
Brought to you by:
suresh_pragada
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] |