Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework DefaultRepository.java,1.2,1.3 Lo
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-14 23:01:22
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18019 Modified Files: DefaultRepository.java LoggingManager.java Repository.java Log Message: no message Index: DefaultRepository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/DefaultRepository.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DefaultRepository.java 4 Mar 2006 04:48:52 -0000 1.2 --- DefaultRepository.java 14 Mar 2006 23:00:57 -0000 1.3 *************** *** 1,18 **** package org.jmonks.batchserver.framework; /** * <p> ! * This implementation of repository uses the DB4O database as the repository. It expects the following two properties present in the repository configuration in framework-cofig.xml file. * <br><br> * <pre> ! * <repository-config repository-class-name="org.jmonks.batchserver.framework.DefaultRepository"> ! * <property key="repository-location">/batchserver/repository</property> ! * <property key="repository-filename">batchserver_repository.db</property> ! * </repository-config> * </pre> * <br><br> ! * Here repository-location defines where the DB4O database needs to be created and repository-filename defines the name of the file to be used as the repository. ! * * </p> * @author Suresh Pragada --- 1,26 ---- package org.jmonks.batchserver.framework; + import java.util.HashMap; + import java.util.Map; + import org.apache.log4j.Logger; + import org.jmonks.batchserver.framework.controller.JobController; + /** * <p> ! * This implementation of repository uses the DB4O database as the repository. ! * It expects the two properties repository-location and repository-filename present in the repository configuration ! * in framework-cofig.xml file. * <br><br> * <pre> ! * <repository-config repository-class-name="org.jmonks.batchserver.framework.DefaultRepository"> ! * <property key="repository-location">/batchserver/repository</property> ! * <property key="repository-filename">batchserver_repository.db</property> ! * </repository-config> * </pre> * <br><br> ! * Here repository-location defines where the DB4O database needs to be created and ! * repository-filename defines the name of the file to be used as the repository. ! * By default framework will be configured with the values shown in the above XML configuration snippet. * </p> * @author Suresh Pragada *************** *** 20,27 **** * @since 1.0 */ ! public abstract class DefaultRepository extends Repository { ! private DefaultRepository(java.util.Map configProps) { } --- 28,43 ---- * @since 1.0 */ ! public class DefaultRepository extends Repository { ! private Map repositoryConfigProperties=null; ! ! private static Logger logger=Logger.getLogger(DefaultRepository.class); ! ! /** ! * ! */ ! public DefaultRepository(Map configProps) { + this.repositoryConfigProperties=new HashMap(configProps); } *************** *** 30,34 **** */ public boolean logStatistics(org.jmonks.batchserver.framework.JobStatistics statistics) - { return true; --- 46,49 ---- *************** *** 40,44 **** */ public boolean sendDatatoNextJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp, Object data) - { return true; --- 55,58 ---- *************** *** 50,54 **** */ public Object getDataFromPreviousJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp) - { return null; --- 64,67 ---- *************** *** 60,64 **** */ public boolean registerJobMgmtMntrInfo(String jobName, Object registrationInfo) - { return true; --- 73,76 ---- *************** *** 70,74 **** */ public Object lookupJobMgmtMntrInfo(String jobName) - { return null; --- 82,85 ---- *************** *** 80,84 **** */ public boolean unregisterJobMgmtMntrInfo(String jobName) - { return true; --- 91,94 ---- *************** *** 89,94 **** * @see org.jmonks.batchserver.framework.Repository#getStatistics(String) */ ! public org.jmonks.batchserver.framework.JobStatistics[] getStatistics(String jobName) ! { return null; --- 99,103 ---- * @see org.jmonks.batchserver.framework.Repository#getStatistics(String) */ ! public JobStatistics[] getStatistics(String jobName) { return null; *************** *** 99,104 **** * @see org.jmonks.batchserver.framework.Repository#saveController(org.jmonks.batchserver.framework.controller.JobController,String) */ ! public boolean saveController(org.jmonks.batchserver.framework.controller.JobController controller, String jobName) ! { return true; --- 108,112 ---- * @see org.jmonks.batchserver.framework.Repository#saveController(org.jmonks.batchserver.framework.controller.JobController,String) */ ! public boolean saveController(String jobName, JobController controller) { return true; *************** *** 109,114 **** * @see org.jmonks.batchserver.framework.Repository#loadController(String) */ ! public org.jmonks.batchserver.framework.controller.JobController loadController(String jobName) ! { return null; --- 117,121 ---- * @see org.jmonks.batchserver.framework.Repository#loadController(String) */ ! public JobController loadController(String jobName) { return null; *************** *** 120,124 **** */ public boolean releaseController(String jobName) - { return true; --- 127,130 ---- Index: Repository.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/Repository.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Repository.java 4 Mar 2006 04:48:52 -0000 1.2 --- Repository.java 14 Mar 2006 23:00:57 -0000 1.3 *************** *** 1,13 **** package org.jmonks.batchserver.framework; import org.jmonks.batchserver.framework.config.*; ! import org.jmonks.batchserver.framework.controller.*; /** * <p> ! * Repository provides utility methods to access and use the repository. ! * There could be differnt implementations of the repository. Framework ! * configuration defines which implementation should be used for this framework. ! * This povides utility methods to logs the job statistics and persist any objects, * transfer some information between the jobs and transfer some management and monitor * information between framework and server. --- 1,18 ---- package org.jmonks.batchserver.framework; + import java.lang.reflect.Constructor; + import java.lang.reflect.InvocationTargetException; + import java.util.Map; + import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.*; ! import org.jmonks.batchserver.framework.controller.JobController; ! /** * <p> ! * Repository provides utility methods to access and use the repository maintained ! * by the framework. There could be differnt implementations of the repository. ! * Framework configuration defines which implementation should be used for this framework. ! * This povides utility methods to logs the job statistics and persist job controllers, * transfer some information between the jobs and transfer some management and monitor * information between framework and server. *************** *** 20,69 **** { protected Repository() { } ! public static void getRepository(org.jmonks.batchserver.framework.config.FrameworkConfig.RepositoryConfig config) { } /** ! * This method logs the job statistics given in the form JobStatistics object ! * in the repository for further use. * * @param statistics Job Statistics object which holds all the statistics related to that job. * ! * @return Returns true if statistics can be logged, false, otherwise. */ ! public abstract boolean logStatistics(org.jmonks.batchserver.framework.JobStatistics statistics); /** ! * Given data will be sent to the specified job behalf of this job. * ! * @param srcJN Name of the source job. ! * @param srcCmp Name of the source componenet. ! * @param tgtJN Name of the target job. ! * @param tgtCmp Name of the target component. ! * @param data data that needs to be sent as the object. * * @return Returns true, if it could save the data to be sent to the next job. */ ! public abstract boolean sendDatatoNextJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp, Object data); /** ! * Gets the data that has been sent to this job. * ! * @param srcJN Name of the source job. ! * @param srcCmp Name of the source componenet. ! * @param tgtJN Name of the target job. ! * @param tgtCmp Name of the target component. * ! * @return Returns the data, null, it it couldnt find any data. */ ! public abstract Object getDataFromPreviousJob(String srcJN, String srcCmp, String tgtJN, String tgtCmp); /** * Registers the job management and monitoring info with the given job name. * ! * @param jobName Name of the job. * @param registrationInfo Information to be associated with this job name. * --- 25,151 ---- { + private static Logger logger=Logger.getLogger(Repository.class); + + /** + * Protected constructor to make sure Repository cannot be instantiated + * other than extending this class. + */ protected Repository() { } ! ! /** ! * Factory method returns the specific implementation of repository based on the ! * repository configuration. ! * ! * @param repositoryConfig Repository configuration object. ! * ! * @throws ConfigurationException If repositoryClassName is missing or invalid ! * or it cannot be instantiated because of the lack of mandatory properties required ! * by the specific repository implementations. ! * @throws IllegalArgumentException If input repositoryConfig is null. ! */ ! public static Repository getRepository(FrameworkConfig.RepositoryConfig repositoryConfig) { + logger.trace("Entering getRepository"); + + if(repositoryConfig==null) + throw new IllegalArgumentException("repository configuration object cannot be null."); + + String repositoryClassName=repositoryConfig.getRepositoryClassName(); + if(repositoryClassName==null || "".equals(repositoryClassName)) + throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, "repository class name is not defined in repository configuration"); + logger.debug("repository class name = " + repositoryClassName); + + Repository repository=null; + + try + { + Class repositoryClass=Class.forName(repositoryClassName); + Constructor repositoryConstructor=repositoryClass.getConstructor(new Class[]{Map.class}); + repository=(Repository)repositoryConstructor.newInstance(new Object[]{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(NoSuchMethodException 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()); + } + catch(InvocationTargetException exception) + { + exception.printStackTrace(); + logger.error(exception.getMessage(),exception); + throw new ConfigurationException(ConfigurationException.REPOSITORY_CONFIG, exception.getMessage()); + } + + logger.trace("Exiting getRepository"); + return repository; } /** ! * Logs the job statistics given in the form of JobStatistics object ! * in the repository for further use/reference. * * @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. */ ! public abstract boolean logStatistics(JobStatistics statistics); /** ! * Data will be sent to the specified component of the specified ! * job behalf of the specific component from specific job. * ! * @param sourceJobName Name of the source job. ! * @param sourceComponent Name of the source componenet. ! * @param targetJobName Name of the target job. ! * @param targetComponent Name of the target component. ! * @param data Data that needs to be sent as the object. * * @return Returns true, if it could save the data to be sent to the next job. */ ! public abstract boolean sendDatatoNextJob(String sourceJobName, String sourceComponent, ! String targetJobName, String targetComponent, Object data); /** ! * Gets the data that has been sent to this component of this job from ! * specific component of specific job. * ! * @param sourceJobName Name of the source job. ! * @param sourceComponent Name of the source componenet. ! * @param targetJobName Name of the target job. ! * @param targetComponent Name of the target component. * ! * @return Returns the data, null, if it couldnt find any data. */ ! public abstract Object getDataFromPreviousJob(String sourceJobName, String sourceComponent, ! String targetJobName, String targetComponent); /** * Registers the job management and monitoring info with the given job name. + * If there is an association with this job name existing, that information + * will be overriden. This could happen, if job forgot to unregister the + * management and monitoring information. * ! * @param jobName Name of the job. * @param registrationInfo Information to be associated with this job name. * *************** *** 96,100 **** * @return Returns the array of JobStatistics object, null, if it couldnt find any job with that name. */ ! public abstract org.jmonks.batchserver.framework.JobStatistics[] getStatistics(String jobName); /** --- 178,182 ---- * @return Returns the array of JobStatistics object, null, if it couldnt find any job with that name. */ ! public abstract JobStatistics[] getStatistics(String jobName); /** *************** *** 108,112 **** * @return Returns true, if it could persist the controller, false, otherwise. */ ! public abstract boolean saveController(org.jmonks.batchserver.framework.controller.JobController controller, String jobName); /** --- 190,194 ---- * @return Returns true, if it could persist the controller, false, otherwise. */ ! public abstract boolean saveController(String jobName, JobController controller); /** *************** *** 118,122 **** * @return Returns the controller object, null, if it couldnt find any. */ ! public abstract org.jmonks.batchserver.framework.controller.JobController loadController(String jobName); /** --- 200,204 ---- * @return Returns the controller object, null, if it couldnt find any. */ ! public abstract JobController loadController(String jobName); /** Index: LoggingManager.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/LoggingManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** LoggingManager.java 14 Mar 2006 05:46:33 -0000 1.4 --- LoggingManager.java 14 Mar 2006 23:00:57 -0000 1.5 *************** *** 44,49 **** * Standard pattern expression used for all the log files. */ ! public static final String DEFAULT_MESSAGE_PATTERN = "%-5p [%t]: %m%n"; private LoggingManager() { --- 44,52 ---- * Standard pattern expression used for all the log files. */ ! public static final String DEFAULT_MESSAGE_PATTERN = "%5p [%d{ISO8601}] [%t - %C] %m%n"; + /** + * Private constructor to make sure LoggingManager will not be instantiated. + */ private LoggingManager() { *************** *** 60,64 **** * <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 for the root logger. * <li>Access the defined loggers at job level and set the level for those loggers. * </ul> --- 63,67 ---- * <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> *************** *** 72,76 **** * </p> */ ! public static void initializeJobLogging(String jobName, FrameworkConfig.LoggingConfig frameworkLoggingConfig,JobLoggingConfig jobLoggingConfig) { if(jobName==null) --- 75,79 ---- * </p> */ ! public static void initializeJobLogging(String jobName, FrameworkConfig.FrameworkLoggingConfig frameworkLoggingConfig,JobLoggingConfig jobLoggingConfig) { if(jobName==null) *************** *** 80,88 **** throw new IllegalArgumentException("framework logging config object cannot be null to establish the job logging service."); ! File loggingDirecotry=new File(frameworkLoggingConfig.getLoggingDirecotry()+File.separator+jobName); LoggingManager.createDirectory(loggingDirecotry); String completeFileName=loggingDirecotry.getAbsolutePath()+File.separator+ ! jobName+"_"+new SimpleDateFormat("yyyyMMdd_HHmmss_S").format(Calendar.getInstance().getTime())+"_.log"; ! LoggingManager.addAppender(completeFileName); if(jobLoggingConfig!=null) { --- 83,110 ---- throw new IllegalArgumentException("framework logging config object cannot be null to establish the job logging service."); ! 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) { *************** *** 99,103 **** /** * Initializes the logging of the framework in the directory defined in framework configuration. ! * This will be used until the job logging is enabled. * * @param frameworkLoggingConfig Framework logging configuration object. --- 121,126 ---- /** * 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. *************** *** 105,114 **** * @throws ConfigurationException If logging directory cannot be created. */ ! public static void initializeFrameworkLogging(FrameworkConfig.LoggingConfig frameworkLoggingConfig) { ! File loggingDirecotry=new File(frameworkLoggingConfig.getLoggingDirecotry()); LoggingManager.createDirectory(loggingDirecotry); String completeFileName=loggingDirecotry.getAbsolutePath()+File.separator+LoggingManager.FRAMEWORK_LOGGING_FILE; ! LoggingManager.addAppender(completeFileName); } --- 128,157 ---- * @throws ConfigurationException If logging directory cannot be created. */ ! public static void initializeFrameworkLogging(FrameworkConfig.FrameworkLoggingConfig frameworkLoggingConfig) { ! 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.batchserver.framework"); ! frameworkLogger.addAppender(fileAppender); ! frameworkLogger.setAdditivity(true); ! frameworkLogger.setLevel(Level.toLevel(frameworkLoggingConfig.getFrameworkLoggingLevel())); } *************** *** 130,157 **** } } - - /** - * Common method creates the rolling file appender with the given name and attaches it - * to the root logger after creating all the existing loggers. - * - * @param fileName Name of the file to be attached to the appender. - */ - private static void addAppender(String fileName) - { - try - { - PatternLayout layout=new PatternLayout(LoggingManager.DEFAULT_MESSAGE_PATTERN); - RollingFileAppender fileAppender=new RollingFileAppender(layout,fileName,true); - fileAppender.setMaxFileSize("10MB"); - fileAppender.activateOptions(); - Logger rootLogger=LogManager.getRootLogger(); - rootLogger.removeAllAppenders(); - rootLogger.addAppender(fileAppender); - } - catch(IOException exception) - { - exception.printStackTrace(); - } - - } } --- 173,175 ---- |