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.wso2.carbon.andes.cluster.mgt.internal.managementBeans.ClusterManagementBeans.java

/**
 * Gets the coordinator node's host address and port in a cluster
 *
 * @return The coordinator node's host address and port
 * @throws ClusterMgtException//  w  w w.  j a v  a 2  s. co  m
 */
public String getCoordinatorNodeAddress() throws ClusterMgtException {
    String coordinatorNodeAddress = StringUtils.EMPTY;
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName objectName = new ObjectName(
                "org.wso2.andes:type=ClusterManagementInformation," + "name=ClusterManagementInformation");
        Object result = mBeanServer.getAttribute(objectName, ClusterMgtConstants.COORDINATOR_NODE_ADDRESS);
        if (result != null) {
            coordinatorNodeAddress = (String) result;
        }
        return coordinatorNodeAddress;

    } catch (MalformedObjectNameException e) {
        throw new ClusterMgtException("Cannot get coordinator node address. Check if clustering is enabled.",
                e);
    } catch (ReflectionException e) {
        throw new ClusterMgtException("Cannot get coordinator node address. Check if clustering is enabled.",
                e);
    } catch (MBeanException e) {
        throw new ClusterMgtException("Cannot get coordinator node address. Check if clustering is enabled.",
                e);
    } catch (InstanceNotFoundException e) {
        throw new ClusterMgtException("Cannot get coordinator node address. Check if clustering is enabled.",
                e);
    } catch (AttributeNotFoundException e) {
        throw new ClusterMgtException("Cannot get coordinator node address. Check if clustering is enabled.",
                e);
    }
}

From source file:org.apache.hadoop.jmx.JMXJsonServlet.java

/**
 * Initialize this servlet./*ww w . j  av a  2  s. co m*/
 */
@Override
public void init() throws ServletException {
    // Retrieve the MBean server
    mBeanServer = ManagementFactory.getPlatformMBeanServer();
}

From source file:org.onehippo.forge.channelmanager.pagesupport.channel.event.DocumentManagementServiceClient.java

public MBeanServer getMbeanServer() {
    if (mbeanServer == null) {
        mbeanServer = ManagementFactory.getPlatformMBeanServer();
    }

    return mbeanServer;
}

From source file:dk.dma.ais.reader.AisReaders.java

public static void manageGroup(AisReaderGroup group) throws JMException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName mxbeanName = new ObjectName("dk.dma.ais.readers.group." + group.name + ":name=Group");
    mbs.registerMBean(new AisReaderGroupMXBeanImpl(group), mxbeanName);
    for (AisTcpReader r : group.readers.values()) {
        mxbeanName = new ObjectName(
                "dk.dma.ais.readers.group." + group.name + ":source=Source-" + r.getSourceId());
        mbs.registerMBean(new AisReaderMXBeanImpl(r), mxbeanName);

    }//from   ww  w  .  ja  v a  2 s.  c om
}

From source file:org.sakaiproject.nakamura.memory.CacheManagerServiceImpl.java

private void create() throws IOException {
    LOGGER.info("Loading Resource using " + this.getClass().getClassLoader());
    LOGGER.info("Locally Stream was " + this.getClass().getClassLoader().getResourceAsStream(CONFIG_PATH));
    InputStream in = ResourceLoader.openResource(CONFIG_PATH, this.getClass().getClassLoader());
    cacheManager = new CacheManager(in);
    in.close();//  w ww.  ja  v  a2s. c  om

    /*
     * Add in a shutdown hook, for safety
     */
    Runtime.getRuntime().addShutdownHook(new Thread() {
        /*
         * (non-Javadoc)
         *
         * @see java.lang.Thread#run()
         */
        @Override
        public void run() {
            try {
                CacheManagerServiceImpl.this.stop();
            } catch (Throwable t) {

                // I really do want to swallow this, and make the shutdown clean for
                // others
            }
        }
    });

    // register the cache manager with JMX
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);

}

From source file:io.fabric8.insight.log.support.LogQuerySupport.java

public MBeanServer getMbeanServer() {
    if (mbeanServer == null) {
        mbeanServer = ManagementFactory.getPlatformMBeanServer();
    }
    return mbeanServer;
}

From source file:org.red5.server.scheduling.ApplicationSchedulingService.java

protected void unregisterJMX() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {//  ww w .j  a v  a  2s .  c  o m
        ObjectName oName = null;
        if (instanceId == null) {
            oName = new ObjectName(
                    "org.red5.server:type=ApplicationSchedulingService,applicationName=" + applicationName);
        } else {
            oName = new ObjectName("org.red5.server:type=ApplicationSchedulingService,applicationName="
                    + applicationName + ",instanceId=" + instanceId);
        }
        mbs.unregisterMBean(oName);
    } catch (Exception e) {
        log.warn("Exception unregistering", e);
    }
}

From source file:org.codice.ddf.resourcemanagement.usage.service.DataUsage.java

private void registerMbean() {
    try {//  ww  w  . ja  v  a 2  s .com
        objectName = new ObjectName(DataUsage.class.getName() + ":service=datausage");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.error("Unable to create Data Usage Configuration MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Registered Data Usage Configuration MBean under object name: {}",
                    objectName.toString());
        } catch (InstanceAlreadyExistsException e) {
            // Try to remove and re-register
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Re-registered Data Usage Configuration MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException
            | NotCompliantMBeanException e) {
        LOGGER.error("Could not register MBean [{}].", objectName.toString(), e);
    }

}

From source file:org.jolokia.jmx.JolokiaMBeanServerTest.java

@Test
public void withModelMBean() throws MBeanException, InvalidTargetObjectTypeException, InstanceNotFoundException,
        InstanceAlreadyExistsException, NotCompliantMBeanException, MalformedObjectNameException,
        NoSuchMethodException, IntrospectionException {

    RequiredModelMBean modelMBean = new RequiredModelMBean();

    ModelMBeanInfo mbi = new ModelMBeanInfoSupport(JsonAnnoPlainTest.class.getName(), "JsonMBean Test",
            new ModelMBeanAttributeInfo[] { new ModelMBeanAttributeInfo("DeepDive", "description",
                    JsonAnnoPlainTest.class.getDeclaredMethod("getDeepDive"), null) },
            new ModelMBeanConstructorInfo[] {}, new ModelMBeanOperationInfo[] {},
            new ModelMBeanNotificationInfo[] {});
    modelMBean.setModelMBeanInfo(mbi);/*from  w  ww .j  av  a  2  s  . com*/
    modelMBean.setManagedResource(new JsonAnnoPlainTest(), "ObjectReference");

    JolokiaMBeanServer server = new JolokiaMBeanServer();

    ObjectName oName = new ObjectName("test:type=jsonMBean");

    server.registerMBean(modelMBean, oName);
    MBeanServer plattformServer = ManagementFactory.getPlatformMBeanServer();

    Assert.assertTrue(plattformServer.isRegistered(oName));
    Assert.assertTrue(server.isRegistered(oName));

    server.unregisterMBean(oName);
    Assert.assertFalse(plattformServer.isRegistered(oName));
    Assert.assertFalse(server.isRegistered(oName));

}

From source file:org.apache.cassandra.db.HintedHandOffManager.java

public HintedHandOffManager() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {// w  w  w  . j  av  a2  s  .  c  o  m
        mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=HintedHandoffManager"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}