[Batchserver-cvs] batchserver/src/org/jmonks/batch/framework/management/jmxmp JMXMPConnectorHelper
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 20:07:12
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batch/framework/management/jmxmp In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20312 Added Files: JMXMPConnectorHelper.java RepositoryJMXMPConnectorHelper.java Log Message: no message --- NEW FILE: RepositoryJMXMPConnectorHelper.java --- package org.jmonks.batch.framework.management.jmxmp; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXServiceURL; import org.apache.log4j.Logger; import org.jmonks.batch.framework.JobContext; import org.jmonks.batch.framework.Repository; /** * <p> * This connector is based on JMX Messaging protocol and uses the framework * reposiotry as the lookup location to register and unregister the JMX Service URL. * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class RepositoryJMXMPConnectorHelper extends JMXMPConnectorHelper { private static Logger logger=Logger.getLogger(RepositoryJMXMPConnectorHelper.class); /** * @see org.jmonks.batch.framework.management.JobConnectorHelper@init(java.util.Map) */ public void init(java.util.Map configProps) { logger.trace("Entering init") ; /** * Because this uses the repository, defined for this framework as the * lookup location, this implementation does not require any properties * in configuration file to initialize the lookup location. */ logger.trace("Exiting init") ; } /** * Registers the jmx connector server with the job name taken from job context in the repository * defined for this framework. Repository reference will also be taken from job context. * * @param jobContext Context of the job is being run. * @param jmxConnectorServer JMX connector server identifies where all the manager and montiro mbeans are configured. * * @return Returns true, if it successfully registred in repository, false, otherwise. * * @throws IllegalArgumentException If job name paramter or jmxConnectorServer parameter is null. */ public boolean registerConnectorServer(JobContext jobContext,JMXConnectorServer jmxConnectorServer) { logger.trace("Entering registerConnectorServer") ; if(jobContext==null) throw new IllegalArgumentException("job context cannot be null to registerd jmx service url."); if(jmxConnectorServer==null) throw new IllegalArgumentException("jmx connector server cannot be null to registerd jmx connector server."); /** * By default repository will be associated with the job. So we can ignore the jobName here. */ JMXServiceURL jmxServiceURL=jmxConnectorServer.getAddress(); boolean registered=jobContext.getRepository().registerJobMgmtMntrInfo(jmxServiceURL.toString()); logger.info(jobContext.getJobName() + " with the service url " + jmxServiceURL.toString() + " registered in repository = " + registered); logger.trace("Exiting registerConnectorServer") ; return registered; } /** * Unregisters the jmx connector server registered in repository with the * job name available in job context. * * @param jobContext Context of the job is begin run. * * @return Returns true, if it successfully unregistered, false otherwise. * * @throws IllegalArgumentException If job name paramter is null. */ public boolean unregisterConnectorServer(JobContext jobContext) { logger.trace("Entering unregisterConnectorServer"); if(jobContext==null) throw new IllegalArgumentException("job context cannot be null to unregister the service url."); /** * By default repository will be associated with the job. So we can ignore the jobName here. */ boolean unregistered=jobContext.getRepository().unregisterJobMgmtMntrInfo(); logger.debug(jobContext.getJobName() + " mgmt and mntr information unregistered = " + unregistered); logger.trace("Exiting unregisterConnectorServer") ; return unregistered; } } --- NEW FILE: JMXMPConnectorHelper.java --- /* * JMXMPConnectorHelper.java * * Created on March 22, 2006, 9:27 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.batch.framework.management.jmxmp; import java.io.IOException; import java.net.MalformedURLException; import java.util.HashMap; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; import org.apache.log4j.Logger; import org.jmonks.batch.framework.management.JobConnectorHelper; /** * <p> * JMXMPConnectorHelper creates the JMX connector server based on the JMX Messaging * protocol and leaves the lookup location details to the class going to implement this * abstract class. The machine the job being run will be used as the host name and * the port will be selected automatically by the JMX connector server factory. * </p> * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public abstract class JMXMPConnectorHelper extends JobConnectorHelper { private static Logger logger=Logger.getLogger(JMXMPConnectorHelper.class); /** * JMX Messaging Protocol URL to be used to create the connector server. */ private static final String JMXMP_SERVICE_URL = "service:jmx:jmxmp://"; /** * Creates the JMX connector server based on JMX Messaging protocol. This does * not defined the host name and port name in the URL. So, the machine job * being run will be used as the host and port will be automatically choosen. * * @return Returns the JMX connector server, null, if it cannot create the connector server. */ public JMXConnectorServer createConnectorServer() { JMXServiceURL jmxServiceURL=null; JMXConnectorServer jmxConnectorServer=null; try { jmxServiceURL=new JMXServiceURL(JMXMPConnectorHelper.JMXMP_SERVICE_URL); jmxConnectorServer=JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, new HashMap(), null); } catch(MalformedURLException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); } catch(IOException exception) { exception.printStackTrace(); logger.error(exception.getMessage(), exception); } return jmxConnectorServer; } } |