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.italiangrid.voms.container.Container.java

protected void configureJettyServer() {

    SSLOptions options = getSSLOptions();

    CANLListener l = new CANLListener();

    CertificateValidatorBuilder builder = new CertificateValidatorBuilder();

    X509CertChainValidatorExt validator = builder.trustAnchorsDir(options.getTrustStoreDirectory())
            .trustAnchorsUpdateInterval(trustDirRefreshIntervalInMsec).crlChecks(CrlCheckingMode.IF_VALID)
            .lazyAnchorsLoading(false).ocspChecks(OCSPCheckingMode.IGNORE).storeUpdateListener(l)
            .validationErrorListener(l).build();

    int maxConnections = Integer.parseInt(getConfigurationProperty(ConfigurationProperty.MAX_CONNECTIONS));

    int maxRequestQueueSize = Integer
            .parseInt(getConfigurationProperty(ConfigurationProperty.MAX_REQUEST_QUEUE_SIZE));

    server = ServerFactory.newServer(bindAddress, Integer.parseInt(port), getSSLOptions(), validator,
            maxConnections, maxRequestQueueSize);

    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());

    // Enable JMX
    server.addBean(mbContainer);//from w ww. jav  a 2  s . com
    server.getContainer().addEventListener(mbContainer);
    mbContainer.addBean(Log.getLog());

    addNameToHTTPSConnector();
    configureLocalHTTPConnector();

    server.addLifeCycleListener(new ServerListener());

    configureDeploymentManager();

    configureLegacyConnectors(null, validator, options, maxConnections, maxRequestQueueSize);

    // Handlers contains VOMS webapp, status webapp, and as final
    // choice the default handler to correctly handle 404 for non-handled
    // contexts etc.
    handlers.setHandlers(new Handler[] { contexts, new DefaultHandler() });

    // The rewrite handler, will internally foward
    // generate-ac request to legacy voms ports to the appropriate
    // voms-admin webapp
    RewriteHandler rh = new RewriteHandler();
    rh.setRewritePathInfo(true);
    rh.setRewriteRequestURI(true);

    rh.addRule(new VOMSRewriteRule(getConfiguredVOPortMappings()));

    // webapps are wrapped in the rewrite handler
    // or VOMS port rewriting will not work
    rh.setHandler(handlers);
    server.setHandler(rh);

    server.setDumpAfterStart(false);
    server.setDumpBeforeStop(false);
    server.setStopAtShutdown(true);

    server.addBean(deploymentManager);

}

From source file:co.paralleluniverse.common.spring.SpringContainerHelper.java

private static BeanDefinition getMBeanExporterBeanDefinition(String defaultDomain) {
    final AnnotationJmxAttributeSource annotationSource = new AnnotationJmxAttributeSource();

    final GenericBeanDefinition bean = new GenericBeanDefinition();
    bean.setBeanClass(MBeanExporter.class);
    MutablePropertyValues properties = new MutablePropertyValues();
    properties.add("server", ManagementFactory.getPlatformMBeanServer());
    properties.add("autodetectMode", MBeanExporter.AUTODETECT_ASSEMBLER);
    properties.add("assembler", new MetadataMBeanInfoAssembler(annotationSource));
    properties.add("namingStrategy", new MBeanNamingStrategy(annotationSource).setDefaultDomain(defaultDomain));
    bean.setPropertyValues(properties);/*  ww w . j  a  va 2 s  . c  o m*/
    return bean;
}

From source file:org.apache.juddi.v3.client.mapping.UDDIServiceCache.java

private MBeanServer getMBeanServer() {
    MBeanServer mbserver = null;/*from w  w  w.  j av a  2s . com*/
    ArrayList<MBeanServer> mbservers = MBeanServerFactory.findMBeanServer(null);
    if (mbservers.size() > 0) {
        mbserver = (MBeanServer) mbservers.get(0);
    }
    if (mbserver != null && log.isDebugEnabled()) {
        log.debug("Found MBean server");
    } else {
        mbserver = ManagementFactory.getPlatformMBeanServer();
    }
    return mbserver;
}

From source file:org.apache.hadoop.raid.TestBlockFixer.java

private void verifyMXBean(RaidNode cnode) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName mxbeanName = new ObjectName("hadoop:service=RaidNode,name=RaidNodeState");
    Long timeSinceLastSuccessfulFix = (Long) mbs.getAttribute(mxbeanName, "TimeSinceLastSuccessfulFix");
    assertNotNull(timeSinceLastSuccessfulFix);
    if (timeSinceLastSuccessfulFix == 0) {
        assertEquals("No files need to fix", 0, cnode.blockIntegrityMonitor.approximateNumRecoverableFiles);
    }/*from   www . j a va 2 s.  c o  m*/
    LOG.info("timeSinceLastSuccessfulFix:" + timeSinceLastSuccessfulFix + "\t"
            + "approximateNumRecoverableFiles:" + cnode.blockIntegrityMonitor.approximateNumRecoverableFiles
            + "\t" + "lastSuccessfulFixTime:" + cnode.blockIntegrityMonitor.lastSuccessfulFixTime);
}

From source file:org.sakaiproject.kernel.component.KernelLifecycle.java

/**
 * Stop the kernel.// ww  w  .  java 2  s .co  m
 */
public void stop() {
    LOG.info("Component Lifecyle is stopping");
    try {
        lifecycleEvent(CommonLifecycleEvent.BEFORE_STOP);
        lifecycleEvent(CommonLifecycleEvent.STOP);
        componentManager.stop();
        serviceManager.stop();
        kernel.stop();
        lifecycleEvent(CommonLifecycleEvent.AFTER_STOP);
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName kernel = new ObjectName(Kernel.MBEAN_KERNEL);
        mbs.unregisterMBean(kernel);
    } catch (Throwable ex) {
        LOG.error("Failed to stop Component Lifecycle ", ex);
    }

}

From source file:org.wso2.carbon.andes.internal.QpidServiceComponent.java

/**
 * Check if the broker is up and running
 *
 * @return true if the broker is running or false otherwise
 *//*from ww w. j  a va 2  s. c  om*/
private boolean isBrokerRunning() {
    boolean response = false;

    try {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        Set<ObjectName> set = mBeanServer
                .queryNames(new ObjectName("org.wso2.andes:type=VirtualHost.VirtualHostManager,*"), null);

        if (set.size() > 0) { // Virtual hosts created, hence broker running.
            response = true;
        }
    } catch (MalformedObjectNameException e) {
        log.error("Error checking if broker is running.", e);
    }

    return response;
}

From source file:com.facebook.infrastructure.service.StorageService.java

private void init() {
    // Register this instance with JMX
    try {//ww w. j  av  a  2s  .  co m
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(this, new ObjectName("com.facebook.infrastructure.service:type=StorageService"));
    } catch (Exception e) {
        logger_.error(LogUtil.throwableToString(e));
    }
}

From source file:org.rhq.core.pc.measurement.MeasurementManager.java

public void shutdown() {
    if (this.collectorThreadPool != null) {
        this.collectorThreadPool.shutdownNow();
    }/* w ww.ja v a  2  s  .c  o m*/

    if (this.senderThreadPool != null) {
        this.senderThreadPool.shutdownNow();
    }

    if (configuration.isStartManagementBean()) {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        try {
            server.unregisterMBean(new ObjectName(OBJECT_NAME));
        } catch (JMException e) {
            LOG.warn("Unable to unregister MeasurementManagerMBean", e);
        }
    }
}

From source file:com.ngdata.sep.impl.fork.ForkedReplicationSource.java

/**
 * SEP change - new method.//from  w w  w.  j  a  v a2 s . co m
 */
private void registerMBean() {
    try {
        ManagementFactory.getPlatformMBeanServer().registerMBean(infoMBean, getMBeanName());
    } catch (Exception e) {
        LOG.warn("Error registering mbean", e);
    }
}

From source file:org.apache.camel.management.DefaultManagementAgent.java

protected MBeanServer findOrCreateMBeanServer() {

    // return platform mbean server if the option is specified.
    if (usePlatformMBeanServer) {
        return ManagementFactory.getPlatformMBeanServer();
    }/*from   www.  j  a v a2s  .c  o m*/

    // look for the first mbean server that has match default domain name
    List<MBeanServer> servers = (List<MBeanServer>) MBeanServerFactory.findMBeanServer(null);

    for (MBeanServer server : servers) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found MBeanServer with default domain " + server.getDefaultDomain());
        }

        if (mBeanServerDefaultDomain.equals(server.getDefaultDomain())) {
            return server;
        }
    }

    // create a mbean server with the given default domain name
    return MBeanServerFactory.createMBeanServer(mBeanServerDefaultDomain);
}