1 25 26 package org.objectweb.easybeans.jmx; 27 28 import java.net.URL ; 29 30 import javax.management.ObjectName ; 31 32 import org.apache.commons.modeler.Registry; 33 import org.objectweb.easybeans.log.JLog; 34 import org.objectweb.easybeans.log.JLogFactory; 35 36 39 public final class CommonsModelerHelper { 40 41 44 private static Registry registry = null; 45 46 49 private static JLog logger = JLogFactory.getLog(CommonsModelerHelper.class); 50 51 54 private CommonsModelerHelper() { 55 56 } 57 58 62 public static synchronized void initRegistry() throws CommonsModelerException { 63 64 if (registry == null) { 65 registry = Registry.getRegistry(null, null); 67 68 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 69 70 try { 72 registry.loadDescriptors("org.objectweb.easybeans.deployer.management", classLoader); 74 75 registry.loadDescriptors("org.objectweb.easybeans.jsr77", classLoader); 77 78 extendsManagedBeansDescription("org.objectweb.easybeans.container.management", classLoader); 80 extendsManagedBeansDescription("org.objectweb.easybeans.container.session.stateful.management", classLoader); 81 extendsManagedBeansDescription("org.objectweb.easybeans.container.session.stateless.management", classLoader); 82 extendsManagedBeansDescription("org.objectweb.easybeans.server.management", classLoader); 83 } catch (Exception e) { 84 throw new CommonsModelerException("Cannot load descriptors of commons modeler", e); 85 } 86 87 if (logger.isDebugEnabled()) { 88 String [] managedBeans = registry.findManagedBeans(); 89 logger.debug("List of all MBeans descriptors"); 90 for (String managedBean : managedBeans) { 91 logger.debug("Found managedBean {0}.", managedBean); 92 } 93 logger.debug("End of list of all MBeans descriptors"); 94 } 95 } 96 } 97 98 108 private static void extendsManagedBeansDescription(final String packageLoc, 109 final ClassLoader classLoader) throws Exception { 110 String resource = packageLoc.replace('.', '/'); 111 URL url = classLoader.getResource(resource + "/mbeans-descriptors-ext.xml"); 112 CommonsModelerExtension.updateDescriptors(registry, url.openStream()); 113 } 114 115 121 public static Registry getRegistry() throws CommonsModelerException { 122 initRegistry(); 123 return registry; 124 } 125 126 132 public static void registerModelerMBean(final Object bean, 133 final String objectName) throws CommonsModelerException { 134 initRegistry(); 135 try { 136 registry.registerComponent(bean, objectName, null); 137 } catch (Exception e) { 138 throw new CommonsModelerException("Cannot register MBean with name '" + objectName + "'.", e); 139 } 140 } 141 142 146 public static void unregisterModelerMBean(final ObjectName on) { 147 if (registry != null) { 148 registry.unregisterComponent(on); 149 } 150 } 151 } 152 | Popular Tags |