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:net.timewalker.ffmq4.jmx.rmi.JMXOverRMIAgent.java

private void init() throws JMSException {
    try {//from   w  w  w  .  ja  v  a2  s  . c o m
        log.info("Starting JMX agent");

        // Get or create an RMI registry
        if (rmiListenAddr == null || rmiListenAddr.equals("auto"))
            rmiListenAddr = InetAddress.getLocalHost().getHostName();

        // Connector JNDI name
        String jndiName = "jmxconnector-" + agentName;

        try {
            registry = LocateRegistry.getRegistry(rmiListenAddr, jndiRmiPort);
            registry.lookup(jndiName);

            // Remove the old registered connector
            registry.unbind(jndiName);

            log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort
                    + " with connector already registered");
        } catch (NotBoundException e) {
            // Registry already exists
            log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort);
        } catch (RemoteException e) {
            log.debug("Creating RMI registry at " + rmiListenAddr + ":" + jndiRmiPort);
            RMIServerSocketFactory ssf = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, false);
            registry = LocateRegistry.createRegistry(jndiRmiPort, null, ssf);
        }

        // Get the JVM MBean server
        mBeanServer = ManagementFactory.getPlatformMBeanServer();

        // Service URL
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + rmiListenAddr + "/jndi/rmi://"
                + rmiListenAddr + ":" + jndiRmiPort + "/" + jndiName);
        log.info("JMX Service URL : " + url);

        // Create and start the RMIConnectorServer
        Map<String, Object> env = new HashMap<>();
        mBeanServerSocketFactory = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, true);
        env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
        //env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new JMXRMIClientSocketFactory(rmiListenAddr));
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, mBeanServerSocketFactory);
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mBeanServer);
        connectorServer.start();
    } catch (Exception e) {
        throw new FFMQException("Could not initialize JMX agent", "JMX_ERROR", e);
    }
}

From source file:com.neophob.sematrix.jmx.PixelControllerStatus.java

/**
 * Register the JMX Bean.//  w w w. j  a  v a2  s .  co  m
 *
 * @param configuredFps the configured fps
 */
public PixelControllerStatus(int configuredFps) {
    LOG.log(Level.INFO, "Initialize the PixelControllerStatus JMX Bean");

    this.configuredFps = configuredFps;

    // initialize all buffers 
    this.timeMeasureMapGlobal = new ConcurrentHashMap<TimeMeasureItemGlobal, CircularFifoBuffer>();
    for (TimeMeasureItemGlobal timeMeasureItem : TimeMeasureItemGlobal.values()) {
        this.timeMeasureMapGlobal.put(timeMeasureItem, new CircularFifoBuffer(this.configuredFps * SECONDS));
    }
    this.timeMeasureMapOutput = new ConcurrentHashMap<Output, Map<TimeMeasureItemOutput, CircularFifoBuffer>>();
    this.outputList = new ArrayList<Output>();

    startTime = System.currentTimeMillis();

    // register MBean
    try {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName name = new ObjectName(JMX_BEAN_NAME);
        // check if the MBean is already registered
        if (!server.isRegistered(name)) {
            server.registerMBean(this, name);
        }
    } catch (JMException ex) {
        LOG.log(Level.WARNING, "Error while registering class as JMX Bean.", ex);
    }
}

From source file:org.obiba.mica.config.MetricsConfiguration.java

@PostConstruct
public void init() {
    log.debug("Registering JVM gauges");
    METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
    METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
    METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
    METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
    METRIC_REGISTRY.register(PROP_METRIC_REG_JVM_BUFFERS,
            new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
    if (propertyResolver.getProperty(PROP_JMX_ENABLED, Boolean.class, false)) {
        log.info("Initializing Metrics JMX reporting");
        JmxReporter jmxReporter = JmxReporter.forRegistry(METRIC_REGISTRY).build();
        jmxReporter.start();//  w w w  .j  a v a2s . c  o m
    }
}

From source file:org.opendaylight.controller.config.yang.logback.config.LogbackWithXmlConfigModuleTest.java

/**
 * Tests filtering loggers. Loggers inherited from ROOT logger and duplicate
 * loggers should be removed./*from w ww. j a  v a  2  s.  c o m*/
 */
@Test
public void testAllLoggers() throws InstanceAlreadyExistsException, InstanceNotFoundException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();

    LogbackModuleMXBean bean = JMX.newMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
            transaction.lookupConfigBean("logback", "singleton"), LogbackModuleMXBean.class);

    assertEquals(5, bean.getLoggerTO().size());
}

From source file:org.apache.accumulo.server.metrics.AbstractMetricsImpl.java

/**
 * Registers a StandardMBean with the MBean Server
 *//*from   ww w  . j a v a 2s .com*/
public void register(StandardMBean mbean) throws Exception {
    // Register this object with the MBeanServer
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    if (null == getObjectName())
        throw new IllegalArgumentException("MBean object name must be set.");
    mbs.registerMBean(mbean, getObjectName());

    setupLogging();
}

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

/**
 * Creates a new ThreadPool//from w w  w .java2 s .  c  o m
 * @param domain The JMX domain where the MBean will be published 
 * @param name The name property for the MBean ObjectName
 */
private ThreadPoolFactory(String domain, String name) {
    super(0, Integer.MAX_VALUE, 50L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    setThreadFactory(this);
    this.name = name;
    try {
        objectName = new ObjectName(domain + ":service=ThreadPool,name=" + name);
        ManagementFactory.getPlatformMBeanServer().registerMBean(this, objectName);
        threadingMetrics.put(name, poolMetrics);
        ManagementFactory.getPlatformMBeanServer().addNotificationListener(MetricCollector.OBJECT_NAME, this,
                this, null);
        String prefix = "threadPools.[" + name + "].";
        for (String s : points) {
            metricNames.add(prefix + s);
        }
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to register management interface for pool [" + domain + "/" + name + "]", e);
    }

}

From source file:org.apache.james.modules.server.JMXServer.java

private void doStart() {
    try {//  w w w.  java  2 s . c  o  m
        PropertiesConfiguration configuration = new PropertiesConfiguration(
                fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties"));
        String address = configuration.getString("jmx.address");
        int port = configuration.getInt("jmx.port");
        String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address + ":" + port + "/jmxrmi";
        RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address);
        LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory);

        Map<String, ?> environment = ImmutableMap.of();
        jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL),
                environment, ManagementFactory.getPlatformMBeanServer());

        jmxConnectorServer.start();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

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

protected void registerJMX() {
    //register with jmx server
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {//from   w w  w .j a  va2 s.  co 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);
        }
        mbeanServer.registerMBean(new StandardMBean(this, QuartzSchedulingServiceMXBean.class, true), oName);
    } catch (Exception e) {
        log.warn("Error on jmx registration", e);
    }
}

From source file:org.cloudata.core.common.metrics.CloudataMetricsFactory.java

public ObjectName registerMBean(final String serviceName, final String nameName, final Object theMbean) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = getMBeanName(serviceName, nameName);
    try {//  w  w w . j  a v  a  2  s. c  o m
        mbs.registerMBean(theMbean, name);
        return name;
    } catch (InstanceAlreadyExistsException ie) {
        // Ignore if instance already exists
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.aludratest.cloud.impl.request.ClientRequestServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    instance = this;
    super.init(config);

    requestHandler = new ClientRequestHandler(CloudManagerApp.getInstance().getResourceManager());
    // register request handler as MBean
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/* w w  w  .j a  v a 2s  . c om*/
        mbs.registerMBean(requestHandler, new ObjectName("org.aludratest.cloud:type=ClientRequestHandler"));
    } catch (JMException e) {
        LOG.error("Could not register request handler in MBean Server", e);
    }
}