1 24 package org.objectweb.jonas.jmx; 25 26 import java.util.List ; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MBeanServerFactory ; 30 import javax.management.remote.JMXServiceURL ; 31 import javax.naming.Context ; 32 import javax.naming.NamingException ; 33 34 import org.objectweb.jonas.common.Log; 35 import org.objectweb.jonas.service.AbsServiceImpl; 36 import org.objectweb.jonas.service.ServiceException; 37 import org.objectweb.util.monolog.api.BasicLevel; 38 import org.objectweb.util.monolog.api.Logger; 39 40 48 49 public abstract class AbsJmxServiceImpl extends AbsServiceImpl implements JmxService { 50 51 54 private static Logger logger = null; 55 56 59 protected static Logger getLogger() { 60 return logger; 61 } 62 63 66 private MBeanServer jmxServer = null; 67 68 74 public void doInit(Context ctx) throws ServiceException { 75 logger = Log.getLogger(Log.JONAS_JMX_PREFIX); 76 super.initLogger(Log.getLogger(Log.JONAS_MANAGEMENT_PREFIX)); 77 78 80 String idMBeanServer = null; 82 try { 83 idMBeanServer = (String ) ctx.lookup("idMBeanServer"); 84 } catch (NamingException ne) { 85 throw new ServiceException("Cannot found the id of the MBean Server", ne); 86 } 87 88 List mbeanServers = MBeanServerFactory.findMBeanServer(idMBeanServer); 90 if (mbeanServers.size() == 0) { 91 throw new ServiceException("No MBean server found for id '" + idMBeanServer + "'."); 92 } 93 if (logger.isLoggable(BasicLevel.DEBUG)) { 94 logger.log(BasicLevel.DEBUG, "Use first MBean server ID found"); 95 } 96 jmxServer = (MBeanServer ) mbeanServers.get(0); 97 98 if (logger.isLoggable(BasicLevel.DEBUG)) { 99 logger.log(BasicLevel.DEBUG, "JMX Service initialized"); 100 } 101 } 102 103 107 public abstract void doStart() throws ServiceException; 108 109 113 public abstract void doStop() throws ServiceException; 114 115 public abstract JMXServiceURL [] getConnectorServerURLs(); 116 117 120 public MBeanServer getJmxServer() { 121 return this.jmxServer; 122 } 123 124 127 protected void releaseJmxServer() { 128 try { 129 MBeanServerFactory.releaseMBeanServer(jmxServer); 130 } catch (java.lang.IllegalArgumentException ex) { 131 logger.log(BasicLevel.ERROR, "Cannot find the MBeanServer" + ex); 133 } 134 } 135 136 } | Popular Tags |