List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.sakaiproject.kernel.component.core.SharedClassLoaderContainer.java
/** * Stop the classloader container, removing the MBean from the MBean server. * @see org.sakaiproject.kernel.api.RequiresStop#stop() *//* ww w . j a v a2 s .c om*/ public void stop() { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName common = new ObjectName(CommonObject.MBEAN_COMMON + ".sharedclassloader"); mbs.unregisterMBean(common); LOG.info("Shared Classloader Container stopped Ok"); } catch (JMException e) { LOG.debug( "Cant stop the shared classloader bean, this will cause problems if the kernel is restarted in this jvm " + e.getMessage(), e); } }
From source file:com.twitter.hraven.hadoopJobMonitor.HadoopJobMonitorService.java
public void init() { YarnConfiguration yConf = new YarnConfiguration(); DefaultMetricsSystem.initialize("HadoopJobMonitor"); String logDir = System.getProperty("hadoopJobMonitor.log.dir"); if (logDir == null) logDir = "/tmp"; MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try {//from ww w .j ava 2 s. com ObjectName name = new ObjectName( "com.twitter.hraven.hadoopJobMonitor.jmx:type=" + WhiteList.class.getSimpleName()); WhiteList.init(logDir); WhiteList mbean = WhiteList.getInstance(); mbs.registerMBean(mbean, name); LOG.error("Current whitelist is: \n" + mbean.getExpirations()); } catch (Exception e) { LOG.fatal("Error in retriving white list from dir " + logDir, e); } metrics = HadoopJobMonitorMetrics.initSingleton(conf); rmDelegate = new ResourceMgrDelegate(yConf); clientCache = new ClientCache(conf, rmDelegate); AppConfCache.init(conf); ProgressCache.init(conf); Mail.init(conf); Notifier.init(conf); clusterCheckerExecutor = Executors .newSingleThreadScheduledExecutor(new ClusterStatusChecker.SimpleThreadFactory()); int concurrentAppCheckers = conf.getInt(HadoopJobMonitorConfiguration.NEW_APP_CHECKER_CONCURRENCY, HadoopJobMonitorConfiguration.DEFAULT_NEW_APP_CHECKER_CONCURRENCY); appCheckerExecutor = new BlockingExecutor(concurrentAppCheckers, new AppStatusChecker.SimpleThreadFactory()); }
From source file:rapture.jmx.JmxServer.java
private void registerBean(Object object, String objNameStr) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try {// w w w . j a va 2s .co m ObjectName objectName = new ObjectName(objNameStr); if (!mbs.isRegistered(objectName)) { mbs.registerMBean(object, objectName); } } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) { log.warn(String.format("Registering a bean with name [%s] caused an exception", objNameStr), e); } }
From source file:org.springframework.jmx.support.JmxUtils.java
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @param agentId the agent identifier of the MBeanServer to retrieve. * If this parameter is {@code null}, all registered MBeanServers are considered. * If the empty String is given, the platform MBeanServer will be returned. * @return the {@code MBeanServer} if found * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer(String) *///from w w w .j a va2s. com public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { MBeanServer server = null; // null means any registered server, but "" specifically means the platform server if (!"".equals(agentId)) { List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId); if (!CollectionUtils.isEmpty(servers)) { // Check to see if an MBeanServer is registered. if (servers.size() > 1 && logger.isWarnEnabled()) { logger.warn("Found more than one MBeanServer instance" + (agentId != null ? " with agent id [" + agentId + "]" : "") + ". Returning first from list."); } server = servers.get(0); } } if (server == null && !StringUtils.hasLength(agentId)) { // Attempt to load the PlatformMBeanServer. try { server = ManagementFactory.getPlatformMBeanServer(); } catch (SecurityException ex) { throw new MBeanServerNotFoundException("No specific MBeanServer found, " + "and not allowed to obtain the Java platform MBeanServer", ex); } } if (server == null) { throw new MBeanServerNotFoundException("Unable to locate an MBeanServer instance" + (agentId != null ? " with agent id [" + agentId + "]" : "")); } if (logger.isDebugEnabled()) { logger.debug("Found MBeanServer: " + server); } return server; }
From source file:com.funambol.pushlistener.example.DummyJMXPlugin.java
@Override public void startPlugin() { if (logger.isInfoEnabled()) { logger.info("Starting JMXDummyPlugin"); logger.info("Registering MBean " + MBEAN_NAME); }// w ww.j a va2 s. c o m MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { // Construct the ObjectName for the MBean we will register ObjectName name = new ObjectName(MBEAN_NAME); mbs.registerMBean(this, name); } catch (Exception ex) { logger.error("Error registering mbean '" + MBEAN_NAME + "'", ex); } }
From source file:gridool.metrics.GridNodeMetricsProvider.java
private static void unregisterMBeans() { final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectName name = GridUtils.makeMBeanName("gridool", "GridService", "GridLocalNodeMetrics"); try {//ww w . j a va 2 s .com server.unregisterMBean(name); } catch (InstanceNotFoundException inf) { LOG.warn("Failed unregistering mbean: " + name); } catch (MBeanRegistrationException re) { LOG.warn("Failed unregistering mbean: " + name); } }
From source file:org.codice.alliance.nsili.sourcestoquery.ui.service.SourcesToQuery.java
private void registerMbean() { try {//from w w w.j a v a 2s . com objectName = new ObjectName(SourcesToQuery.class.getName() + ":service=stream"); mBeanServer = ManagementFactory.getPlatformMBeanServer(); } catch (MalformedObjectNameException e) { LOGGER.error("Unable to create Sources to Query Helper MBean.", e); } if (mBeanServer == null) { return; } try { try { mBeanServer.registerMBean(this, objectName); LOGGER.info("Registered Sources to Query Helper MBean under object name: {}", objectName); } catch (InstanceAlreadyExistsException e) { mBeanServer.unregisterMBean(objectName); mBeanServer.registerMBean(this, objectName); LOGGER.info("Re-registered Sources to Query Helper MBean"); } } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) { LOGGER.error("Could not register MBean [{}].", objectName.toString(), e); } }
From source file:org.sakaiproject.kernel.component.KernelLifecycle.java
/** * Execute the start phase of the lifecycle, creating the MBean and registering the newly started * Kernel with JMX./*from ww w . ja va 2 s . c o m*/ * * @see org.sakaiproject.kernel.loader.common.CommonLifecycle#start() */ public void start() { LOG.info("==========PHASE 1 STARTING ================="); try { long start = System.currentTimeMillis(); lifecycleEvent(CommonLifecycleEvent.BEFORE_START); lastLoadDate = new Date(); // Start the kernel MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); RequiredModelMBean model = new RequiredModelMBean(createMBeanInfo()); model.setManagedResource(this, "objectReference"); ObjectName kernelName = new ObjectName(Kernel.MBEAN_KERNEL); mbs.registerMBean(model, kernelName); kernel = new KernelImpl(); kernel.start(); // Start the service manager serviceManager = new ServiceManagerImpl(kernel); serviceManager.start(); // Start the component manager. componentManager = new ComponentManagerImpl(kernel); componentManager.start(); try { System.runFinalization(); Runtime.getRuntime().gc(); CompositeData permGen = null; try { permGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Perm Gen"), "Usage"); } catch (Exception ex) { permGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Perm Gen"), "Usage"); } CompositeData tenuredGen; try { tenuredGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Tenured Gen"), "Usage"); } catch (Exception ex) { tenuredGen = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=CMS Old Gen"), "Usage"); } CompositeData codeCache = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Code Cache"), "Usage"); CompositeData edenSpace = null; try { edenSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Eden Space"), "Usage"); } catch (Exception ex) { edenSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Par Eden Space"), "Usage"); } CompositeData survivorSpace = null; try { survivorSpace = (CompositeData) mbs .getAttribute(new ObjectName("java.lang:type=MemoryPool,name=Survivor Space"), "Usage"); } catch (Exception ex) { survivorSpace = (CompositeData) mbs.getAttribute( new ObjectName("java.lang:type=MemoryPool,name=Par Survivor Space"), "Usage"); } long permGenUsed = Long.parseLong(String.valueOf(permGen.get("used"))); long codeCacheUsed = Long.parseLong(String.valueOf(codeCache.get("used"))); long edenSpaceUsed = Long.parseLong(String.valueOf(edenSpace.get("used"))); long tenuredGenUsed = Long.parseLong(String.valueOf(tenuredGen.get("used"))); long survivorSpaceUsed = Long.parseLong(String.valueOf(survivorSpace.get("used"))); LOG.info("Memory Stats after startup\n" + "\tPermgen Used " + permGenUsed / (ONEM) + " MB\n" + "\tCode Cache Used " + codeCacheUsed / (ONEM) + " MB\n" + "\tEden Used " + edenSpaceUsed / (ONEM) + " MB\n" + "\tTenured Used " + tenuredGenUsed / (ONEM) + " MB\n" + "\tSurvivour Used " + survivorSpaceUsed / (ONEM) + " MB"); } catch (RuntimeException ex2) { LOG.info("Startup Memory Stats Not available ", ex2); } catch (Exception ex2) { LOG.info("Startup Memory Stats Not available ", ex2); } lifecycleEvent(CommonLifecycleEvent.START); lifecycleEvent(CommonLifecycleEvent.AFTER_START); loadTime = System.currentTimeMillis() - start; } catch (Throwable ex) { LOG.error("Failed to start Component Lifecycle ", ex); throw new Error("Failed to start Component Lifecycle ", ex); } LOG.info("============END of LIFECYCLE STARTUP==============================="); }
From source file:dk.netarkivet.common.management.MBeanConnectorCreator.java
/** * Registers an RMI connector to the local mbean server in a private RMI * registry, under the name "jmxrmi". The port for the registry is read from * settings, and the RMI port used for exposing the connector is also read * from settings. Access to the mbean server is restricted by the rules set * in the password file, likewise read from settings. * * @throws IOFailure on trouble exposing the server. *//*w w w . j a va 2s. c om*/ public static synchronized void exposeJMXMBeanServer() { try { if (!isExposed) { int jmxPort = Settings.getInt(CommonSettings.JMX_PORT); int rmiPort = Settings.getInt(CommonSettings.JMX_RMI_PORT); String passwordFile = Settings.get(CommonSettings.JMX_PASSWORD_FILE); // Create a private registry for the exposing the JMX connector. LocateRegistry.createRegistry(jmxPort); // Create a URL that signifies that we wish to use the local // registry created above, and listen for rmi callbacks on the // RMI port of this machine, exposing the mbeanserver with the // name "jmxrmi". String canonicalHostName = SystemUtils.getLocalHostName(); JMXServiceURL url = new JMXServiceURL(MessageFormat.format(SERVICE_JMX_RMI_URL, canonicalHostName, Integer.toString(rmiPort), Integer.toString(jmxPort))); // Insert the password file into environment used when creating // the connector server. Map<String, Serializable> env = new HashMap<String, Serializable>(); env.put(ENVIRONMENT_PASSWORD_FILE_PROPERTY, passwordFile); // Register the connector to the local mbean server in this // registry under that URL, using the created environment // settings. MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); // Start the connector server. cs.start(); isExposed = true; // Register the JMX server at the registry. MonitorRegistryClientFactory.getInstance().register(canonicalHostName, Settings.getInt(CommonSettings.JMX_PORT), Settings.getInt(CommonSettings.JMX_RMI_PORT)); if (log.isInfoEnabled()) { log.info("Registered mbean server in registry on port " + jmxPort + " communicating on port " + rmiPort + " using password file '" + passwordFile + "'." + "\nService URL is " + url.toString()); } } } catch (IOException e) { throw new IOFailure("Error creating and registering an" + " RMIConnector to the platform mbean server.", e); } }
From source file:org.apache.hadoop.hdfs.server.namenode.TestFSNamesystemMBean.java
@Test public void test() throws Exception { Configuration conf = new Configuration(); MiniDFSCluster cluster = null;/* w ww .j a v a 2s . co m*/ try { cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNameNode().namesystem; MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState"); Object pendingDeletionBlocks = mbs.getAttribute(mxbeanName, "PendingDeletionBlocks"); assertNotNull(pendingDeletionBlocks); assertTrue(pendingDeletionBlocks instanceof Long); } finally { if (cluster != null) { cluster.shutdown(); } } }