List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.dspace.kernel.DSpaceKernelManager.java
/** * Get the kernel. This will be a single instance for the JVM, but * the method will retrieve the same instance regardless of this * object instance./*from ww w .j a v a 2 s .c om*/ * * @param name this is the name of this kernel instance. If you do * not know what this is then use null. * @return the DSpace kernel * @throws IllegalStateException if the kernel is not available or not running */ public DSpaceKernel getKernel(String name) { // Are we getting a named kernel? if (!StringUtils.isEmpty(name)) { String checkedName = checkName(name); if (namedKernelMap.containsKey(checkedName)) { return namedKernelMap.get(checkedName); } if (defaultKernel != null && checkedName.equals(defaultKernel.getMBeanName())) { return defaultKernel; } synchronized (lock) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { ObjectName kernelName = new ObjectName(checkedName); DSpaceKernel namedKernel = (DSpaceKernel) mbs.invoke(kernelName, "getManagedBean", null, null); if (namedKernel == null || !namedKernel.isRunning()) { throw new IllegalStateException( "The DSpace kernel is not started yet, please start it before attempting to use it"); } namedKernelMap.put(checkedName, namedKernel); return namedKernel; } catch (InstanceNotFoundException e) { throw new IllegalStateException(e); } catch (MBeanException e) { throw new IllegalStateException(e); } catch (ReflectionException e) { throw new IllegalStateException(e); } catch (MalformedObjectNameException e) { throw new IllegalStateException(e); } catch (NullPointerException e) { throw new IllegalStateException(e); } } } return defaultKernel; }
From source file:org.apache.james.modules.server.JMXServer.java
public void register(String key, Object remote) throws Exception { ManagementFactory.getPlatformMBeanServer().registerMBean(remote, new ObjectName(key)); synchronized (lock) { registeredKeys.add(key);//from ww w .ja v a 2s . com } }
From source file:com.alibaba.dragoon.common.protocol.MBeanServerMessageHandler.java
public MBeanServerMessageHandler(MBeanServer mbeanServer) { super();//from ww w .j a v a 2s . co m if (mbeanServer == null) { this.mbeanServer = ManagementFactory.getPlatformMBeanServer(); } else { this.mbeanServer = mbeanServer; } }
From source file:com.streamsets.datacollector.http.JMXJsonServlet.java
/** * Initialize this servlet./*from ww w . j av a2s .c om*/ */ @Override public void init() throws ServletException { // Retrieve the MBean server mBeanServer = ManagementFactory.getPlatformMBeanServer(); jsonFactory = new JsonFactory(); }
From source file:com.rackspacecloud.blueflood.tracker.Tracker.java
public synchronized void register() { if (isRegistered) return;/* w w w. j av a 2 s . c o m*/ try { ObjectName objectName = new ObjectName(trackerName); // register TrackerMBean only if not already registered MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); if (!mBeanServer.isRegistered(objectName)) { ManagementFactory.getPlatformMBeanServer().registerMBean(instance, objectName); } isRegistered = true; log.info("MBean registered as " + trackerName); } catch (Exception exc) { log.error("Unable to register MBean " + trackerName, exc); } }
From source file:com.rackspacecloud.blueflood.cache.TtlCache.java
public TtlCache(String label, TimeValue expiration, int cacheConcurrency, final InternalAPI internalAPI) { try {/*from www . ja v a2s .c o m*/ final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); final String name = String.format( TtlCache.class.getPackage().getName() + ":type=%s,scope=%s,name=Stats", TtlCache.class.getSimpleName(), label); final ObjectName nameObj = new ObjectName(name); mbs.registerMBean(this, nameObj); instantiateYammerMetrics(TtlCache.class, label, nameObj); } catch (Exception ex) { log.error("Unable to register mbean for " + getClass().getName()); } generalErrorMeter = Metrics.newMeter(TtlCache.class, "Load Errors", label, "Rollups", TimeUnit.MINUTES); httpErrorMeter = Metrics.newMeter(TtlCache.class, "Http Errors", label, "Rollups", TimeUnit.MINUTES); CacheLoader<String, Map<ColumnFamily<Locator, Long>, TimeValue>> loader = new CacheLoader<String, Map<ColumnFamily<Locator, Long>, TimeValue>>() { // values from the default account are used to build a ttl map for tenants that do not exist in the // internal API. These values are put into the cache, meaning subsequent cache requests do not // incur a miss and hit the internal API. private final Account DEFAULT_ACCOUNT = new Account() { @Override public TimeValue getMetricTtl(String resolution) { return SAFETY_TTLS .get(AstyanaxIO.getColumnFamilyMapper().get(Granularity.fromString(resolution).name())); } }; @Override public Map<ColumnFamily<Locator, Long>, TimeValue> load(final String key) throws Exception { // load account, build ttl map. try { Account acct = internalAPI.fetchAccount(key); return buildTtlMap(acct); } catch (HttpResponseException ex) { // cache the default value on a 404. this means that we will not be hammering the API for values // that are constantly not there. The other option was to let the Http error bubble out, use a // and value from SAFETY_TTLS. But the same thing (an HTTP round trip) would happen the very next // time a TTL is requested. if (ex.getStatusCode() == 404) { httpErrorMeter.mark(); log.warn(ex.getMessage()); return buildTtlMap(DEFAULT_ACCOUNT); } else throw ex; } } }; cache = CacheBuilder.newBuilder().expireAfterWrite(expiration.getValue(), expiration.getUnit()) .concurrencyLevel(cacheConcurrency).recordStats().build(loader); }
From source file:co.runrightfast.core.utils.JmxUtils.java
static void unregisterApplicationMBean(final String domain, final Class<?> mbeanType) { final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); try {/* w w w . j a va 2 s . co m*/ mbeanServer.unregisterMBean(applicationMBeanObjectName(domain, mbeanType)); } catch (final InstanceNotFoundException | MBeanRegistrationException ex) { final Logger log = Logger.getLogger(JmxUtils.class.getName()); log.logp(WARNING, JmxUtils.class.getName(), "unregisterApplicationMBean", "failed", ex); } }
From source file:org.sakaiproject.kernel.loader.server.test.DummySharedClassLoaderContainer.java
/** * Stop the classloader container, removing the MBean from the MBean server. * @see org.sakaiproject.kernel.api.RequiresStop#stop() *///from ww w. j ava 2 s. c o m 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.info( "Cant stop the shared classloader bean, this will cause problems if the kernel is restarted in this jvm " + e.getMessage(), e); } }
From source file:co.paralleluniverse.common.monitoring.PeriodicMonitor.java
private void registerMBean() { try {/*from ww w. j a va 2s. co m*/ LOG.info("Registering MBean {}", name); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName(name); mbs.registerMBean(this, mxbeanName); timer.addNotificationListener(this, new NotificationFilter() { @Override public boolean isNotificationEnabled(Notification notification) { return "tickTimer".equals(notification.getType()); } }, null); this.registered = true; } catch (InstanceAlreadyExistsException ex) { throw new RuntimeException(ex); } catch (MBeanRegistrationException ex) { throw new RuntimeException(ex); } catch (NotCompliantMBeanException ex) { throw new AssertionError(ex); } catch (MalformedObjectNameException ex) { throw new AssertionError(ex); } }
From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggeneratorTest.java
@Before public void setUp() throws Exception { jmxConfiggenerator = new JmxDatacollectionConfiggenerator( new Slf4jLogAdapter(JmxDatacollectionConfiggenerator.class)); platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName("org.opennms.tools.jmxconfiggenerator.jmxconfig:type=JmxTest"); JmxTestDummyMBean testMBean = new JmxTestDummy(); platformMBeanServer.registerMBean(testMBean, objectName); }