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:c3.ops.priam.aws.S3FileSystem.java

@Inject
public S3FileSystem(Provider<AbstractBackupPath> pathProvider, ICompression compress,
        final IConfiguration config, ICredential cred) {
    this.pathProvider = pathProvider;
    this.compress = compress;
    this.config = config;
    int threads = config.getMaxBackupUploadThreads();
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(threads);
    this.executor = new BlockingSubmitThreadPoolExecutor(threads, queue, UPLOAD_TIMEOUT);
    double throttleLimit = config.getUploadThrottle();
    rateLimiter = RateLimiter.create(throttleLimit < 1 ? Double.MAX_VALUE : throttleLimit);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String mbeanName = MBEAN_NAME;
    try {//w w w. j a v  a 2 s . co  m
        mbs.registerMBean(this, new ObjectName(mbeanName));
    } catch (Exception e) {
        logger.warn("Fail to register " + mbeanName);
        //throw new RuntimeException(e);
    }

    s3Client = new AmazonS3Client(cred.getAwsCredentialProvider());
    s3Client.setEndpoint(getS3Endpoint());
}

From source file:com.ning.metrics.collector.guice.module.ServerModule.java

protected void installJMX() {
    bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
    install(new MBeanModule());
}

From source file:org.chorusbdd.chorus.tools.webagent.JmxManagementServerExporter.java

public void startServer() throws Exception {

    // Ensure cryptographically strong random number generator used
    // to choose the object number - see java.rmi.server.ObjID
    ///*from w ww.ja v  a2s .c om*/
    //System.setProperty("java.rmi.server.randomIDs", "true");

    // Start an RMI registry on port 3000.
    //
    if (!registriesCreated.contains(port)) {
        log.info("Creating RMI registry on port " + port);
        LocateRegistry.createRegistry(port);
        registriesCreated.add(port);
    } else {
        //there's no way to shut it dnwn? So if we run a sequence of tests we clean up by unexporting the
        //listener object, and have to reuse the registry instance
        log.info("RMI registry was already running on port " + port);
    }

    // Retrieve the PlatformMBeanServer.
    //
    log.info(usePlatformMBeanServer ? "Using Platform MBean Server" : "Creating the MBean server");
    mBeanServer = usePlatformMBeanServer ? ManagementFactory.getPlatformMBeanServer()
            : MBeanServerFactory.createMBeanServer();

    // Environment map.
    //
    log.info("Initialize the environment map");
    HashMap<String, Object> env = new HashMap<String, Object>();

    // Provide SSL-based RMI socket factories.
    //
    // The protocol and cipher suites to be enabled will be the ones
    // defined by the default JSSE implementation and only server
    // authentication will be required.
    //
    //SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
    //SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory();
    //env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
    //env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);

    // Provide the password file used by the connector server to
    // perform user authentication. The password file is a properties
    // based text file specifying username/password pairs.
    //
    //env.put("jmx.remote.x.password.file", "password.properties");

    // Provide the access level file used by the connector server to
    // perform user authorization. The access level file is a properties
    // based text file specifying username/access level pairs where
    // access level is either "readonly" or "readwrite" access to the
    // MBeanServer operations.
    //
    //env.put("jmx.remote.x.access.file", "access.properties");

    // Create an RMI connector server.
    //
    // As specified in the JMXServiceURL the RMIServer stub will be
    // registered in the RMI registry running in the local host on
    // port 3000 with the name "jmxrmi". This is the same name the
    // out-of-the-box management agent uses to register the RMIServer
    // stub too.
    //
    log.info("Create an RMI connector server");
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + port + "/jmxrmi");
    jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mBeanServer);

    // Start the RMI connector server.
    //
    log.info("Start the JMX connector server on port " + port);
    jmxConnectorServer.start();
}

From source file:org.ngrinder.monitor.share.domain.MBeanClient.java

private void connectClient() throws IOException, TimeoutException {
    if (jmxUrl == null || ("localhost".equals(jmxUrl.getHost()) && jmxUrl.getPort() == 0)) {
        mbeanServerConnection = ManagementFactory.getPlatformMBeanServer();
    } else {//from   w  w  w .java2s. c om
        jmxConnector = connectWithTimeout(jmxUrl, timeout);
        mbeanServerConnection = jmxConnector.getMBeanServerConnection();
    }
    this.connected = true;
}

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

private void doStop() {
    try {//from   w ww . j av  a  2  s. c o m
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        registeredKeys.forEach(key -> {
            try {
                mBeanServer.unregisterMBean(new ObjectName(key));
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        });
        registeredKeys.clear();
        jmxConnectorServer.stop();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

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

private void registerMBean(ComponentContext context, Object object, String serviceClass)
        throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException,
        NotCompliantMBeanException {
    String simpleName = object.getClass().getSimpleName();
    // It is required to do a != Boolean.TRUE to avoid the NPE here.
    if (jmxServices.get(simpleName.toLowerCase()) != Boolean.TRUE) {
        return;//  w  w w.j a va 2 s .co m
    }
    mBeans.push(new ObjectName("org.wso2.carbon:Type=Registry,ConnectorName=" + simpleName));
    ManagementFactory.getPlatformMBeanServer().registerMBean(object, mBeans.peek());
    serviceRegistrations.push(context.getBundleContext().registerService(serviceClass, object, null));
}

From source file:com.netflix.priam.aws.S3FileSystem.java

@Inject
public S3FileSystem(Provider<AbstractBackupPath> pathProvider, ICompression compress,
        final IConfiguration config, ICredential cred) {
    this.pathProvider = pathProvider;
    this.compress = compress;
    this.config = config;
    int threads = config.getMaxBackupUploadThreads();
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(threads);
    this.executor = new BlockingSubmitThreadPoolExecutor(threads, queue, UPLOAD_TIMEOUT);
    double throttleLimit = config.getUploadThrottle();
    rateLimiter = RateLimiter.create(throttleLimit < 1 ? Double.MAX_VALUE : throttleLimit);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String mbeanName = MBEAN_NAME;
    try {//from   w  w w .jav a 2  s.c o m
        mbs.registerMBean(this, new ObjectName(mbeanName));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    s3Client = new AmazonS3Client(cred.getAwsCredentialProvider());
    s3Client.setEndpoint(getS3Endpoint());
}

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

/**
 * Registers this MBean with the MBean Server
 *//* ww  w  . j a v  a  2s. com*/
@Override
public void register() 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(this, getObjectName());
    setupLogging();
}

From source file:org.eclipse.gyrex.monitoring.internal.MetricSetTracker.java

@Override
public void removedService(final ServiceReference<MetricSet> reference,
        final MetricSetJmxRegistration metricSetJmxRegistration) {
    try {//  ww  w  .  j  a v a 2 s.  co m
        // unregister MBean
        final MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        beanServer.unregisterMBean(metricSetJmxRegistration.objectName);
    } catch (final Exception e) {
        LOG.warn("Failed to unregister metric JMX registration {}. {}", metricSetJmxRegistration.objectName,
                ExceptionUtils.getRootCauseMessage(e));
    } finally {
        // unget service
        context.ungetService(reference);
    }
}

From source file:org.dspace.kernel.DSpaceKernelManager.java

/**
 * Register a new kernel MBean with the given name or fail
 * @param mBeanName the bean name to use
 * @param kernel the kernel bean to register
 * @throws IllegalStateException if the MBean cannot be registered
 *///  w ww .  j a v  a2 s . co m
public static void registerMBean(String mBeanName, DSpaceKernel kernel) {
    String checkedMBeanName = DSpaceKernelManager.checkName(mBeanName);
    synchronized (mBeanName) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        try {
            ObjectName name = new ObjectName(checkedMBeanName);
            if (!mbs.isRegistered(name)) {
                // register the MBean
                mbs.registerMBean(kernel, name);
                log.info("Registered new Kernel MBEAN: " + checkedMBeanName + " [" + kernel + "]");
            }
        } catch (MalformedObjectNameException e) {
            throw new IllegalStateException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new IllegalStateException(e);
        } catch (MBeanRegistrationException e) {
            throw new IllegalStateException(e);
        } catch (NotCompliantMBeanException e) {
            throw new IllegalStateException(e);
        } catch (NullPointerException e) {
            throw new IllegalStateException(e);
        }
    }
}