List of usage examples for javax.management MBeanServerFactory newMBeanServer
public static MBeanServer newMBeanServer(String domain)
Return a new object implementing the MBeanServer interface with the specified default domain name, without keeping an internal reference to this new object.
From source file:com.appleframework.jmx.connector.framework.ConnectorRegistry.java
@SuppressWarnings("deprecation") private static ConnectorRegistry create(ApplicationConfig config) throws Exception { Map<String, String> paramValues = config.getParamValues(); String appId = config.getApplicationId(); String connectorId = (String) paramValues.get("connectorId"); File file1 = new File(CoreUtils.getConnectorDir() + File.separatorChar + connectorId); URL[] urls = new URL[] { file1.toURL() }; ClassLoader cl = ClassLoaderRepository.getClassLoader(urls, true); //URLClassLoader cl = new URLClassLoader(urls, // ConnectorMBeanRegistry.class.getClassLoader()); Registry.MODELER_MANIFEST = MBEANS_DESCRIPTOR; URL res = cl.getResource(MBEANS_DESCRIPTOR); logger.info("Application ID : " + appId); logger.info("Connector Archive: " + file1.getAbsoluteFile()); logger.info("MBean Descriptor : " + res.toString()); //Thread.currentThread().setContextClassLoader(cl); //Registry.setUseContextClassLoader(true); ConnectorRegistry registry = new ConnectorRegistry(); registry.loadMetadata(cl);//from ww w . j ava 2 s . c o m String[] mbeans = registry.findManagedBeans(); MBeanServer server = MBeanServerFactory.newMBeanServer(DOMAIN_CONNECTOR); for (int i = 0; i < mbeans.length; i++) { ManagedBean managed = registry.findManagedBean(mbeans[i]); String clsName = managed.getType(); String domain = managed.getDomain(); if (domain == null) { domain = DOMAIN_CONNECTOR; } Class<?> cls = Class.forName(clsName, true, cl); Object objMBean = null; // Use the factory method when it is defined. Method[] methods = cls.getMethods(); for (Method method : methods) { if (method.getName().equals(FACTORY_METHOD) && Modifier.isStatic(method.getModifiers())) { objMBean = method.invoke(null); logger.info("Create MBean using factory method."); break; } } if (objMBean == null) { objMBean = cls.newInstance(); } // Call the initialize method if the MBean extends ConnectorSupport class if (objMBean instanceof ConnectorSupport) { Method method = cls.getMethod("initialize", new Class[] { Map.class }); Map<String, String> props = config.getParamValues(); method.invoke(objMBean, new Object[] { props }); } ModelMBean mm = managed.createMBean(objMBean); String beanObjName = domain + ":name=" + mbeans[i]; server.registerMBean(mm, new ObjectName(beanObjName)); } registry.setMBeanServer(server); entries.put(appId, registry); return registry; }
From source file:org.springframework.jmx.support.MBeanServerFactoryBean.java
/** * Create a new {@code MBeanServer} instance and register it with the * {@code MBeanServerFactory}, if desired. * @param defaultDomain the default domain, or {@code null} if none * @param registerWithFactory whether to register the {@code MBeanServer} * with the {@code MBeanServerFactory}//from w ww . j a v a 2s . c o m * @see javax.management.MBeanServerFactory#createMBeanServer * @see javax.management.MBeanServerFactory#newMBeanServer */ protected MBeanServer createMBeanServer(@Nullable String defaultDomain, boolean registerWithFactory) { if (registerWithFactory) { return MBeanServerFactory.createMBeanServer(defaultDomain); } else { return MBeanServerFactory.newMBeanServer(defaultDomain); } }