[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/management JobConnectorHelper.jav
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-28 04:55:22
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2031 Modified Files: JobManagementAgent.java JobManagerMBean.java JobMonitor.java Added Files: JobConnectorHelper.java JobManager.java Removed Files: JobConnectorServerHelper.java Log Message: no message --- JobConnectorServerHelper.java DELETED --- --- NEW FILE: JobConnectorHelper.java --- /* * JobConnectorHelper.java * * Created on March 24, 2006, 8:04 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.batchserver.framework.management; import java.util.List; import java.util.Map; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorServer; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.config.FrameworkConfig; /** * <p> * 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. * <br> * <ul> * <li>Create the JMX connector server. * <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 * @version 1.0 * @since 1.0 */ public abstract class JobConnectorHelper { 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 * instance. * <br> * <pre> * <job-connector-config job-connector-helper-class-name="org.jmonks.batchserver.framework.management.jmxmp.repository.RepositoryJMXMPConnectorHelper"> * <property key="mgmt-mntr-config-key">mgmt-mntr-config-value</property> * </job-connector-config> * </pre> * * @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; } /** * This method will be called after instantiating the JobConnectorHelper to * initialize JobConnectorHelper with the properties needed to create JMX connector server * and initialize the lookup location needed to register and unregister the JMX connector servers. * * @param configProps Properties defined for this connector server as a map. * * @throws ConfigurationException If required properties for this connector server are missing. */ protected abstract void init(Map configProps); /** * Creates the JMX connector server based on the desired connector protocol. * * @return Returns the JMX connector server, null, if helper cannot create the connector server. */ public abstract JMXConnectorServer createConnectorServer(); /** * Registers the jmx connector server with the given job name in the desired lookup location. * * @param jobName Name of the job to be used in the registration. * @param jmxConnectorServer JMX connector server where all the manager and monnitor mbeans are configured. * * @return Returns true, if it successfully registred in lookup location, false, otherwise. * * @throws IllegalArgumentException If job name paramter is null. */ public abstract boolean registerConnectorServer(String jobName,JMXConnectorServer connectorServer); /** * Unregisters the jmx connector server registered in desired lookup location with the given * job name. * * @param Name of the job by which jmx connector server has been registered with. * * @return Returns true, if it successfully unregistered, false otherwise. * * @throws IllegalArgumentException If job name paramter is null. */ public abstract boolean unregisterConnectorServer(String jobName); /** * Gets all the job names registered in the lookup location. * * @return Returns the list of all the job names registered in lookup location. */ public abstract List getRegisteredJobList(); /** * Returns the JMX connector client for the given job name. * * @return Returns the JXM connector client for the given job name, * null, if it doesnt find or could not create the JMX connector client. */ public abstract JMXConnector createConnector(String jobName); } Index: JobManagerMBean.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management/JobManagerMBean.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobManagerMBean.java 25 Mar 2006 19:29:57 -0000 1.1 --- JobManagerMBean.java 28 Mar 2006 04:55:18 -0000 1.2 *************** *** 1,8 **** package org.jmonks.batchserver.framework.management; /** * <p> ! * This standard MBean, enables the controller to implementat management methods. * </p> * @author : Suresh Pragada --- 1,11 ---- package org.jmonks.batchserver.framework.management; + import org.apache.log4j.Level; + /** * <p> ! * This standard MBean interface provodes the methods to instrument the ! * job controller. * </p> * @author : Suresh Pragada *************** *** 16,20 **** * @return Returns the job status. */ ! public org.jmonks.batchserver.framework.management.JobStatus getJobStatus(); /** --- 19,23 ---- * @return Returns the job status. */ ! public JobStatus getJobStatus(); /** *************** *** 40,42 **** --- 43,64 ---- */ public boolean resume(); + + /** + * Gets the log level of the given logger name. + * + * @param loggerName Name of the logger wants to find the log level. + * + * @return Returns the log level, null, if the given logger could not be found. + */ + public Level getLogLevel(String loggerName); + + /** + * Changes the log level for the requested logger name with the given log level. + * + * @param loggerName Logger name needs to be modified. + * @param newLogLevel new logging level. + * + * @return Returns true, if log level could be changed, false, otherwise. + */ + public boolean changeLogLevel(String loggerName,Level newLogLevel); } Index: JobManagementAgent.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management/JobManagementAgent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobManagementAgent.java 25 Mar 2006 19:29:57 -0000 1.1 --- JobManagementAgent.java 28 Mar 2006 04:55:18 -0000 1.2 *************** *** 1,12 **** package org.jmonks.batchserver.framework.management; import java.io.IOException; ! import java.util.HashMap; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.remote.JMXConnectorServer; - import javax.management.remote.JMXConnectorServerFactory; - import javax.management.remote.JMXServiceURL; import org.apache.log4j.Logger; ! import org.jmonks.batchserver.framework.common.StatusCode; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.controller.JobController; --- 1,14 ---- package org.jmonks.batchserver.framework.management; import java.io.IOException; ! import javax.management.InstanceAlreadyExistsException; ! import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; + import javax.management.MalformedObjectNameException; + import javax.management.NotCompliantMBeanException; + import javax.management.ObjectName; import javax.management.remote.JMXConnectorServer; import org.apache.log4j.Logger; ! import org.jmonks.batchserver.framework.common.ErrorCode; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.controller.JobController; *************** *** 16,25 **** * <p> * JobManagementAgent defines the methods to start and stop the JMX Agent for this job. ! * Only one agent for the job will be created and this agent will be initialized * when you request to get the job management agent instance. Agent service can be * started and stopped only once during the life cycle of the job. This uses ! * the JobConnectorServerHelper to take the help in creating different JMX * connector servers and different lookup locations to ! * register and unregister jmx service urls. * </p> * @author Suresh Pragada --- 18,27 ---- * <p> * JobManagementAgent defines the methods to start and stop the JMX Agent for this job. ! * Only one agent will be created for a job and this agent will be initialized * when you request to get the job management agent instance. Agent service can be * started and stopped only once during the life cycle of the job. This uses ! * the JobConnectorHelper to take the help in creating different JMX * connector servers and different lookup locations to ! * register and unregister jmx connector servers. * </p> * @author Suresh Pragada *************** *** 50,57 **** private JMXConnectorServer jmxConnectorServer=null; /** ! * Job connector server helper instance. This defines the implementation * and lookup location of the JMX connector server. */ ! private JobConnectorServerHelper jobConnectorServerHelper=null; /** * Name of the job this agent configured for. --- 52,59 ---- private JMXConnectorServer jmxConnectorServer=null; /** ! * Job connector helper instance. This defines the implementation * and lookup location of the JMX connector server. */ ! private JobConnectorHelper jobConnectorHelper=null; /** * Name of the job this agent configured for. *************** *** 77,83 **** private JobManagementAgent() { ! this.jobConnectorServerHelper=JobConnectorServerHelper.getJobConnectorServerHelper(); ! if(jobConnectorServerHelper==null) ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "could not get the reference to job connector server helper class."); } --- 79,85 ---- 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."); } *************** *** 98,103 **** * <li>Creates the job manager and job monitor mbeans by passing the controller reference. * <li>Creates the MBeanServer and registers these two MBeans. ! * <li>Create the JMX Connector server based on the service url got from the connector server helper implementation. ! * <ii>Registers JMX Connector server service url in the lookup location defined by connector server helper implementation. * <li>Marks the started flag as true to indicate that agent has been started. * </ul> --- 100,105 ---- * <li>Creates the job manager and job monitor mbeans by passing the controller reference. * <li>Creates the MBeanServer and registers these two MBeans. ! * <li>Create the JMX Connector server based connector helper implementation. ! * <ii>Registers JMX Connector server in the lookup location defined by connector helper implementation. * <li>Marks the started flag as true to indicate that agent has been started. * </ul> *************** *** 132,143 **** { MBeanServer mbeanServer=MBeanServerFactory.createMBeanServer(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME); ! JMXServiceURL jmxServiceURL=this.jobConnectorServerHelper.getServiceURL(); ! jmxConnectorServer=JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, new HashMap(), mbeanServer); ! logger.debug("Got the jmx connector server from the implementation"); /** * Create the mbeans and register them with this mbean server. */ ! boolean registered=this.jobConnectorServerHelper.registerServiceURL(jobName,jmxServiceURL); if(registered) { --- 134,166 ---- { MBeanServer mbeanServer=MBeanServerFactory.createMBeanServer(JobManagementAgent.MBEAN_SERVER_DOMAIN_NAME); ! this.jmxConnectorServer=this.jobConnectorHelper.createConnectorServer(); ! if(this.jmxConnectorServer==null) ! { ! logger.error("Unable to get the jmx connector server from job connector helper implementation."); ! throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "Unable to get the jmx connector server from job connector helper implementation."); ! } ! else ! { ! logger.debug("Got the jmx connector server from the implementation"); ! } ! JobMonitorMBean monitorBean=new JobMonitor(jobController); ! JobManagerMBean managerBean=new JobManager(jobController); ! ! 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); ! mbeanServer.registerMBean(monitorBean, monitorBeanObjectName); ! mbeanServer.registerMBean(managerBean, managerBeanObjectName); ! /** * Create the mbeans and register them with this mbean server. */ ! boolean registered=this.jobConnectorHelper.registerConnectorServer(jobName,this.jmxConnectorServer); if(registered) { *************** *** 146,153 **** else { this.started=false; } } ! catch(IOException exception) { exception.printStackTrace(); --- 169,192 ---- else { + logger.error("Unable to register the jmx connector server using job connector helper"); this.started=false; } } ! catch(MalformedObjectNameException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! } ! catch(InstanceAlreadyExistsException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! } ! catch(MBeanRegistrationException exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! } ! catch(NotCompliantMBeanException exception) { exception.printStackTrace(); *************** *** 155,158 **** --- 194,198 ---- } + logger.trace("Exiting start"); return this.started; *************** *** 166,170 **** * * ! * @param existStatus errorCode returned by controller to the Main class. * * @return Returns true, if agent could be stopped properly, false otherwise. --- 206,210 ---- * * ! * @param exitCode errorCode returned by controller to the Main class. * * @return Returns true, if agent could be stopped properly, false otherwise. *************** *** 173,177 **** * @throws IllegalStateException If agent is already stopped or it not yet started. */ ! public boolean stop(StatusCode controllerExitStatus) { logger.trace("Entering stop"); --- 213,217 ---- * @throws IllegalStateException If agent is already stopped or it not yet started. */ ! public boolean stop(ErrorCode exitCode) { logger.trace("Entering stop"); *************** *** 182,193 **** throw new IllegalStateException("Job management agent has been stopped already."); ! if(controllerExitStatus==null) ! throw new IllegalArgumentException("controller exit status cannot be null to stop the server."); try { this.jmxConnectorServer.stop(); ! this.jobConnectorServerHelper.unregisterServiceURL(this.jobName); this.stopped=true; ! logger.debug("unregistered the jmx service url from lookup location"); } catch(IOException exception) --- 222,233 ---- 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 { this.jmxConnectorServer.stop(); ! this.jobConnectorHelper.unregisterConnectorServer(this.jobName); this.stopped=true; ! logger.debug("unregistered the jmx connector server from lookup location"); } catch(IOException exception) Index: JobMonitor.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management/JobMonitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobMonitor.java 25 Mar 2006 19:29:57 -0000 1.1 --- JobMonitor.java 28 Mar 2006 04:55:18 -0000 1.2 *************** *** 11,14 **** --- 11,16 ---- package org.jmonks.batchserver.framework.management; + import org.jmonks.batchserver.framework.controller.JobController; + /** * <p> *************** *** 23,32 **** /** ! * Creates a new instance of JobMonitorMBean b * * @param jobController Job controller implements this interface. */ public JobMonitor(JobController jobController) { this.jobMonitor=(JobMonitorMBean)jobController; } --- 25,38 ---- /** ! * Creates a new instance of JobMonitorMBean and initializes with job controller. * * @param jobController Job controller implements this interface. + * + * @throws IllegalArgumentException if input argument job controller is null. */ public JobMonitor(JobController jobController) { + if(jobController==null) + throw new IllegalArgumentException("job controller cannot be null to create the job monitor mbean."); this.jobMonitor=(JobMonitorMBean)jobController; } *************** *** 37,41 **** public int getExpectedRecordsCount() { ! return 0; } /** --- 43,47 ---- public int getExpectedRecordsCount() { ! return this.jobMonitor.getExpectedRecordsCount(); } /** *************** *** 44,48 **** public int getProcessedRecordsCount() { ! return 0; } /** --- 50,54 ---- public int getProcessedRecordsCount() { ! return this.jobMonitor.getProcessedRecordsCount(); } /** *************** *** 51,55 **** public String[] getThreadIDList() { ! return null; } /** --- 57,61 ---- public String[] getThreadIDList() { ! return this.jobMonitor.getThreadIDList(); } /** *************** *** 58,62 **** public ThreadState getThreadState(String threadID) { ! return null; } } --- 64,68 ---- public ThreadState getThreadState(String threadID) { ! return this.jobMonitor.getThreadState(threadID); } } --- NEW FILE: JobManager.java --- /* * JobManager.java * * Created on March 25, 2006, 11:14 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.batchserver.framework.management; import org.apache.log4j.Level; import org.jmonks.batchserver.framework.controller.JobController; /** * <p> * JobManager instruments the job controller for management purposes. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class JobManager implements JobManagerMBean { private JobManagerMBean jobManager=null; /** * Creates a new instance of JobManagerMBean and initializes with job controller. * * @param jobController Job controller implements this interface. * * @throws IllegalArgumentException if input argument job controller is null. */ public JobManager(JobController jobController) { if(jobController==null) throw new IllegalArgumentException("job controller cannot be null to create the job monitor mbean."); this.jobManager=(JobManagerMBean)jobController; } /** * Controller should stop its processing as soon this method call has been * received. If the restart flag is true, it persist the controller to the repository. * * @param restart Tells whether job needs to be restarted or not. * * @return Returns whether job can be stopped or not. */ public boolean stop(boolean restart) { return this.jobManager.stop(restart) ; } /** * Controller should suspend its processing as soon as its receive this method call. * * @return Returns true, if controller can suspend the process, false otherwise. */ public boolean suspend() { return this.jobManager.suspend(); } /** * Controller should resume its processing as soon as it receive this method call. * * @return Returns true, if controller can resume the processing, false, otherwise. */ public boolean resume() { return this.jobManager.resume(); } /** * Returns the status of the job. These statuses are defined as constants in JobManagerMBean. * * @return Returns the job status. */ public JobStatus getJobStatus() { return this.jobManager.getJobStatus(); } /** * Gets the log level of the given logger name. * * @param loggerName Name of the logger wants to find the log level. * * @return Returns the log level, null, if the given logger could not be found. */ public Level getLogLevel(String loggerName) { return this.jobManager.getLogLevel(loggerName); } /** * Changes the log level for the requested logger name with the given log level. * * @param loggerName Logger name needs to be modified. * @param newLogLevel new logging level. * * @return Returns true, if log level could be changed, false, otherwise. */ public boolean changeLogLevel(String loggerName, Level newLogLevel) { return this.jobManager.changeLogLevel(loggerName, newLogLevel); } } |