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.xwiki.management.internal.DefaultJMXBeanRegistration.java

@Override
public void unregisterMBean(String name) {
    // Make sure we never fail since XWiki should execute correctly even if it fail to unregister some MBean
    try {//  w w w  .j ava 2 s  .c o m
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName oname = new ObjectName(OBJECTNAME_PREFIX + name);
        mbs.unregisterMBean(oname);
        this.logger.debug("Unregistered resource with name [{}]", name);
    } catch (Exception e) {
        // Failed to unregister the MBean, log a warning
        this.logger.warn("Failed to unregister resource with name [{}]. Reason = [{}]", name,
                ExceptionUtils.getMessage(e));
    }
}

From source file:com.chiralBehaviors.groo.configuration.ChakaalConfiguration.java

public Chakaal construct() throws Exception {
    return construct(ManagementFactory.getPlatformMBeanServer());
}

From source file:org.sonatype.nexus.internal.httpclient.PoolingClientConnectionManagerMBeanInstaller.java

/**
 * Unregisters the connection manager from JMX.
 *//*from ww  w  . jav a  2 s.  co m*/
synchronized void unregister() {
    if (jmxName != null) {
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            server.unregisterMBean(jmxName);
        } catch (final Exception e) {
            LOGGER.warn("Failed to unregister mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage());
        } finally {
            jmxName = null;
        }
    }
}

From source file:org.codice.ddf.resourcemanagement.query.service.QueryMonitor.java

private void registerMbean() {
    try {/*  w  ww .ja  v  a  2s. com*/
        objectName = new ObjectName(QueryMonitor.class.getName() + ":service=querymonitor");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.error("Unable to create Query Monitor Configuration MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Registered Query Monitor 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 Query Monitor Configuration MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException
            | NotCompliantMBeanException e) {
        LOGGER.error("Could not register MBean [{}].", objectName.toString(), e);
    }
}

From source file:com.bigdata.dastor.gms.FailureDetector.java

public FailureDetector() {
    phiConvictThreshold_ = DatabaseDescriptor.getPhiConvictThreshold();
    creationTime_ = System.currentTimeMillis();
    // Register this instance with JMX
    try {//from  w w w.  j a  v  a 2 s  . c om
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(this, new ObjectName("com.bigdata.dastor.gms:type=FailureDetector"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sonatype.nexus.apachehttpclient.PoolingClientConnectionManagerMBeanInstaller.java

/**
 * Unregisters the connection manager from JMX.
 *///from   w  w  w  .  j av  a  2  s  . c  o  m
public synchronized void unregister() {
    if (jmxName != null) {
        try {
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            server.unregisterMBean(jmxName);
        } catch (final Exception e) {
            LOGGER.warn("Failed to unregister mbean {} due to {}:{}", jmxName, e.getClass(), e.getMessage());
        } finally {
            jmxName = null;
        }
    }
}

From source file:org.springframework.boot.context.SpringApplicationLifecycleRegistrar.java

@Override
public void afterPropertiesSet() throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    server.registerMBean(new SpringApplicationLifecycle(), objectName);
    if (logger.isDebugEnabled()) {
        logger.debug("Application lifecycle MBean registered with name '" + objectName + "'");
    }/*w  ww . j  ava 2  s .  com*/
}

From source file:co.paralleluniverse.common.monitoring.Monitor.java

public void unregisterMBean() {
    try {/*w  ww. j a va2 s  .c  om*/
        if (registered) {
            LOG.info("Unregistering MBean {}", name);
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(name));
        }
        this.registered = false;
    } catch (Exception e) {
        LOG.warn("Exception:", e);
    }
}

From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatMetricSet.java

public TomcatMetricSet() {
    this.mBeanServer = ManagementFactory.getPlatformMBeanServer();

    Map<String, Metric> metricsByNames = new HashMap<>();

    // Executors/*from   ww w  .j a  v a2 s  .  c  om*/
    List<TomcatExecutorStatus> executorStatuses = new ArrayList<>();

    Set<ObjectName> executorObjectNames = null;
    try {
        executorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Executor,*"), null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's Executor MxBean", e);
    }

    if (executorObjectNames != null && !executorObjectNames.isEmpty()) {
        for (final ObjectName executorObjectName : executorObjectNames) {
            TomcatExecutorMetricSet executorMetricSet = new TomcatExecutorMetricSet(executorObjectName);
            if (!executorMetricSet.getMetrics().isEmpty()) {
                metricsByNames.put(MetricNamingUtil.join("executors", executorMetricSet.getName()),
                        executorMetricSet);
            }
            executorStatuses.add(executorMetricSet);
        }
    }

    this.executorStatuses = executorStatuses;

    // Thread Pools
    final List<TomcatConnectorMetricSet> connectorMetricSets = new ArrayList<>();
    List<TomcatConnectorStatus> connectorStatuses = new ArrayList<>();

    Set<ObjectName> threadPoolObjectNames = null;
    try {
        threadPoolObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=ThreadPool,*"), null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's ThreadPool MxBean", e);
    }

    if (threadPoolObjectNames != null && !threadPoolObjectNames.isEmpty()) {
        for (final ObjectName threadPoolObjectName : threadPoolObjectNames) {
            TomcatConnectorMetricSet connectorMetricSet = new TomcatConnectorMetricSet(threadPoolObjectName);
            if (!connectorMetricSet.getMetrics().isEmpty()) {
                metricsByNames.put(MetricNamingUtil.join("connectors", connectorMetricSet.getName()),
                        connectorMetricSet);
                connectorMetricSets.add(connectorMetricSet);
            }
            connectorStatuses.add(connectorMetricSet);
        }
    }

    this.connectorStatuses = connectorStatuses;

    if (!connectorMetricSets.isEmpty()) {
        this.executorService = Executors.newSingleThreadScheduledExecutor(
                new ThreadFactoryBuilder().setNameFormat("TomcatMetricSet-%d").build());
        this.executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                for (TomcatConnectorMetricSet connectorMetricSet : connectorMetricSets) {
                    try {
                        connectorMetricSet.updateQps();
                    } catch (Exception e) {
                        logger.debug("Error while updating QPS for connector {}", connectorMetricSet.getName(),
                                e);

                        if (InterruptedException.class.isInstance(e)) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            }
        }, 1, 1, TimeUnit.SECONDS);
    }

    this.metricsByNames = metricsByNames;

    this.shutdown = new AtomicBoolean(false);
}

From source file:org.nuxeo.runtime.jtajca.management.CanMonitorTransactions.java

@Before
public void lookupMonitor() throws MalformedObjectNameException {
    MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
    monitor = JMX.newMXBeanProxy(srv, new ObjectName(TransactionMonitor.NAME), TransactionMonitor.class);
}