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:com.github.stephanarts.cas.ticket.registry.ZMQTicketRegistry.java

/**
 * {@inheritDoc}//from  ww w.  j  a  v  a2 s. co  m
 *
 */
@Override
public void destroy() throws Exception {
    this.provider.cleanup();
    this.registryBroker.cleanup();
    this.pacemaker.destroy();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbs.unregisterMBean(this.mbeanName);
    return;
}

From source file:org.opendaylight.infrautils.diagstatus.MBeanUtils.java

@Nullable
public static Object getMBeanAttribute(String objName, String attribute) throws JMException {
    ObjectName objectName = new ObjectName(objName);
    MBeanServer platformMbeanServer = ManagementFactory.getPlatformMBeanServer();
    return platformMbeanServer.getAttribute(objectName, attribute);
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.MMXPlugin.java

public void initializePlugin(PluginManager manager, File pluginDirectory) {
    /*//w w  w  .j  a v a  2  s. c o m
      Initialize properties so that all the properties added by the plugin schema upgrade are loaded
     */
    JiveProperties.getInstance().init();
    //log the java version
    String version = System.getProperty("java.version");
    String vendor = System.getProperty("java.vendor");
    String vmName = System.getProperty("java.vm.name");
    Log.warn("Java details vendor:{} version:{} vmName:{}", vendor, version, vmName);

    {
        try {
            JiveGlobals.setProperty(MMXConfigKeys.MMX_VERSION, MMXVersion.getVersion());
            Log.debug("mmx properties updated");
        } catch (Exception e) {
            Log.error("Problem in reading java properties", e);
        }
    }

    Log.info("MMX version:" + MMXVersion.getVersion());

    /**
     * register the config MBean
     */
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mbeanName = new ObjectName(MMXServerConstants.MMX_MBEAN_NAME);
        MMXManagedConfigurationMBean mbean = new MMXManagedConfiguration(MMXConfiguration.getConfiguration());
        mbs.registerMBean(mbean, mbeanName);
    } catch (Throwable t) {
        Log.warn("Configuration MBean registration failed", t);
    }

    // Add Context event dispatcher
    try {
        Class.forName(GeoEventDispatcher.class.getName());
        contextDispatcher = ContextDispatcherFactory.getInstance()
                .getDispatcher((GeoEventDispatcher.class.getName()));
    } catch (IllegalAccessException e) {
        Log.error("event dispatcher error", e);
    } catch (InstantiationException e) {
        Log.error("event dispatcher error", e);
    } catch (ClassNotFoundException e) {
        Log.error("event dispatcher error", e);
    }

    XMPPServer server = XMPPServer.getInstance();
    IQRouter iqRouter = server.getIQRouter();

    // Add IQHandler to register an application for push notification and
    // generate a pair of app-key and api-key for the client app.
    mIQAppRegHandler = new AppHandler("appreg");
    mIQDevRegHandler = new DeviceHandler("devreg");
    mIQUserRegHandler = new MMXUserHandler("userreg");
    mIQMessageStateHandler = new MessageStateHandler("msgstate");
    mIQPubSubHandler = new MMXPubSubHandler("pubsub");

    mIQWakeupNSHandler = new MMXWakeupNSHandler("wakeupns");
    mIQPushNSHandler = new MMXPushNSHandler("pushns");
    mIQMsgAckNSHandler = new MsgAckIQHandler("msgack");

    mmxPacketInterceptor = new MMXPacketInterceptor(new MMXMessageHandlingRule());

    iqRouter.addHandler(mIQAppRegHandler);
    iqRouter.addHandler(mIQDevRegHandler);
    iqRouter.addHandler(mIQUserRegHandler);
    iqRouter.addHandler(mIQMessageStateHandler);
    iqRouter.addHandler(mIQPubSubHandler);
    iqRouter.addHandler(mIQWakeupNSHandler);
    iqRouter.addHandler(mIQPushNSHandler);
    iqRouter.addHandler(mIQMsgAckNSHandler);

    Log.info("App Management Plugin is initialized");

    InterceptorManager im = InterceptorManager.getInstance();
    im.addInterceptor(mmxPacketInterceptor);
    Log.info("MMXPacketInterceptor is initialized");

    if (ClusterManager.isClusteringEnabled()) {
        Log.debug("initializePlugin : clustering is available, timer tasks will start on joining cluster");
        ClusterManager.addListener(this);
    } else {
        Log.debug("initializePlugin : Clustering is disabled, starting scheduled tasks");
        startSchedulededTasks();
    }

    publicAPIServer = new MMXPublicAPIServer();
    publicAPIServer.start();

    //initialize the APNS connection pool.
    initializeAPNSConnectionPool();

    adminAPIServer = new MMXAdminAPIServer();
    adminAPIServer.start();

}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

/**
 * Initialize this MBean and register it with the MBean server
 *///from   ww  w. j a va  2  s  .c om
public void init() {
    try {
        if (objectName == null) {
            objectName = new ObjectName(ConfigurationAdminMBean.OBJECTNAME);
        }
        if (mBeanServer == null) {
            mBeanServer = ManagementFactory.getPlatformMBeanServer();
        }
        try {
            mBeanServer.registerMBean(this, objectName);
        } catch (InstanceAlreadyExistsException iaee) {
            // Try to remove and re-register
            LOGGER.info("Re-registering SchemaLookup MBean");
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
        }
    } catch (Exception e) {
        LOGGER.warn("Exception during initialization: ", e);
        throw new RuntimeException(e);
    }
}

From source file:org.apache.synapse.JmxAdapter.java

/**
 * Lazily creates the RMI registry and starts the JMX connector server based on the 
 *
 * @throws  SynapseException  if the JMX configuration is erroneous and/or the connector server
 *                            cannot be started
 *///  ww w  . j av a  2 s .  c o  m
public void start() {
    initConfiguration();

    try {
        boolean registryCreated = false;
        int jndiPort = jmxInformation.getJndiPort();

        // automatic detection starting at base port
        if (jndiPort == 0) {
            jndiPort = JNDI_AUTO_PORT_OFFSET;
            for (int retries = 0; !registryCreated && (retries < 100); retries++) {
                try {
                    RMIRegistryController.getInstance().createLocalRegistry(jndiPort);
                    registryCreated = true;
                } catch (Exception ignored) {
                    jndiPort++;
                    log.warn("Trying alternate port " + jndiPort);
                }
            }
            jmxInformation.setJndiPort(jndiPort);
        } else {
            RMIRegistryController.getInstance().createLocalRegistry(jndiPort);
            registryCreated = true;
        }

        if (registryCreated) {
            jmxInformation.updateJMXUrl();
            JMXServiceURL url = new JMXServiceURL(jmxInformation.getJmxUrl());
            Map<String, Object> env = createContextMap();
            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
            try {
                connectorServer.start();
            } catch (IOException ex) {
                log.warn("Cannot start JMXConnectorServer on " + jmxInformation.getJmxUrl(), ex);
            }
        }
    } catch (Exception ex) {
        log.error("Error while setting up remote JMX connector", ex);
    }
}

From source file:org.apache.hadoop.hbase.http.jmx.JMXJsonServlet.java

/**
 * Initialize this servlet.// w ww  . ja v  a  2 s.c  om
 */
@Override
public void init() throws ServletException {
    // Retrieve the MBean server
    mBeanServer = ManagementFactory.getPlatformMBeanServer();
    this.jsonBeanWriter = new JSONBean();
}

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

private void unregisterDocumentManagementServiceMBean() {
    try {/*from www. j  ava  2  s  . c o m*/
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName mbeanName = new ObjectName(DocumentManagementServiceMXBean.NAME);

        if (mbeanServer.isRegistered(mbeanName)) {
            mbeanServer.unregisterMBean(mbeanName);
        }
    } catch (Exception e) {
        log.error("Failed to unregister MBean.", e);
    }
}

From source file:org.codice.ddf.admin.core.impl.AdminConsoleService.java

/** Initialize this MBean and register it with the MBean server */
public void init() {
    try {//from   www . j  av a 2 s .  c  om
        if (objectName == null) {
            objectName = new ObjectName(AdminConsoleServiceMBean.OBJECT_NAME);
        }
        if (mBeanServer == null) {
            mBeanServer = ManagementFactory.getPlatformMBeanServer();
        }
        try {
            mBeanServer.registerMBean(this, objectName);
        } catch (InstanceAlreadyExistsException iaee) {
            // Try to remove and re-register
            LOGGER.debug("Re-registering SchemaLookup MBean");
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
        }
    } catch (Exception e) {
        LOGGER.info("Exception during initialization: ", e);
        throw new RuntimeException(e);
    }
}

From source file:net.zcarioca.jmx.services.impl.MBeanObjectServiceImpl.java

private MBeanServer getPlatformMBeanServer() {
    synchronized (mbeanServer) {
        if (mbeanServer == null) {
            // find the JBoss mbean server, if it exists
            Collection<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
            if (mbeanServers != null) {
                if (mbeanServers.size() == 1) {
                    return mbeanServers.iterator().next();
                } else if (mbeanServers.size() > 1) {
                    for (MBeanServer mbeanServer : mbeanServers) {
                        String domain = mbeanServer.getDefaultDomain();
                        if (StringUtils.contains(domain, "jboss")) {
                            return mbeanServer;
                        }//  w  ww .  j  av a2s  .com
                    }
                }
            }
            mbeanServer = ManagementFactory.getPlatformMBeanServer();
        }
        return mbeanServer;
    }
}

From source file:org.codice.ddf.admin.application.service.impl.ApplicationServiceBean.java

/**
 * Creates an instance of an ApplicationServiceBean
 *
 * @param appService ApplicationService that is running in the system.
 * @throws ApplicationServiceException If an error occurs when trying to construct the MBean
 *                                     objects.
 *//*  w  w w. j  a v  a2  s.c o  m*/
public ApplicationServiceBean(ApplicationService appService, ConfigurationAdminExt configAdminExt,
        MBeanServer mBeanServer) throws ApplicationServiceException {
    this.appService = appService;
    this.configAdminExt = configAdminExt;
    this.mBeanServer = mBeanServer;
    try {
        objectName = new ObjectName(ApplicationService.class.getName() + ":service=application-service");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException mone) {
        throw new ApplicationServiceException("Could not create objectname.", mone);
    }
}