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.apache.hadoop.hdfs.server.datanode.fsdataset.impl.TestSpaceReservation.java

@Test(timeout = 30000)
public void testReservedSpaceInJMXBean() throws Exception {

    final short replication = 1;
    startCluster(BLOCK_SIZE, replication, -1);

    final String methodName = GenericTestUtils.getMethodName();
    final Path file = new Path("/" + methodName + ".01.dat");

    try (FSDataOutputStream os = fs.create(file, replication)) {
        // Write 1 byte to the file
        os.write(new byte[1]);
        os.hsync();//from ww w  .  ja  v a  2  s.  c  om

        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName mxbeanName = new ObjectName("Hadoop:service=DataNode,name=DataNodeInfo");
        final String volumeInfo = (String) mbs.getAttribute(mxbeanName, "VolumeInfo");

        // verify reserved space for Replicas in JMX bean volume info
        assertTrue(volumeInfo.contains("reservedSpaceForReplicas"));
    }
}

From source file:org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.java

/**
 * Registers the Platform MBeanServer as OSGi service. This would enable
 * Aries JMX Whitboard support to then register the JMX MBean which are registered as OSGi service
 * to be registered against the MBean server
 *///  w w  w  .  j  a va 2  s.c o m
private static void registerMBeanServer(PojoServiceRegistry registry) {
    MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
    Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
    try {
        ObjectName beanName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        AttributeList attrs = platformMBeanServer.getAttributes(beanName,
                new String[] { "MBeanServerId", "SpecificationName", "SpecificationVersion",
                        "SpecificationVendor", "ImplementationName", "ImplementationVersion",
                        "ImplementationVendor" });
        for (Object object : attrs) {
            Attribute attr = (Attribute) object;
            if (attr.getValue() != null) {
                mbeanProps.put(attr.getName(), attr.getValue().toString());
            }
        }
    } catch (Exception je) {
        log.info("Cannot set service properties of Platform MBeanServer service, registering without", je);
    }
    registry.registerService(MBeanServer.class.getName(), platformMBeanServer, mbeanProps);
}

From source file:com.tc.server.TCServerImpl.java

protected DistributedObjectServer createDistributedObjectServer(L2ConfigurationSetupManager configSetupManager,
        ConnectionPolicy policy, TCServerImpl serverImpl) {
    DistributedObjectServer dso = new DistributedObjectServer(configSetupManager, getThreadGroup(), policy,
            this, this, securityManager);
    try {/*from www  .j  a  va 2  s .  co m*/
        registerServerMBeans(dso, ManagementFactory.getPlatformMBeanServer());
    } catch (NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException exp) {
        throw new RuntimeException(exp);
    }
    return dso;
}

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 www . java  2  s .c  om*/
 * 
 * @param mbean The MBean instance that should be registered
 * @param mbeanInterface The MBean interface this instance implements
 * @param mbeanName A custom name for this MBean
 * @throws ServerRuntimeException
 */
public static void registerMBean(Object mbean, Class<?> mbeanInterface, String mbeanName, boolean ignored) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        if (logger.isDebugEnabled())
            logger.debug("Registering mbean: " + mbean.getClass());

        ObjectName name = generateMBeanObjectName(mbeanInterface.getName(), mbeanName);

        if (mbs.isRegistered(name))
            mbs.unregisterMBean(name);
        mbs.registerMBean(mbean, name);
    } catch (Exception e) {
        throw new ServerRuntimeException("Unable to register mbean: class=" + mbean.getClass() + " interface="
                + mbeanInterface + " name=" + mbeanName, e);

    }
}

From source file:org.apache.hadoop.hbase.util.JSONBean.java

/**
 * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out.
 * @throws MalformedObjectNameException/*from w w  w  .j a va  2 s . c om*/
 * @throws IOException
 */
public static String dumpRegionServerMetrics() throws MalformedObjectNameException, IOException {
    StringWriter sw = new StringWriter(1024 * 100); // Guess this size
    try (PrintWriter writer = new PrintWriter(sw)) {
        JSONBean dumper = new JSONBean();
        try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            jsonBeanWriter.write(mbeanServer, new ObjectName("java.lang:type=Memory"), null, false);
            jsonBeanWriter.write(mbeanServer, new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"),
                    null, false);
            jsonBeanWriter.write(mbeanServer,
                    new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false);
            jsonBeanWriter.write(mbeanServer,
                    new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false);
        }
    }
    sw.close();
    return sw.toString();
}

From source file:com.norconex.collector.core.crawler.AbstractCrawler.java

private void registerMonitoringMbean(ICrawlDataStore crawlDataStore) {
    try {/*w w w  . jav  a 2s  .  com*/
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(
                "com.norconex.collector.http.crawler:type=" + getCrawlerConfig().getId());
        Monitoring mbean = new Monitoring(crawlDataStore);
        mbs.registerMBean(mbean, name);
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException
            | NotCompliantMBeanException e) {
        throw new CollectorException(e);
    }
}

From source file:org.marketcetera.strategyagent.StrategyAgent.java

/**
 * Initializes the module manager./*from ww w.  j a va 2s.co  m*/
 *
 * @throws ModuleException if there were errors initializing the module
 * manager.
 * @throws MalformedObjectNameException if there were errors creating
 * the object name of the module manager bean.
 */
private void init() throws ModuleException, MalformedObjectNameException {
    //Initialize the module manager.
    mManager.init();
    //Add the logger sink listener
    mManager.addSinkListener(new SinkDataListener() {
        public void receivedData(DataFlowID inFlowID, Object inData) {
            final boolean isNullData = inData == null;
            Messages.LOG_SINK_DATA.info(SINK_DATA, inFlowID, isNullData ? 0 : 1,
                    isNullData ? null : inData.getClass().getName(), inData);
        }
    });
    mManagerBean = JMX.newMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
            new ObjectName(ModuleManager.MODULE_MBEAN_NAME), ModuleManagerMXBean.class);
}

From source file:info.archinnov.achilles.embedded.ServerStarter.java

private boolean isAlreadyRunning() {
    log.trace("Check whether an embedded Cassandra is already running");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {//from  w w  w .j  a  va2 s . co  m
        MBeanInfo mBeanInfo = mbs.getMBeanInfo(new ObjectName("org.apache.cassandra.db:type=StorageService"));
        if (mBeanInfo != null) {
            return true;
        }
        return false;
    } catch (InstanceNotFoundException e) {
        return false;
    } catch (IntrospectionException e) {
        throw new IllegalStateException("Cannot check if cassandra is already running", e);
    } catch (MalformedObjectNameException e) {
        throw new IllegalStateException("Cannot check if cassandra is already running", e);
    } catch (ReflectionException e) {
        throw new IllegalStateException("Cannot check if cassandra is already running", e);
    }

}

From source file:com.tc.server.TCServerImpl.java

private void registerDSOServer(TCDumper dumper) throws InstanceAlreadyExistsException,
        MBeanRegistrationException, NotCompliantMBeanException, NullPointerException {

    ServerManagementContext mgmtContext = this.dsoServer.getManagementContext();
    ServerConfigurationContext configContext = this.dsoServer.getContext();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    registerDSOMBeans(mgmtContext, configContext, dumper, mBeanServer);
}