[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework/management JobConnectorHelper.java, 1
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-19 22:51:31
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3112/management Modified Files: JobConnectorHelper.java JobManagementAgent.java JobManager.java JobMonitor.java Log Message: no message Index: JobManagementAgent.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/JobManagementAgent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JobManagementAgent.java 19 Sep 2006 00:05:52 -0000 1.2 --- JobManagementAgent.java 19 Sep 2006 22:51:28 -0000 1.3 *************** *** 14,18 **** import org.jmonks.batch.framework.Main; import org.jmonks.batch.framework.config.ConfigurationException; ! import org.jmonks.batch.framework.controller.JobController; /** --- 14,19 ---- import org.jmonks.batch.framework.Main; import org.jmonks.batch.framework.config.ConfigurationException; ! import org.jmonks.batch.framework.JobController; ! import org.jmonks.batch.framework.config.FrameworkConfig; /** *************** *** 45,52 **** public static final String JOB_MONITOR_MBEAN_NAME = "JobMonitorMBean"; /** - * Singleton job management agent instance. - */ - private static final JobManagementAgent jobManagementAgent=new JobManagementAgent(); - /** * JMX Connector server instance created for this agent. */ --- 46,49 ---- *************** *** 58,64 **** private JobConnectorHelper jobConnectorHelper=null; /** ! * Name of the job this agent configured for. */ ! private String jobName=null; /** * Tells whether the agent has been started or not. --- 55,61 ---- private JobConnectorHelper jobConnectorHelper=null; /** ! * Context of the job is being run. */ ! private JobContext jobContext=null; /** * Tells whether the agent has been started or not. *************** *** 73,94 **** /** ! * Initializes the job management agent. It make sure it would be able to get ! * the reference to job connector server helper class. ! * ! * @throws ConfigurationException If it couldnt get the job connector server helper class. */ private JobManagementAgent() { - this.jobConnectorHelper=JobConnectorHelper.getJobConnectorHelper(); - if(jobConnectorHelper==null) - throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "could not get the reference to job connector helper class."); } /** ! * Returns the job management agent instance. ! */ ! public static JobManagementAgent getJobManagementAgent() { ! return jobManagementAgent; } --- 70,108 ---- /** ! * Make sure nobody is trying to create the agent from outside of this class. */ private JobManagementAgent() { } /** ! * <p> ! * Creates the agent and initializes with the job context and job connection ! * helper. Once it is created, it will be associated with the job in the job ! * context. ! * </p> ! * ! * @param jobContext Context of the job is being run. ! * @param agentCreator Main class instance authroized to create the agent. ! * ! * @return Returns the JobConnectorHelper implemenation. ! * ! * @throws SecurityException If there is an attempt to create the agent other than Main class(framework). ! * @throws ConfigurationException If unable to instantiate the job connection helper. ! */ ! public static JobManagementAgent createJobManagementAgent(JobContext jobContext, Main agentCreator) { ! logger.trace("Entering createJobManagementAgent"); ! ! if(!(agentCreator instanceof Main)) ! throw new SecurityException("Not authorized to create the management agent."); ! ! JobManagementAgent agent=new JobManagementAgent(); ! agent.jobContext=jobContext; ! agent.jobConnectorHelper=JobConnectorHelper.getJobConnectorHelper ! (jobContext.getFrameworkConfig().getJobConnectorConfig(), agent); ! ! logger.trace("Exiting createJobManagementAgent"); ! return agent; } *************** *** 106,114 **** * </ul> * <br> - * Agent can be started only once in the job life cycle. If it receives a request to start - * when it is already started, it throws IllegalStateException. * </p> * - * @param jobContext Context of the job is being run. * @param jobController Controller reference to be passed to the mbeans. * @param agentManager Main class reference as a agent manager. --- 120,125 ---- *************** *** 116,130 **** * @return Returns true, if manager is started properly, false, otherwise. * - * @throws SecurityException if an attempt is maded to start by any one other than Main(framework). * @throws IllegalArgumentException If input parameters job name or job controller is null. ! * @throws IllegalStateException If manager is already started or already stopped. */ ! public boolean start(JobContext jobContext, JobController jobController, Main agentManager) { logger.trace("Entering start"); - if(!(agentManager instanceof Main)) - throw new SecurityException("Not authorized to manage the agent."); - if(this.started) throw new IllegalStateException("job management agent has been already started."); --- 127,137 ---- * @return Returns true, if manager is started properly, false, otherwise. * * @throws IllegalArgumentException If input parameters job name or job controller is null. ! * @throws IllegalStateException If manager is already started. */ ! public boolean start(JobController jobController) { logger.trace("Entering start"); if(this.started) throw new IllegalStateException("job management agent has been already started."); *************** *** 132,142 **** throw new IllegalStateException("job management agent has not been stopped."); - if(jobContext==null) - throw new IllegalArgumentException("job context cannot be null to start the job management agent."); if(jobController==null) throw new IllegalArgumentException("controller object cannot be null to start the job management agent."); - this.jobName=jobContext.getJobName(); - try { --- 139,145 ---- *************** *** 160,168 **** ObjectName connectorServerObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+jobName+",objectType=JMXConnectorServer"); ObjectName monitorBeanObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+jobName+",objectType="+JobManagementAgent.JOB_MONITOR_MBEAN_NAME); ObjectName managerBeanObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+jobName+",objectType="+JobManagementAgent.JOB_MANAGER_MBEAN_NAME); mbeanServer.registerMBean(this.jmxConnectorServer, connectorServerObjectName); --- 163,171 ---- ObjectName connectorServerObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+this.jobContext.getJobName()+",objectType=JMXConnectorServer"); ObjectName monitorBeanObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+this.jobContext.getJobName()+",objectType="+JobManagementAgent.JOB_MONITOR_MBEAN_NAME); ObjectName managerBeanObjectName= ! new ObjectName(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME+":jobName="+this.jobContext.getJobName()+",objectType="+JobManagementAgent.JOB_MANAGER_MBEAN_NAME); mbeanServer.registerMBean(this.jmxConnectorServer, connectorServerObjectName); *************** *** 173,177 **** */ this.jmxConnectorServer.start(); ! boolean registered=this.jobConnectorHelper.registerConnectorServer(jobContext,this.jmxConnectorServer); if(registered) { --- 176,180 ---- */ this.jmxConnectorServer.start(); ! boolean registered=this.jobConnectorHelper.registerConnectorServer(this.jobContext,this.jmxConnectorServer); if(registered) { *************** *** 184,188 **** logger.error("Unable to register the jmx connector server using job connector helper"); this.started=false; ! this.stopped=false; } } --- 187,191 ---- logger.error("Unable to register the jmx connector server using job connector helper"); this.started=false; ! this.stopped=true; } } *************** *** 223,243 **** * exit status will be sent to all the JMX remote clients as a notification. * - * @param jobContext Context of the job is being run. * @param exitCode errorCode returned by controller to the Main class. - * @param agentManager Main class reference as a agent manager. * * @return Returns true, if agent could be stopped properly, false otherwise. * - * @throws SecurityException if an attempt is maded to stop by any one other than Main(framework). * @throws IllegalArgumentException If input parameter status code is null. * @throws IllegalStateException If agent is already stopped or it not yet started. */ ! public boolean stop(JobContext jobContext, ErrorCode exitCode, Main agentManager) { logger.trace("Entering stop"); - if(!(agentManager instanceof Main)) - throw new SecurityException("Not authorized to manage the agent."); - if(!this.started) throw new IllegalStateException("Job management agent has not been started."); --- 226,240 ---- * exit status will be sent to all the JMX remote clients as a notification. * * @param exitCode errorCode returned by controller to the Main class. * * @return Returns true, if agent could be stopped properly, false otherwise. * * @throws IllegalArgumentException If input parameter status code is null. * @throws IllegalStateException If agent is already stopped or it not yet started. */ ! public boolean stop(ErrorCode exitCode) { logger.trace("Entering stop"); if(!this.started) throw new IllegalStateException("Job management agent has not been started."); *************** *** 245,256 **** throw new IllegalStateException("Job management agent has been stopped already."); - if(jobContext==null) - throw new IllegalArgumentException("Job context cannot be null to stop the server."); - if(exitCode==null) throw new IllegalArgumentException("controller exit code cannot be null to stop the server."); try { ! JobNotification notification=new JobNotification(this.jobName, JobNotification.JOB_FINISHED, this, exitCode.toString()); this.jmxConnectorServer.sendNotification(notification); this.jmxConnectorServer.stop(); --- 242,250 ---- throw new IllegalStateException("Job management agent has been stopped already."); if(exitCode==null) throw new IllegalArgumentException("controller exit code cannot be null to stop the server."); try { ! JobNotification notification=new JobNotification(this.jobContext.getJobName(), JobNotification.JOB_FINISHED, this, exitCode.toString()); this.jmxConnectorServer.sendNotification(notification); this.jmxConnectorServer.stop(); Index: JobMonitor.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/JobMonitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobMonitor.java 15 Sep 2006 20:07:01 -0000 1.1 --- JobMonitor.java 19 Sep 2006 22:51:28 -0000 1.2 *************** *** 11,15 **** package org.jmonks.batch.framework.management; ! import org.jmonks.batch.framework.controller.JobController; /** --- 11,15 ---- package org.jmonks.batch.framework.management; ! import org.jmonks.batch.framework.JobController; /** Index: JobManager.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/JobManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobManager.java 15 Sep 2006 20:07:01 -0000 1.1 --- JobManager.java 19 Sep 2006 22:51:28 -0000 1.2 *************** *** 13,17 **** import javax.management.NotificationBroadcasterSupport; import org.apache.log4j.Level; ! import org.jmonks.batch.framework.controller.JobController; /** --- 13,17 ---- import javax.management.NotificationBroadcasterSupport; import org.apache.log4j.Level; ! import org.jmonks.batch.framework.JobController; /** Index: JobConnectorHelper.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/JobConnectorHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobConnectorHelper.java 15 Sep 2006 20:07:01 -0000 1.1 --- JobConnectorHelper.java 19 Sep 2006 22:51:28 -0000 1.2 *************** *** 15,19 **** import org.jmonks.batch.framework.JobContext; import org.jmonks.batch.framework.config.ConfigurationException; ! import org.jmonks.batch.framework.config.FrameworkConfig; /** --- 15,19 ---- import org.jmonks.batch.framework.JobContext; import org.jmonks.batch.framework.config.ConfigurationException; ! import org.jmonks.batch.framework.config.FrameworkConfig.JobConnectorConfig; /** *************** *** 21,29 **** * JobConnectorHelper defines the helper methods will be used in creating the * JMX connector server, registering and unregistering the JMX connector server ! * in lookup location and querying the registerd jobs in look up location and ! * creating the JMX connector clients. * Because of many possible implementations available in creating * the JMX connector server and lookup locations, this class defines the methods ! * to choose their own implementations. Mainly, Agent and client looks for the following * information and activities from the concrete implementations of the connector * helper class. --- 21,28 ---- * JobConnectorHelper defines the helper methods will be used in creating the * JMX connector server, registering and unregistering the JMX connector server ! * in lookup location. * Because of many possible implementations available in creating * the JMX connector server and lookup locations, this class defines the methods ! * to choose their own implementations. Mainly, Agent looks for the following * information and activities from the concrete implementations of the connector * helper class. *************** *** 33,43 **** * <li>Register the given the JMX connector server in the lookup location with the given jobname. * <li>Unregister the JMX connector server available in lookup location with the given jobname. - * <li>Get all the registered jobs in look up location as list. - * <li>Get the JMX connector from the look up location for the requested job name. * </ul> * <br> * This class provides the factory method to return the configured JobConnectorHelper * instance by looking at the framework configuration and make sure only one ! * instance will be created for the job(jvm). * </p> * @author Suresh Pragada --- 32,40 ---- * <li>Register the given the JMX connector server in the lookup location with the given jobname. * <li>Unregister the JMX connector server available in lookup location with the given jobname. * </ul> * <br> * This class provides the factory method to return the configured JobConnectorHelper * instance by looking at the framework configuration and make sure only one ! * instance will be created for the job. * </p> * @author Suresh Pragada *************** *** 48,59 **** { private static Logger logger=Logger.getLogger(JobConnectorHelper.class); - /** - * Singleton job connector helper instance. - */ - private static JobConnectorHelper jobConnectorHelper=null; /** * This factory method creates the correct implementation of JobConnectorHelper ! * based on the configuration defined in framework-config.xml file. * This looks for the following configuration and uses the class name provided * at the job-connector-helper-class-name attribute to create the helper --- 45,52 ---- { private static Logger logger=Logger.getLogger(JobConnectorHelper.class); /** * This factory method creates the correct implementation of JobConnectorHelper ! * based on the given configuration which is defined in framework-config.xml file. * This looks for the following configuration and uses the class name provided * at the job-connector-helper-class-name attribute to create the helper *************** *** 68,109 **** * @return Returns the JobConnectorHelper implemenation. * * @throws ConfigurationException If configuration could not be found or * implementation class cannot be accessed or instantiated. */ ! public static synchronized JobConnectorHelper getJobConnectorHelper() { logger.trace("Entering getJobConnectorHelper"); - if(jobConnectorHelper==null) - { - FrameworkConfig.JobConnectorConfig jobConnectorConfig=FrameworkConfig.getInstance().getJobConnectorConfig(); - if(jobConnectorConfig==null) - throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "job connector configuration is not configured in framework configuration"); ! String jobConnectorHelperClassName=jobConnectorConfig.getJobConnectorHelperClassName(); ! logger.trace("Job connector helper class name = " + jobConnectorHelperClassName); ! try ! { ! jobConnectorHelper=(JobConnectorHelper)Class.forName(jobConnectorHelperClassName).newInstance(); ! jobConnectorHelper.init(jobConnectorConfig.getJobConnectorConfigProperties()); ! } ! catch(ClassNotFoundException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); ! } ! catch(InstantiationException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); ! } ! catch(IllegalAccessException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); ! } } logger.trace("Exiting getJobConnectorHelper"); return jobConnectorHelper; --- 61,106 ---- * @return Returns the JobConnectorHelper implemenation. * + * @throws SecurityException If there is any attempt to create the job connector helper by other than JobManagementAgent. * @throws ConfigurationException If configuration could not be found or * implementation class cannot be accessed or instantiated. */ ! public static synchronized JobConnectorHelper getJobConnectorHelper(JobConnectorConfig jobConnectorConfig, JobManagementAgent agent) { logger.trace("Entering getJobConnectorHelper"); ! if(!(agent instanceof JobManagementAgent)) ! throw new SecurityException("Not authorized to create the job connector helper."); ! ! if(jobConnectorConfig==null) ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "job connector configuration is not configured in framework configuration"); ! ! String jobConnectorHelperClassName=jobConnectorConfig.getJobConnectorHelperClassName(); ! logger.trace("Job connector helper class name = " + jobConnectorHelperClassName); ! ! JobConnectorHelper jobConnectorHelper=null; ! try ! { ! jobConnectorHelper=(JobConnectorHelper)Class.forName(jobConnectorHelperClassName).newInstance(); ! jobConnectorHelper.init(jobConnectorConfig.getJobConnectorConfigProperties()); ! } ! catch(ClassNotFoundException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); ! } ! catch(InstantiationException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); } + catch(IllegalAccessException exception) + { + exception.printStackTrace(); + logger.error(exception.getMessage(),exception); + throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, exception.getMessage()); + } + logger.trace("Exiting getJobConnectorHelper"); return jobConnectorHelper; |