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:com.espertech.esper.metrics.jmx.CommonJMXUtil.java

private static void registerMbean(Object mbean, ObjectName name) {
    try {/*from   ww w.  ja  v a  2  s.c  om*/
        registerMbean(ManagementFactory.getPlatformMBeanServer(), createModelMBean(mbean), name);
    } catch (Exception e) {
        log.error("Error registering mbean: " + e.getMessage(), e);
    }
}

From source file:utilities.srvRutinas.java

public static double getProcessCpuLoad() throws Exception {

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
    AttributeList list = mbs.getAttributes(name, new String[] { "ProcessCpuLoad" });

    if (list.isEmpty())
        return Double.NaN;

    Attribute att = (Attribute) list.get(0);
    Double value = (Double) att.getValue();

    // usually takes a couple of seconds before we get real values
    if (value == -1.0)
        return Double.NaN;
    // returns a percentage value with 1 decimal point precision
    return ((int) (value * 1000) / 10.0);
}

From source file:org.eclipse.gyrex.monitoring.internal.MetricSetTracker.java

@Override
public MetricSetJmxRegistration addingService(final ServiceReference<MetricSet> reference) {
    // get service
    final MetricSet metricSet = context.getService(reference);
    if (metricSet == null) {
        return null;
    }// ww  w  .  j a  v a2 s  .c  om

    try {
        final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        final ObjectName objectName = getObjectName(reference, metricSet);
        beanServer.registerMBean(new MetricSetMBean(metricSet, reference), objectName);
        return new MetricSetJmxRegistration(objectName, metricSet);
    } catch (final Exception e) {
        LOG.warn("Failed to expose metric {} using JMX. {}", metricSet, ExceptionUtils.getRootCauseMessage(e));
    }
    return null;
}

From source file:org.apache.cassandra.gms.FailureDetector.java

public FailureDetector() {
    phiConvictThreshold_ = DatabaseDescriptor.getPhiConvictThreshold();
    // Register this instance with JMX
    try {//from  w  w  w .j  a v a  2 s  . c o  m
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(this, new ObjectName("org.apache.cassandra.net:type=FailureDetector"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:uk.co.gidley.jmxmonitor.services.InternalJmxTest.java

@Test
public void testStartupShutdownNoop()
        throws MalformedObjectNameException, InitialisationException, ConfigurationException {

    MainConfiguration mainConfiguration = mock(MainConfiguration.class);
    RegistryShutdownHub registryShutdownHub = mock(RegistryShutdownHub.class);

    Configuration configuration = new PropertiesConfiguration(
            "src/test/resources/noopConfiguration.properties");
    when(mainConfiguration.getConfiguration()).thenReturn(configuration);

    InternalJmx internalJmx = new InternalJmx(mainConfiguration, registryShutdownHub);

    verify(registryShutdownHub).addRegistryShutdownListener(internalJmx);

    // Internal JMX should now be not running

    try {/*from w ww  . jav a 2  s .  com*/
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(internalJmx.getConnectorServerName());
        assertThat("Exception Shourt have thrown", false);
    } catch (InstanceNotFoundException e) {

    }

    // Fire shutdown anyhow
    internalJmx.registryDidShutdown();

}

From source file:org.wso2.carbon.cassandra.mgt.internal.CassandraAdminDataHolder.java

private CassandraAdminDataHolder() {
    this.mbeanLocator = new CassandraMBeanLocator(ManagementFactory.getPlatformMBeanServer());
}

From source file:com.fatwire.gst.web.status.StatusRequestListener.java

public void contextDestroyed(ServletContextEvent sce) {
    ConcurrencyCounterLocator.getInstance().deregister(requestCounter);
    requestCounter = null;/*w  w w  .ja  v  a  2s. co  m*/
    try {
        ManagementFactory.getPlatformMBeanServer().unregisterMBean(name);
    } catch (Throwable e) {
        log.info(e.getMessage(), e);
    }

}

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

public void unRegisterMBean(String category, String id) {
    try {//from ww  w  . j  a v  a2s .  com
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objName = new ObjectName(getObjectName(category, id));
        if (mbs.isRegistered(objName)) {
            mbs.unregisterMBean(objName);
        }
    } catch (Exception e) {
        log.warn("Error un-registering a  MBean with name ' " + id + " ' and category name ' " + category
                + "' for JMX management", e);
    }
}

From source file:org.rhq.enterprise.server.test.TestBean.java

@Override
public void enableHibernateStatistics() {
    PersistenceUtility.enableHibernateStatistics(entityManager, ManagementFactory.getPlatformMBeanServer(),
            true);
}