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.opendaylight.infrautils.diagstatus.MBeanUtils.java

public static void unregisterServerMBean(Object mxBeanImplementor, String objNameStr)
        throws MalformedObjectNameException, InstanceNotFoundException, MBeanRegistrationException {
    LOG.debug("unregister MXBean for {}", objNameStr);
    MBeanServer mplatformMbeanServer = ManagementFactory.getPlatformMBeanServer();
    try {/*from  ww  w. j  a va  2s  .  c  o  m*/
        mplatformMbeanServer.unregisterMBean(new ObjectName(objNameStr));
    } catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException e) {
        LOG.error("Error while unregistering MBean {}", objNameStr, e);
        throw e;
    }
}

From source file:org.bigmouth.nvwa.transport.DelegatedSender.java

@Override
protected void doDestroy() {
    sendExecutor.shutdownNow();//from ww w .j a  va 2  s .  co m
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    if (null != senderMBeanName) {

        try {
            ObjectName acceptorName = new ObjectName(this.senderMBeanName);
            mBeanServer.unregisterMBean(acceptorName);
        } catch (MalformedObjectNameException e) {
            LOG.error("Unable DelegatedSender jmx unregister:", e);
        } catch (NullPointerException e) {
            LOG.error("Unable DelegatedSender jmx unregister:", e);
        } catch (MBeanRegistrationException e) {
            LOG.error("Unable DelegatedSender jmx unregister:", e);
        } catch (InstanceNotFoundException e) {
            LOG.error("Unable DelegatedSender jmx unregister:", e);
        }
    }
}

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

public void unregisterMBean(ObjectName mbeanName) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    if (mbeanName == null)
        return;/*from www  .j  a  va2 s  .com*/
    try {
        mbs.unregisterMBean(mbeanName);
    } catch (InstanceNotFoundException e) {
        // ignore
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.onehippo.forge.channelmanager.pagesupport.document.management.impl.DocumentManagementServiceDaemonModule.java

private void registerDocumentManagementServiceMBean() {
    try {/*ww  w . j ava2  s  .c o m*/
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName mbeanName = new ObjectName(DocumentManagementServiceMXBean.NAME);

        if (mbeanServer.isRegistered(mbeanName)) {
            mbeanServer.unregisterMBean(mbeanName);
        }

        mbeanServer.registerMBean(documentManagementService, mbeanName);
    } catch (Exception e) {
        log.error("Failed to register MBean.", e);
    }
}

From source file:gridool.discovery.jgroups.JGroupsDiscoveryService.java

private static MBeanServer registerMBeans(JChannel channel) throws GridException {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {//  w w  w.  ja v  a2 s.co m
        JmxConfigurator.registerChannel(channel, server, JGROUPS_DOMAIN_NAME, channel.getClusterName(), true);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new GridException(e);
    }
    return server;
}

From source file:de.thorstenberger.examServer.pdf.PDFExporter.java

/**
 * use jmx, query catalina mbean to find non ssl connectors (-Dcom.sun.management.jmxremote) FIXME tomcat specific
 * code/*from w  w w  .ja  va  2 s.c  o m*/
 *
 * @param request
 * @return
 */
private String getServerUrl() {

    final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        for (final Object mbean : beanServer.queryMBeans(new ObjectName("*:type=Connector,*"), null)) {
            final ObjectInstance oi = (ObjectInstance) mbean;
            final Boolean isSecure = (Boolean) beanServer.getAttribute(oi.getObjectName(), "secure");
            final String protocol = (String) beanServer.getAttribute(oi.getObjectName(), "protocol");
            final int port = (Integer) beanServer.getAttribute(oi.getObjectName(), "port");
            if (!isSecure && protocol.startsWith("HTTP")) {
                log.debug(String.format("Using unsecured tomcat connector at port %d", port));
                return "http://localhost:" + port;
            }
        }
    } catch (final MalformedObjectNameException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final NullPointerException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final AttributeNotFoundException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final InstanceNotFoundException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final MBeanException e) {
        log.warn("Could not access JMX mbeans.", e);
    } catch (final ReflectionException e) {
        log.warn("Could not access JMX mbeans.", e);
    }
    log.warn(
            "No mbeans of type '*:type=Connector,*' configured, using default url (assuming non-ssl http connector on port 8080).");
    return "http://localhost:8080";
}

From source file:org.wso2.carbon.registry.extensions.internal.RegistryJMXServiceComponent.java

protected void deactivate(ComponentContext context) {
    while (!mBeans.empty()) {
        try {//  ww w . j ava 2  s .c om
            ManagementFactory.getPlatformMBeanServer().unregisterMBean(mBeans.pop());
        } catch (JMException e) {
            log.error("Unable to un-register JMX extensions", e);
        }
    }
    while (!serviceRegistrations.empty()) {
        serviceRegistrations.pop().unregister();
    }
    log.debug("Registry JMX component is deactivated");
}

From source file:com.avanza.ymer.YmerMirrorIntegrationTest.java

@Test
public void mbeanInvoke() throws Exception {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    ObjectName nameTemplate = ObjectName.getInstance(
            "se.avanzabank.space.mirror:type=DocumentWriteExceptionHandler,name=documentWriteExceptionHandler");
    Set<ObjectName> names = server.queryNames(nameTemplate, null);
    assertThat(names.size(), is(greaterThan(0)));
    server.invoke(names.toArray(new ObjectName[1])[0], "useCatchesAllHandler", null, null);
}

From source file:org.codice.ddf.configuration.migration.ConfigurationMigrationManagerTest.java

@Before
public void setup() throws Exception {
    this.path = createDirectory(TEST_DIRECTORY);
    this.encryptedFileName = path.resolve(TEST_BRANDING) + "-" + TEST_VERSION + ".dar";
    this.decryptedFileName = path.resolve(TEST_BRANDING) + "-" + TEST_VERSION + ".zip";

    migratables = Collections.emptyList();
    ManagementFactory.getPlatformMBeanServer().registerMBean(mockWrapperManager,
            new ObjectName("org.tanukisoftware.wrapper:type=WrapperManager"));
    doNothing().when(mockWrapperManager).restart();
    createBrandingFile();/*ww  w. j  av  a  2 s.  c o  m*/
    createVersionFile();
    createMigrationPropsFile();
    this.configurationMigrationManager = mock(ConfigurationMigrationManager.class, Mockito.withSettings()
            .useConstructor(migratables, mockSystemService).defaultAnswer(Mockito.CALLS_REAL_METHODS));
    System.setProperty(RESTART_JVM, "true");
}

From source file:org.lobzik.home_sapiens.pi.AppData.java

public static List<String> getHTTPEndPoints() throws Exception { //tomcat-specific
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String hostname = InetAddress.getLocalHost().getHostName();
    InetAddress[] addresses = InetAddress.getAllByName(hostname);
    ArrayList<String> endPoints = new ArrayList<String>();
    for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
        ObjectName obj = i.next();
        String scheme = mbs.getAttribute(obj, "scheme").toString();
        if (!scheme.toLowerCase().equals("http")) {
            continue;
        }/*  w  w w  .  jav  a2s.  c o m*/
        String port = obj.getKeyProperty("port");
        for (InetAddress addr : addresses) {
            String host = addr.getHostAddress();
            String ep = scheme + "://" + host + ":" + port;
            endPoints.add(ep);
        }
    }
    return endPoints;
}