Example usage for java.lang.management ManagementFactory getPlatformMBeanServer

List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getPlatformMBeanServer.

Prototype

public static synchronized MBeanServer getPlatformMBeanServer() 

Source Link

Document

Returns the platform javax.management.MBeanServer MBeanServer .

Usage

From source file:org.openmrs.module.jmx.impl.JMXServiceImpl.java

/**
 * @see org.openmrs.module.jmx.JMXService#registerBean(String, Object)
 *///from  w w w .  j a  va 2 s .  c o m
@Override
public void registerMBean(String folder, String name, Object mbean) {
    Object proxiedBean = MBeanProxifier.getProxy(mbean);

    try {
        ObjectName objName = getObjectName(folder, name);
        MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        if (beanServer.isRegistered(objName))
            beanServer.unregisterMBean(objName);

        beanServer.registerMBean(proxiedBean, objName);

        log.debug("Registered MBean: " + objName.toString());

    } catch (MalformedObjectNameException e) {
        log.error("Invalid MBean name", e);
    } catch (Exception e) {
        log.error("Unable to register MBean", e);
    }
}

From source file:org.apache.synapse.transport.passthru.jmx.MBeanRegistrar.java

public void registerMBean(Object mBeanInstance, String category, String id) throws AxisFault {
    assertNull(mBeanInstance, "MBean instance is null");
    assertNull(category, "MBean instance category is null");
    assertNull(id, "MBean instance name is null");
    try {//w ww  . j  a  va  2s .  co m
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(getObjectName(category, id));
        Set set = mbs.queryNames(name, null);
        if (set != null && set.isEmpty()) {
            mbs.registerMBean(mBeanInstance, name);
        } else {
            mbs.unregisterMBean(name);
            mbs.registerMBean(mBeanInstance, name);
        }
    } catch (Exception e) {
        log.warn("Error registering a MBean with name ' " + id + " ' and category name ' " + category
                + "' for JMX management", e);
    }
}

From source file:com.buschmais.maexo.test.server.factory.ServerFactoryTest.java

@Override
protected void preProcessBundleContext(BundleContext platformBundleContext) throws Exception {
    // getting the platform MBean server registers an instance in the MBean server factory 
    ManagementFactory.getPlatformMBeanServer();
    super.preProcessBundleContext(platformBundleContext);
}

From source file:org.apache.synapse.commons.jmx.MBeanRegistrar.java

public boolean registerMBean(Object mBeanInstance, String category, String id) {
    assertNull(mBeanInstance, "MBean instance is null");
    assertNull(category, "MBean instance category is null");
    assertNull(id, "MBean instance name is null");
    try {// w  w  w .j a  va  2 s.  c o m
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(getObjectName(category, id));
        Set set = mbs.queryNames(name, null);
        if (set != null && set.isEmpty()) {
            mbs.registerMBean(mBeanInstance, name);
        } else {
            mbs.unregisterMBean(name);
            mbs.registerMBean(mBeanInstance, name);
        }
        return true;
    } catch (Exception e) {
        log.warn("Error registering a MBean with name ' " + id + " ' and category name ' " + category
                + "' for JMX management", e);
        return false;
    }
}

From source file:com.alibaba.dragoon.client.DragoonClientStandardMBeanProviderFilter.java

@Override
public void start(DaemonServiceLifeCycleFilterChain chain) {
    try {/*from w w w.j  a  va  2 s. c om*/
        standardMBeanProvider.register(ManagementFactory.getPlatformMBeanServer());
    } catch (JMException e) {
        LOG.error("start error", e);
    }

    chain.start();
}

From source file:com.cisco.cta.taxii.adapter.AdapterConfigurationTest.java

@Test
public void jmxStatisticsRegistered() throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("com.cisco.cta.taxii:component=taxii-log-adapter,type=statistics");
    assertTrue(mbs.isRegistered(name));//  www .ja  v  a  2s.co m
}

From source file:org.jumpmind.metl.StartWebServer.java

public static void runWebServer() throws Exception {

    disableJettyLogging();// www .j  a v a2  s . co m

    System.out.println(IOUtils.toString(StartWebServer.class.getResource("/Metl.asciiart")));

    Server server = new Server(PORT);

    ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
            "org.eclipse.jetty.annotations.AnnotationConfiguration");

    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);

    ProtectionDomain protectionDomain = StartWebServer.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    File locationDir = new File(location.getFile()).getParentFile();

    WebAppContext webapp = new WebAppContext();

    //        HashSessionManager sessionManager = new HashSessionManager();
    //        File storeDir = new File(locationDir, "sessions");
    //        storeDir.mkdirs();
    //        sessionManager.setStoreDirectory(storeDir);
    //        sessionManager.setLazyLoad(true);
    //        sessionManager.setSavePeriod(5);
    //        sessionManager.setDeleteUnrestorableSessions(true);        
    //        SessionHandler sessionHandler = new SessionHandler(sessionManager);
    //        webapp.setSessionHandler(sessionHandler);

    webapp.setContextPath("/metl");
    webapp.setWar(location.toExternalForm());
    webapp.addAliasCheck(new AllowSymLinkAliasChecker());

    File pluginsDir = new File(locationDir, "plugins");
    pluginsDir.mkdirs();
    StringBuilder extraClasspath = new StringBuilder();
    File[] files = pluginsDir.listFiles();
    Arrays.sort(files);
    for (File file : files) {
        if (file.isFile() && file.getName().endsWith(".jar")) {
            extraClasspath.append(file.toURI().toURL().toExternalForm()).append(",");
        }
    }
    webapp.setExtraClasspath(extraClasspath.toString());

    server.setHandler(webapp);

    ServerContainer webSocketServer = WebSocketServerContainerInitializer.configureContext(webapp);
    webSocketServer.setDefaultMaxSessionIdleTimeout(10000000);

    server.start();

    if (extraClasspath.length() > 0) {
        getLogger().info("Adding extra classpath of: " + extraClasspath.toString());
    }
    getLogger().info("To use Metl, navigate to http://localhost:" + PORT + "/metl");

    server.join();
}

From source file:org.skfiy.typhon.jmx.BuiltinJmxListener.java

@Override
public void execute(LifecycleEvent event) {
    if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getEvent())) {

        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        Registry.getRegistry(null, null).setMBeanServer(mbs);
    } else if (Lifecycle.AFTER_INIT_EVENT.equals(event.getEvent())) {
        // Ensure cryptographically strong random number generator used
        // to choose the object number - see java.rmi.server.ObjID
        ////  w  ww  .j a  v a 2  s .co m
        System.setProperty("java.rmi.server.randomIDs", "true");

        // Start an RMI registry on port.
        try {
            LocateRegistry.createRegistry(port);
            LOG.info("Create RMI registry on port {}", port);
        } catch (RemoteException ex) {
            LOG.error("Create RMI registry error", ex);
            throw new TyphonException(ex);
        }

        Map<String, Object> env = new HashMap<>();

        // Provide the password file used by the connector server to
        // perform user authentication. The password file is a properties
        // based text file specifying username/password pairs.
        //
        // File file = new File(System.getProperty("typhon.home"), "bin/jmxremote.password");
        // env.put("com.sun.management.jmxremote.password.file", file.getAbsolutePath());

        try {
            jcs = JMXConnectorServerFactory.newJMXConnectorServer(newUrl(), env,
                    ManagementFactory.getPlatformMBeanServer());
            jcs.start();
        } catch (IOException ex) {
            LOG.error("start JMXConnectorServer...", ex);
            throw new TyphonException(ex);
        }
    } else if (Lifecycle.AFTER_DESTROY_EVENT.equals(event.getEvent())) {
        if (jcs != null) {
            try {
                jcs.stop();
            } catch (IOException ex) {
                LOG.error("stop JMXConnectorServer...", ex);
                throw new TyphonException(ex);
            }
        }
    }
}

From source file:org.wso2.carbon.andes.cluster.mgt.internal.managementBeans.ClusterManagementBeans.java

/**
 * Checks whether clustering is enabled/*  w w w.ja v  a2s. c o m*/
 *
 * @return a boolean whether clustering is enabled
 * @throws ClusterMgtException
 */
public boolean isClusteringEnabled() throws ClusterMgtException {
    boolean isClustered = false;
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName objectName = new ObjectName(
                "org.wso2.andes:type=ClusterManagementInformation," + "name=ClusterManagementInformation");
        Object result = mBeanServer.getAttribute(objectName, ClusterMgtConstants.IS_CLUSTERING_ENABLED);

        if (result != null) {
            isClustered = (Boolean) result;
        }

        return isClustered;
    } catch (MalformedObjectNameException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (InstanceNotFoundException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (ReflectionException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (AttributeNotFoundException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    } catch (MBeanException e) {
        throw new ClusterMgtException("Cannot access cluster information", e);
    }
}

From source file:com.facio.MainConfig.java

@Bean
public EhCacheCacheManager ehCacheManager() {
    URL url = getClass().getResource("/ehcache.xml");
    LOG.debug("ecache url=" + url);

    CacheManager cacheManager = CacheManager.newInstance(url);
    LOG.debug(" === registering MBeanServer === ");
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);
    return new EhCacheCacheManager(cacheManager);
}