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.eclipse.virgo.repository.internal.remote.RemoteRepositoryTests.java

@Test
public void mBeanPublication() throws Exception {
    URI repositoryUri = URI.create("http://localhost:8080/repository");
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration("remote-repo",
            this.proxyIndexLocation, repositoryUri, 1, MBEAN_DOMAIN_VIRGO_WEB_SERVER, this.cacheDirectory);
    RemoteRepository repository = new RemoteRepository(configuration, new MockEventLogger());
    ObjectName objectName = new ObjectName(MBEAN_DOMAIN_VIRGO_WEB_SERVER + ":type=Repository,name=remote-repo");

    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();

    try {/* ww w  .  j  a va2s. c  o m*/
        platformMBeanServer.getMBeanInfo(objectName);
        fail("MBean should not be present until repository has been started");
    } catch (InstanceNotFoundException infe) {
    }

    repository.start();

    MBeanInfo mBeanInfo = platformMBeanServer.getMBeanInfo(objectName);
    Object type = mBeanInfo.getDescriptor().getFieldValue("type");
    assertNotNull(type);
    assertEquals("remote", type);

    repository.stop();

    try {
        platformMBeanServer.getMBeanInfo(objectName);
        fail("MBean should not be present once repository has been stopped");
    } catch (InstanceNotFoundException infe) {
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestNameNodeMXBean.java

@Test(timeout = 120000)
public void testTopUsersNoPeriods() throws Exception {
    final Configuration conf = new Configuration();
    conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, true);
    conf.set(DFSConfigKeys.NNTOP_WINDOWS_MINUTES_KEY, "");
    MiniDFSCluster cluster = null;//from   w  ww . j  a v a  2s. c  o m
    try {
        cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
        cluster.waitActive();
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState");
        FileSystem fs = cluster.getFileSystem();
        final Path path = new Path("/");
        final int NUM_OPS = 10;
        for (int i = 0; i < NUM_OPS; i++) {
            fs.listStatus(path);
            fs.setTimes(path, 0, 1);
        }
        String topUsers = (String) (mbs.getAttribute(mxbeanNameFsns, "TopUserOpCounts"));
        assertNotNull("Expected TopUserOpCounts bean!", topUsers);
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}

From source file:edu.nwpu.gemfire.monitor.data.JMXDataUpdater.java

private boolean isConnected() {
    // Reference to repository
    Repository repository = Repository.get();
    if (repository.getIsEmbeddedMode()) {
        if (this.mbs == null) {
            this.mbs = ManagementFactory.getPlatformMBeanServer();
            cluster.setConnectedFlag(true);
        }/*  ww  w. ja va2  s.c  o m*/
    } else {
        try {
            if (this.conn == null) {
                cluster.setConnectedFlag(false);
                cluster.setConnectionErrorMsg(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_NOT_FOUND") + " "
                        + resourceBundle.getString("LOG_MSG_JMX_GETTING_NEW_CONNECTION"));
                if (LOGGER.fineEnabled()) {
                    LOGGER.fine(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_NOT_FOUND") + " "
                            + resourceBundle.getString("LOG_MSG_JMX_GET_NEW_CONNECTION"));
                }
                this.conn = getJMXConnection();
                if (this.conn != null) {
                    this.mbs = this.conn.getMBeanServerConnection();
                    cluster.setConnectedFlag(true);
                } else {
                    if (LOGGER.infoEnabled()) {
                        LOGGER.info(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_NOT_FOUND"));
                    }
                    return false;
                }
            } else {
                if (LOGGER.fineEnabled()) {
                    LOGGER.fine(resourceBundle.getString("LOG_MSG_JMX_CONNECTION_IS_AVAILABLE"));
                }
                cluster.setConnectedFlag(true);
                if (this.mbs == null) {
                    this.mbs = this.conn.getMBeanServerConnection();
                }
            }
        } catch (Exception e) {
            this.mbs = null;
            if (this.conn != null) {
                try {
                    this.conn.close();
                } catch (Exception e1) {
                    LOGGER.severe(e);
                }
            }
            this.conn = null;
            return false;
        }
    }

    return true;
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Server helper method to register a JMX MBean. MBeans are registered by a
 * combination of their MBean interface and the custom mbeanName argument.
 * The mbeanName permits multiple mBeans to be registered under the same
 * name.//from w  w w.  jav  a2s. c om
 * 
 * @param mbeanInterface The MBean interface this instance implements
 * @throws ServerRuntimeException
 */
public static void unregisterMBean(Class<?> mbeanInterface) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName name = generateMBeanObjectName(mbeanInterface);
        if (mbs.isRegistered(name)) {
            logger.info("Unregistering mbean: " + name.toString());
            mbs.unregisterMBean(name);
        } else {
            logger.warn("Ignoring attempt to unregister unknown mbean: " + name.toString());
        }
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to unregister mbean: interface=" + mbeanInterface, e);

    }
}

From source file:org.eclipse.virgo.web.test.AbstractWebIntegrationTests.java

private void awaitInitialArtifactDeployment() throws JMException, InterruptedException {
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName(
            "org.eclipse.virgo.kernel:type=ArtifactModel,artifact-type=plan,name=org.eclipse.virgo.web.tomcat,version="
                    + CURRENT_VERSION + ",region=global");

    Object state = null;/*from w w  w .j  av a2  s . c o m*/
    long startTime = System.currentTimeMillis();

    while (!"ACTIVE".equals(state)) {
        try {
            state = mBeanServer.getAttribute(objectName, "State");
            Thread.sleep(100);
        } catch (InstanceNotFoundException _) {
        }
        if (System.currentTimeMillis() - startTime > WEB_PLAN_DEPLOY_TIMEOUT) {
            throw new RuntimeException(
                    "Web plan did not start within " + (WEB_PLAN_DEPLOY_TIMEOUT / 1000) + " seconds.");
        }
    }
}

From source file:org.eclipse.virgo.repository.internal.remote.RemoteRepositoryTests.java

@Test
public void mBeanNonPublication() throws Exception {
    URI repositoryUri = URI.create("http://localhost:8080/repository");
    RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration("remote-repo",
            this.proxyIndexLocation, repositoryUri, 1, null, this.cacheDirectory);
    RemoteRepository repository = new RemoteRepository(configuration, new MockEventLogger());
    ObjectName objectName = new ObjectName(MBEAN_DOMAIN_VIRGO_WEB_SERVER + ":type=Repository,name=remote-repo");
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();

    try {//w  w  w . j  a  v  a 2s.  c o m
        platformMBeanServer.getMBeanInfo(objectName);
        fail("MBean should not be present before start");
    } catch (InstanceNotFoundException infe) {
    }

    repository.start();

    try {
        platformMBeanServer.getMBeanInfo(objectName);
        fail("MBean should not be present after start");
    } catch (InstanceNotFoundException infe) {
    }

    repository.stop();

    try {
        platformMBeanServer.getMBeanInfo(objectName);
        fail("MBean should not be present once repository has been stopped");
    } catch (InstanceNotFoundException infe) {
    }
}

From source file:org.helios.netty.jmx.MetricCollector.java

/**
 * Returns a simple map of NIO metrics/*  w w w . j a va 2s  .co  m*/
 * @return a simple map of NIO metrics
 */
protected Map<String, Long> getNio() {
    Map<String, Long> map = new HashMap<String, Long>(NIO_ATTRS.length);
    try {
        AttributeList attrs = ManagementFactory.getPlatformMBeanServer().getAttributes(directNio, NIO_ATTRS);
        for (Attribute attr : attrs.asList()) {
            map.put(attr.getName(), (Long) attr.getValue());
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    return map;
}

From source file:org.jumpmind.symmetric.SymmetricWebServer.java

protected void registerHttpJmxAdaptor(int jmxPort) throws Exception {
    if (AppUtils.isSystemPropertySet(SystemConstants.SYSPROP_JMX_HTTP_CONSOLE_ENABLED, true) && jmxEnabled) {
        log.info("Starting JMX HTTP console on port {}", jmxPort);
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = getHttpJmxAdaptorName();
        mbeanServer.createMBean(HttpAdaptor.class.getName(), name);
        if (!AppUtils.isSystemPropertySet(SystemConstants.SYSPROP_JMX_HTTP_CONSOLE_LOCALHOST_ENABLED, true)) {
            mbeanServer.setAttribute(name, new Attribute("Host", "0.0.0.0"));
        } else if (StringUtils.isNotBlank(host)) {
            mbeanServer.setAttribute(name, new Attribute("Host", host));
        }/*from   ww  w .ja  va  2  s .  c o  m*/
        mbeanServer.setAttribute(name, new Attribute("Port", new Integer(jmxPort)));
        ObjectName processorName = getXslJmxAdaptorName();
        mbeanServer.createMBean(XSLTProcessor.class.getName(), processorName);
        mbeanServer.setAttribute(name, new Attribute("ProcessorName", processorName));
        mbeanServer.invoke(name, "start", null, null);
    }
}

From source file:azkaban.execapp.AzkabanExecutorServer.java

private void configureMBeanServer() {
    logger.info("Registering MBeans...");
    mbeanServer = ManagementFactory.getPlatformMBeanServer();

    registerMbean("executorJetty", new JmxJettyServer(server));
    registerMbean("flowRunnerManager", new JmxFlowRunnerManager(runnerManager));
    registerMbean("jobJMXMBean", JmxJobMBeanManager.getInstance());

    if (JobCallbackManager.isInitialized()) {
        JobCallbackManager jobCallbackMgr = JobCallbackManager.getInstance();
        registerMbean("jobCallbackJMXMBean", jobCallbackMgr.getJmxJobCallbackMBean());
    }/*from  www  . j av a  2s .  c  o m*/
}

From source file:org.rhq.enterprise.server.core.StartupBean.java

private PluginDeploymentScannerMBean getPluginDeploymentScanner() {
    PluginDeploymentScannerMBean deployer;
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = PluginDeploymentScannerMBean.OBJECT_NAME;
    Class<?> iface = PluginDeploymentScannerMBean.class;
    deployer = (PluginDeploymentScannerMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name, iface,
            false);//www  .  ja  va  2s . c  o m
    return deployer;
}