[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/management JobConnectorServerHelp
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-25 19:30:03
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26476 Added Files: JobConnectorServerHelper.java JobManagementAgent.java JobManagerMBean.java JobMonitor.java JobMonitorMBean.java JobStatus.java ThreadState.java Log Message: no message --- NEW FILE: JobMonitorMBean.java --- package org.jmonks.batchserver.framework.management; /** * <p> * JobMonitorMBean interface defines the methods to instrument the job being run * to find out the statistics of the job and to find out all the thread states * running in the controller. This follows the JMX standard MBean paradigm to define * name of the MBean and methods instrument the job. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public interface JobMonitorMBean { /** * Gets the total number of records this job might try to process. * * @return Returns the total number of records this job might try to process. */ public int getExpectedRecordsCount(); /** * Gets the records processed by this job so far. * * @return Returns the number of records processed by this job so far. */ public int getProcessedRecordsCount(); /** * Returns the number of threads being run by this job. * * @return Returns the number of threads being run by this job. */ public String[] getThreadIDList(); /** * Gets the state of this thread. This returns the state in a ThreadState object. * * @return Returns the state of this thread. */ public ThreadState getThreadState(String threadID); } --- NEW FILE: JobConnectorServerHelper.java --- /* * JobConnectorServerHelper.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.Map; import javax.management.remote.JMXServiceURL; import org.apache.log4j.Logger; import org.jmonks.batchserver.framework.config.ConfigurationException; import org.jmonks.batchserver.framework.config.FrameworkConfig; /** * <p> * JobConnectorServerHelper defines the helper methods used while creating the JMX * connector server and registering and unregistering the JMX Service URL in the * lookup location. Because of many possible implementations available in creating * the JMX connector server and lookup location, 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 * server helper class. * <br> * <ul> * <li>Return the JMX Service URL to create the JMX connector server. * <li>Register the given the JMX Service URL in the lookup location with the given jobname. * <li>Unregister the JMX Service URL available in lookup location with the given jobname. * </ul> * <br> * This class provides the factory method to return the configured JobConnectorServerHelper * instance by looking at the framework configuration and make sure only one * instance will be created for the job. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JobConnectorServerHelper { private static Logger logger=Logger.getLogger(JobConnectorServerHelper.class); /** * Singleton job connector server helper instance. */ private static JobConnectorServerHelper jobConnectorServer=null; /** * This factory method creates the correct implementation of JobConnectorServerHelper * 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-server-helper-class-name attribute to create the server helper * instance. * <br> * <pre> * <job-connector-config job-connector-server-helper-class-name="org.jmonks.batchserver.framework.management.jmxmp.repository.RepositoryJMXMPJobConnectorServer"> * <property key="mgmt-mntr-config-key">mgmt-mntr-config-value</property> * </job-connector-config> * </pre> * * @return Returns the JobConnectorServerHelper implemenation. * * @throws ConfigurationException If configuration could not be found or * implementation class cannot be accessed or instantiated. */ public static synchronized JobConnectorServerHelper getJobConnectorServerHelper() { logger.trace("Entering getJobConnectorServerHelper"); if(jobConnectorServer!=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 jobConnectorServerHelperClassName=jobConnectorConfig.getJobConnectorServerHelperClassName(); logger.trace("Job connector server helper class name = " + jobConnectorServerHelperClassName); try { jobConnectorServer=(JobConnectorServerHelper)Class.forName(jobConnectorServerHelperClassName).newInstance(); jobConnectorServer.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 getJobConnectorServerHelper"); return jobConnectorServer; } /** * This method will be called after instantiating the JobConnectorServerHelper to * initialize JobConnectorServerHelper with the properties needed to create JMX Service URL * and initialize the lookup location needed to register and unregister the JMX Service URL . * * @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 Service URL based on the desired protocol. * * @return Returns the JMX Service URL, null, if helper cannot create the URL. */ public abstract JMXServiceURL getServiceURL(); /** * Registers the jmx service url with the given job name in the desired lookup location. * * @param jobName Name of the job to be used in the registration. * @param jmxServiceURL JMX service url identifies the 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 registerServiceURL(String jobName,JMXServiceURL jmxServiceURL); /** * Unregisters the jmx service url registered in desired lookup location with the given * job name. * * @param Name of the job mgmt and mntr information has been registered with. * * @return Returns true, if it successfully unregistered, false otherwise. * * @throws IllegalArgumentException If job name paramter is null. */ public abstract boolean unregisterServiceURL(String jobName); } --- NEW FILE: JobManagerMBean.java --- package org.jmonks.batchserver.framework.management; /** * <p> * This standard MBean, enables the controller to implementat management methods. * </p> * @author : Suresh Pragada * @versio 1.0 */ public interface JobManagerMBean { /** * Returns the status of the job. These statuses are defined as constants in JobManagerMBean. * * @return Returns the job status. */ public org.jmonks.batchserver.framework.management.JobStatus getJobStatus(); /** * 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); /** * 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(); /** * 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(); } --- NEW FILE: JobManagementAgent.java --- 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; /** * <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 * @version 1.0 * @since 1.0 */ public class JobManagementAgent { /** * Mbean Server domain name. */ public static final String MBEAN_SERVER_DOMAIN_NAME = "EnterpriseBatchServer"; /** * Name of the bean that manages this job. */ public static final String JOB_MANAGER_MBEAN_NAME = "JobManagerMBean"; /** * Name of the bean monitors this job. */ 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. */ 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. */ private String jobName=null; /** * Tells whether the agent has been started or not. */ private boolean started=false; /** * Tells whether the agent has been stopped or not. */ private boolean stopped=false; private static Logger logger=Logger.getLogger(JobManagementAgent.class); /** * 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.jobConnectorServerHelper=JobConnectorServerHelper.getJobConnectorServerHelper(); if(jobConnectorServerHelper==null) throw new ConfigurationException(ConfigurationException.JOB_CONNECTOR_CONFIG, "could not get the reference to job connector server helper class."); } /** * Returns the job management agent instance. */ public static JobManagementAgent getJobManagementAgent() { return jobManagementAgent; } /** * <p> * This method start the job management agent with the given controller information. * Basicially, this does the following activities to start the management agent. * <br> * <ul> * <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> * <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 jobName Name of the job the controller belongs to. * @param jobController Controller reference to be passed to the mbeans. * * @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 or already stopped. */ public boolean start(String jobName,JobController jobController) { logger.trace("Entering start"); if(this.started) throw new IllegalStateException("job management agent has been already started."); if(this.stopped) throw new IllegalStateException("job management agent has been already stopped."); if(jobName==null || "".equals(jobName)) throw new IllegalArgumentException("job name cannot be null or empty 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=jobName; try { 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) { this.started=true; } else { this.started=false; } } catch(IOException exception) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); } logger.trace("Exiting start"); return this.started; } /** * Stops the JMX connector server, unregisters the MBeans and MBeanServer and * unregisters the jmx service url information from lookup location and marks * stopped flag as true to indicate that agent has been stopped. Given controller * exit status will be sent to all the JMX remote clients as a notification. * * * @param existStatus 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(StatusCode controllerExitStatus) { logger.trace("Entering stop"); if(!this.started) throw new IllegalStateException("Job management agent has not been started."); if(this.stopped) 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) { exception.printStackTrace(); logger.error(exception.getMessage(),exception); this.stopped=false; } logger.trace("Exiting stop"); return this.stopped; } } --- NEW FILE: JobMonitor.java --- /* * JobMonitor.java * * Created on March 25, 2006, 1: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.batchserver.framework.management; /** * <p> * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class JobMonitor implements JobMonitorMBean { private JobMonitorMBean jobMonitor=null; /** * Creates a new instance of JobMonitorMBean b * * @param jobController Job controller implements this interface. */ public JobMonitor(JobController jobController) { this.jobMonitor=(JobMonitorMBean)jobController; } /** * @see org.jmonks.batchserver.framework.management.JobMonitorMBean#getExpectedRecordsCount */ public int getExpectedRecordsCount() { return 0; } /** * @see org.jmonks.batchserver.framework.management.JobMonitorMBean#getProcessedRecordsCount */ public int getProcessedRecordsCount() { return 0; } /** * @see org.jmonks.batchserver.framework.management.JobMonitorMBean#getThreadIDList */ public String[] getThreadIDList() { return null; } /** * @see org.jmonks.batchserver.framework.management.JobMonitorMBean#getThreadState(java.lang.String) */ public ThreadState getThreadState(String threadID) { return null; } } --- NEW FILE: ThreadState.java --- package org.jmonks.batchserver.framework.management; /** * <p> * This represents the state of the thread. * This gives the information like thread ID, description and * processing information. * </p> * @author Suresh pragada * @version 1.0 * @since 1.0 */ public class ThreadState { /** * Holds the thread ID. */ private String threadID; /** * Holds the thread description. */ private String threadDescription; /** * Holds the processing information. This can be anything that client and server * can understand. */ private Object processingInfo; /** * Constructor to initialize the whole object at a time and make sure it is immutable. */ public ThreadState(String threadID,String threadDescription,String processingInfo) { this.threadID=threadID; this.threadDescription=threadDescription; this.processingInfo=processingInfo; } /** * Returns the thread ID. */ public String getThreadID() { return this.threadID; } /** * Returns the thread description. */ public String getThreadDescription() { return this.threadDescription; } /** * Returns the thread processing information. */ public Object getProcessingInfo() { return this.processingInfo; } /** * <p> * Returns the string representation of ThreadState class in the format * <br> {ThreadState [ID = value] [desc = value] [processingInfo = value]} * </p> * * @return Returns the string representation of ThreadState. */ public String toString() { StringBuffer stringValue=new StringBuffer("{ThreadState "); stringValue.append("[ID = " + this.threadID + "]"); stringValue.append("[desc = " + this.threadDescription + "]"); stringValue.append("[processingInfo = " + this.processingInfo + "]"); stringValue.append("}"); return stringValue.toString(); } } --- NEW FILE: JobStatus.java --- package org.jmonks.batchserver.framework.management; /** * <p> * JobStatus class defines the available statuses of the jobs in the system as * enums. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class JobStatus { /** * Status indicates that job is running. */ public static JobStatus RUNNING = new JobStatus("RUNNING"); /** * Status indictes that job is suspended. */ public static JobStatus SUSPENDED = new JobStatus("SUSPENDED"); /** * Status indicates the job is stopped. */ public static JobStatus STOPPED = new JobStatus("STOPPED"); /** * Status indicates the job is resumed. */ public static JobStatus RESUMED = new JobStatus("RESUMED"); /** * Varaible holds the status ID. */ private String statusID; /** * Constructor make sure all the constants have been defined inside this * class and takes the status ID. */ private JobStatus(String statusID) { this.statusID=statusID; } /** * Returns the job status in string format. */ public String toString() { return this.statusID; } } |