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.camelpe.examples.jboss7.loanbroker.queue.JBoss7CamelContextConfiguration.java

@PostConstruct
public void createQueues() throws Exception {
    this.log.info("Creating queues ...");
    final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    this.log.info("Found PlatformMBeanServer [{}]", mbeanServer);
    this.log.info("JMX Domains: {}", Arrays.toString(mbeanServer.getDomains()));
    for (final JmsResources.QueueDefinition queueDef : JmsResources.loanBrokerQueues()) {
        mbeanServer.invoke(new ObjectName("org.hornetq:module=JMS,type=Server"), "createQueue",
                new Object[] { queueDef.getName(), queueDef.getBinding() },
                new String[] { "java.lang.String", "java.lang.String" });
        this.log.info("Created queue [{}]", queueDef);
    }/*  w  ww.  j a v a  2 s . co  m*/
}

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

public boolean unRegisterMBean(String category, String id) {
    try {/*from  w  w w .  j  a v  a  2  s. c  o  m*/
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName objName = new ObjectName(getObjectName(category, id));
        if (mbs.isRegistered(objName)) {
            mbs.unregisterMBean(objName);
            return true;
        }
    } catch (Exception e) {
        log.warn("Error un-registering a  MBean with name ' " + id + " ' and category name ' " + category
                + "' for JMX management", e);
    }
    return false;
}

From source file:com.ngdata.hbaseindexer.supervisor.IndexerRegistry.java

private void unregisterMBean() {
    try {/*from   ww  w.j  a  v a2s. c o  m*/
        ManagementFactory.getPlatformMBeanServer().unregisterMBean(jmxObjectName);
    } catch (Exception e) {
        log.warn("Error unregistering mbean '" + jmxObjectName, e);
    }
}

From source file:com.ning.jetty.core.modules.ServerModule.java

protected void installJMX() {
    final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    binder().bind(MBeanServer.class).toInstance(mBeanServer);

    install(new MBeanModule());
}

From source file:org.red5.server.ClientRegistry.java

public ClientRegistry(String name) {
    this.name = name;
    if (StringUtils.isNotBlank(this.name)) {
        try {/*ww w  .j  a va  2  s  .  c om*/
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName oName = new ObjectName("org.red5.server:type=ClientRegistry,name=" + name);
            mbeanServer.registerMBean(new StandardMBean(this, ClientRegistryMXBean.class, true), oName);
        } catch (Exception e) {
            //log.warn("Error on jmx registration", e);
        }
    }
}

From source file:org.ngrinder.monitor.agent.MonitorServer.java

/**
 * Initialize the monitor server.//  w w  w . ja  v a  2  s.c om
 *
 * @param agentConfig agentConfig
 * @throws IOException IO error
 */
public void init(AgentConfig agentConfig) throws IOException {
    this.agentConfig = agentConfig;
    Set<String> systemDataCollector = new HashSet<String>();
    systemDataCollector.add(SYSTEM);
    MonitorContext.getInstance().setDataCollectors(systemDataCollector);
    int port = agentConfig.getMonitorProperties().getPropertyInt(PROP_MONITOR_BINDING_PORT);
    this.rmiRegistry = LocateRegistry.createRegistry(port);
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    String hostname = agentConfig.getMonitorBindingIP();
    if (StringUtils.isBlank(hostname)) {
        hostname = NetworkUtils.getAllPBindingAddress();
    }
    final String jmxUrlString = String.format("service:jmx:rmi://%s:%d/jndi/rmi://%s:%d/jmxrmi", hostname, port,
            hostname, port);
    JMXServiceURL jmxUrl = new JMXServiceURL(jmxUrlString);
    this.jmxServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, mBeanServer);
    RegisterMXBean.getInstance().addDefaultMXBean(mBeanServer);
    LOG.info("Service URL:{} is initiated.", jmxUrl);
}

From source file:com.bigdata.dastor.service.StorageProxy.java

public static void init() // BIGDATA: use init() 
{
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {/*from  w  w  w  . ja v a2  s. c o  m*/
        mbs.registerMBean(new StorageProxy(), new ObjectName(MBEAN_OBJECT_NAME)); // BIGDATA
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

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

From source file:com.nabla.project.application.core.spring.ExtractionScope.java

/**
 * Creates a new ExtractionScope object.
 */
public ExtractionScope() {

    mbs = ManagementFactory.getPlatformMBeanServer();

}

From source file:org.duracloud.syncui.SyncUIDriver.java

/**
 * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation:
 * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp
 *///w  ww.j  av a 2  s.  co  m
private static void launchServer(final String url, final CloseableHttpClient client) {
    try {
        final JDialog dialog = new JDialog();
        dialog.setSize(new java.awt.Dimension(400, 75));
        dialog.setModalityType(ModalityType.MODELESS);
        dialog.setTitle("DuraCloud Sync");
        dialog.setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        final JLabel label = new JLabel("Loading...");
        final JProgressBar progress = new JProgressBar();
        progress.setStringPainted(true);

        panel.add(label);
        panel.add(progress);
        dialog.add(panel);
        dialog.setVisible(true);

        port = SyncUIConfig.getPort();
        contextPath = SyncUIConfig.getContextPath();
        Server srv = new Server(port);

        // Setup JMX
        MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        srv.addBean(mbContainer);

        ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain();
        String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm();

        log.debug("warfile: {}", warFile);
        WebAppContext context = new WebAppContext();
        context.setContextPath(contextPath);
        context.setWar(warFile);
        context.setExtractWAR(Boolean.TRUE);

        Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv);
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
                "org.eclipse.jetty.annotations.AnnotationConfiguration");

        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

        srv.setHandler(context);

        new Thread(new Runnable() {
            @Override
            public void run() {
                createSysTray(url, srv);

                while (true) {
                    if (progress.getValue() < 100) {
                        progress.setValue(progress.getValue() + 3);
                    }

                    sleep(2000);
                    if (isAppRunning(url, client)) {
                        break;
                    }
                }

                progress.setValue(100);

                label.setText("Launching browser...");
                launchBrowser(url);
                dialog.setVisible(false);
            }
        }).start();

        srv.start();

        srv.join();
    } catch (Exception e) {
        log.error("Error launching server: " + e.getMessage(), e);
    }
}