List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
private static void unregisterMBeanIfPresent() { // We want to make sure mBean will be unregistered final Properties dbcpProperties = loadDbcpProperties(); if (dbcpProperties.containsKey(PROP_JMX) && Boolean.valueOf(dbcpProperties.getProperty(PROP_JMX))) { final String mBeanName = dbcpProperties.getProperty(PROP_MBEANNAME); try {//from ww w . j a v a 2 s.c om final ObjectName objectName = ObjectName.getInstance(dbcpProperties.getProperty(PROP_MBEANNAME)); final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); if (platformMBeanServer.isRegistered(objectName)) { platformMBeanServer.unregisterMBean(objectName); } } catch (Exception e) { log.error("Exception un-registering MBean data source " + mBeanName, e); } } }
From source file:com.stratio.cassandra.lucene.IndexService.java
/** Closes and removes all the index files. */ final void delete() { try {/*ww w . j a v a 2s . c om*/ queue.shutdown(); ManagementFactory.getPlatformMBeanServer().unregisterMBean(mbean); } catch (JMException e) { logger.error("Error while unregistering Lucene index MBean", e); } finally { lucene.delete(); } }
From source file:org.eclipse.gyrex.http.jetty.internal.JettyEngineApplication.java
@Override public Object start(final IApplicationContext context) throws Exception { if (JettyDebug.engine) { LOG.debug("Starting Jetty engine."); }// w ww .j a v a2 s . c o m // set stop signal final CountDownLatch stopSignal = new CountDownLatch(1); if (!stopSignalRef.compareAndSet(null, stopSignal)) throw new IllegalStateException("Jetty engine already running!"); try { // FIXME timing issue with "ON_CLOUD_CONNECT" and ZooKeeperBasedPreferences // there is a bit of a timing issue here; we need to wait a bit in order // for the PlatformPreferences to be available int timeout = 5000; while (timeout > 0) { try { CloudScope.INSTANCE.getNode(HttpJettyActivator.SYMBOLIC_NAME); break; } catch (final IllegalStateException e) { if (JettyDebug.engine) { LOG.debug("Platform preferences not available. Jetty start will be delayed."); try { timeout -= 500; Thread.sleep(500); } catch (final Exception e1) { // interrupted Thread.currentThread().interrupt(); } } } } // initialize (but do not start) the Jetty server final Server server = new Server(); // enable Jetty JMX support final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); server.addBean(mbContainer); // register Jetty loggers as MBeans mbContainer.beanAdded(server, Log.getRootLogger()); // create gateway JettyGateway gateway = new JettyGateway(server); // tweak server config configureServer(server); // start the server server.start(); // don't expose too detailed version info // (must be set after server started) HttpGenerator.setServerVersion("7"); if (JettyDebug.engine) { LOG.debug("Jetty server started!"); LOG.debug(server.dump()); } // activate HTTP gateway final ServiceRegistration<IHttpGateway> gatewayServiceRegistration = HttpJettyActivator.getInstance() .getServiceHelper().registerService(IHttpGateway.class, gateway, "Eclipse Gyrex", "Jetty based HTTP gateway.", null, null); if (JettyDebug.engine) { LOG.debug("Jetty HTTP gateway registered!"); LOG.debug(server.dump()); } // signal running context.applicationRunning(); // wait for stop try { stopSignal.await(); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); } // remove gateway gatewayServiceRegistration.unregister(); // remove metrics while (!metricsRegistrations.isEmpty()) { for (final MetricSet metric : metricsRegistrations.keySet()) { unregisterMetrics(metric); } } // shutdown Jetty try { server.stop(); } catch (final Exception e) { if (JettyDebug.debug) { LOG.warn("Error while stopping Jetty. {}", new Object[] { ExceptionUtils.getRootCauseMessage(e), e }); } else { LOG.warn("Error while stopping Jetty. {}", ExceptionUtils.getRootCauseMessage(e)); } } // destroy gateway if (null != gateway) { gateway.close(); gateway = null; } if (JettyDebug.engine) { LOG.debug("Jetty engine shutdown complete."); } // exit final Throwable error = jettyErrorRef.getAndSet(null); return error == null ? IApplication.EXIT_OK : EXIT_ERROR; } catch (final Exception e) { // shutdown the whole server when Jetty does not come up LOG.error("Unable to start Jetty. Please check the log files. System will be shutdown.", e); // ServerApplication.signalShutdown(new Exception("Could not start the Jetty server. " + ExceptionUtils.getRootCauseMessage(e), e)); return EXIT_ERROR; } finally { // done, now reset signal to allow further starts stopSignalRef.compareAndSet(stopSignal, null); } }
From source file:com.bigdata.dastor.db.ColumnFamilyStore.java
public static ColumnFamilyStore createColumnFamilyStore(String table, String columnFamily) throws IOException { /*//from www.j a v a 2 s .c o m * Get all data files associated with old Memtables for this table. * These files are named as follows <Table>-1.db, ..., <Table>-n.db. Get * the max which in this case is n and increment it to use it for next * index. */ List<Integer> generations = new ArrayList<Integer>(); String[] dataFileDirectories = DatabaseDescriptor.getAllDataFileLocationsForTable(table); for (String directory : dataFileDirectories) { File fileDir = new File(directory); File[] files = fileDir.listFiles(); for (File file : files) { String filename = file.getName(); String cfName = getColumnFamilyFromFileName(filename); if (cfName.equals(columnFamily)) { generations.add(getGenerationFromFileName(filename)); } } } Collections.sort(generations); int value = (generations.size() > 0) ? (generations.get(generations.size() - 1)) : 0; ColumnFamilyStore cfs = new ColumnFamilyStore(table, columnFamily, "Super".equals(DatabaseDescriptor.getColumnType(table, columnFamily)), value); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { String mbeanName = "com.bigdata.dastor.db:type=ColumnFamilyStores,keyspace=" + table + ",columnfamily=" + columnFamily; mbs.registerMBean(cfs, new ObjectName(mbeanName)); } catch (Exception e) { throw new RuntimeException(e); } return cfs; }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Server helper method to register a JMX MBean. MBeans are registered by a * combination of their MBean interface and the custom mbeanName argument. * The mbeanName permits multiple mBeans to be registered under the same * name./*from w ww. ja va 2s. c om*/ * * @param mbean The MBean instance that should be registered * @param mbeanClass The base class for the mbean * @throws ServerRuntimeException */ public static void registerMBean(Object mbean, Class<?> mbeanClass) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { if (logger.isDebugEnabled()) logger.debug("Registering mbean: " + mbean.getClass()); ObjectName name = generateMBeanObjectName(mbeanClass); if (mbs.isRegistered(name)) mbs.unregisterMBean(name); mbs.registerMBean(mbean, name); } catch (Exception e) { throw new ServerRuntimeException( String.format("Unable to register mbean for class %s because '%s'", mbeanClass.getName(), e), e); } }
From source file:org.red5.server.winstone.WinstoneLoader.java
protected void registerJMX() { // register with jmx MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try {/* www. j a v a2 s . c o m*/ ObjectName oName = new ObjectName("org.red5.server:type=WinstoneLoader"); // check for existing registration before registering if (!mbs.isRegistered(oName)) { mbs.registerMBean(this, oName); } else { log.debug("ContextLoader is already registered in JMX"); } } catch (Exception e) { log.warn("Error on jmx registration", e); } }
From source file:mondrian.server.MondrianServerImpl.java
/** * Registers the MonitorImpl associated with this server * as an MBean accessible via JMX./*from w ww . j a v a 2 s . c o m*/ */ private void registerMBean() { if (Util.PreJdk16) { LOGGER.info("JMX is supported in Mondrian only on Java 6+."); return; } MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { ObjectName mxbeanName = new ObjectName("mondrian.server:type=Server-" + id); mbs.registerMBean(getMonitor(), mxbeanName); } catch (MalformedObjectNameException e) { LOGGER.warn("Failed to register JMX MBean", e); } catch (NotCompliantMBeanException e) { LOGGER.warn("Failed to register JMX MBean", e); } catch (InstanceAlreadyExistsException e) { LOGGER.warn("Failed to register JMX MBean", e); } catch (MBeanRegistrationException e) { LOGGER.warn("Failed to register JMX MBean", e); } }
From source file:org.apache.jackrabbit.oak.fixture.OakFixture.java
static Oak newOak(NodeStore nodeStore) { return new Oak(nodeStore).with(ManagementFactory.getPlatformMBeanServer()); }
From source file:org.apache.hadoop.hdfs.server.namenode.TestNameNodeMXBean.java
@Test(timeout = 120000) public void testTopUsersDisabled() throws Exception { final Configuration conf = new Configuration(); // Disable nntop conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false); MiniDFSCluster cluster = null;//from w w w .jav a 2 s . c om try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName("Hadoop:service=NameNode,name=FSNamesystemState"); FileSystem fs = cluster.getFileSystem(); final Path path = new Path("/"); final int NUM_OPS = 10; for (int i = 0; i < NUM_OPS; i++) { fs.listStatus(path); fs.setTimes(path, 0, 1); } String topUsers = (String) (mbs.getAttribute(mxbeanNameFsns, "TopUserOpCounts")); assertNull("Did not expect to find TopUserOpCounts bean!", topUsers); } finally { if (cluster != null) { cluster.shutdown(); } } }
From source file:org.apache.hadoop.hbase.util.JSONBean.java
/** * Dump out all registered mbeans as json on System.out. * @throws IOException//from w w w.j a v a2s . c om * @throws MalformedObjectNameException */ public static void dumpAllBeans() throws IOException, MalformedObjectNameException { try (PrintWriter writer = new PrintWriter(System.out)) { JSONBean dumper = new JSONBean(); try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); jsonBeanWriter.write(mbeanServer, new ObjectName("*:*"), null, false); } } }