[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework JobContext.java, 1.6, 1.7
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-14 23:06:25
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11137 Modified Files: JobContext.java Log Message: no message Index: JobContext.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/JobContext.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JobContext.java 13 Sep 2006 23:29:25 -0000 1.6 --- JobContext.java 14 Sep 2006 23:06:22 -0000 1.7 *************** *** 13,16 **** --- 13,17 ---- import java.util.Collections; import java.util.Map; + import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.FrameworkConfig; import org.jmonks.batchserver.framework.config.JobConfig; *************** *** 18,38 **** /** * ! * @author Suresh Pragada */ public class JobContext { ! public static final String CONTEXT_PARAM_JOB_CONFIG="job.config"; ! public static final String CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG="job.command.line.config"; ! public static final String CONTEXT_PARAM_REPOSITORY="repository"; ! protected JobConfig jobConfig=null; protected Repository repository=null; ! protected Map commandLineConfig=null; public JobContext(Map contextParams, Main contextCreator) { if(!(contextCreator instanceof Main)) throw new SecurityException("Not authorized to create the job context."); --- 19,98 ---- /** + * <p> + * JobContext provides the references to the framework resources the job is being + * executed. 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."); *************** *** 42,57 **** /** ! * Retrieve and add the command line config map to the context. */ ! if(contextParams.containsKey(JobContext.CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG)) { ! Object objectCommandLineConfig=contextParams.get(JobContext.CONTEXT_PARAM_JOB_COMMAND_LINE_CONFIG); ! if(objectCommandLineConfig instanceof Map) ! this.commandLineConfig=(Map)objectCommandLineConfig; else ! throw new IllegalArgumentException("Provided job command line configuration object to initalize job context is not valid."); } else ! throw new IllegalArgumentException("Missing the required job command line configuration map object in context params."); /** --- 102,118 ---- /** ! * 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"); /** *************** *** 68,71 **** --- 129,133 ---- else throw new IllegalArgumentException("Missing the required job configuration object in context params."); + logger.debug("Added the job config reference to JobContext"); /** *************** *** 82,87 **** --- 144,157 ---- 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() { *************** *** 89,92 **** --- 159,167 ---- } + /** + * Gets the repository reference configured for this framework. + * + * @return Gets the repository reference. + */ public Repository getRepository() { *************** *** 94,97 **** --- 169,177 ---- } + /** + * Gets the job configuration object belongs to the running job. + * + * @return Returns the running job's configuration object. + */ public JobConfig getJobConfig() { *************** *** 99,107 **** } ! public Map getJobCommandLineConfig() { ! return Collections.unmodifiableMap(this.commandLineConfig); } public FrameworkConfig getFrameworkConfig() { --- 179,199 ---- } ! /** ! * 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() { |