List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.opendaylight.infrautils.diagstatus.MBeanUtils.java
public static <T> T getMBean(String jmxName, Class<T> klass) throws MalformedObjectNameException { return getMBean(jmxName, klass, ManagementFactory.getPlatformMBeanServer()); }
From source file:org.dspace.kernel.DSpaceKernelManager.java
/** * Unregister an MBean if possible/*from w ww . j a v a2s . c om*/ * @param mBeanName the bean name to use * @return true if the MBean was unregistered, false otherwise */ public static boolean unregisterMBean(String mBeanName) { String checkedMBeanName = DSpaceKernelManager.checkName(mBeanName); synchronized (mBeanName) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { mbs.unregisterMBean(new ObjectName(checkedMBeanName)); return true; } catch (InstanceNotFoundException ie) { //If this exception is thrown, the specified MBean is not currently registered //So, we'll ignore the error and return true return true; } catch (Exception e) { //log this issue as a System Warning. Also log the underlying error message. log.warn("Failed to unregister the MBean: " + checkedMBeanName, e); return false; } } }
From source file:org.rhq.core.pc.measurement.MeasurementManager.java
public void initialize() { if (configuration.isStartManagementBean()) { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try {/*from w ww . j a v a 2s.c o m*/ server.registerMBean(this, new ObjectName(OBJECT_NAME)); } catch (JMException e) { LOG.error("Unable to register MeasurementManagerMBean", e); } } this.inventoryManager = PluginContainer.getInstance().getInventoryManager(); int threadPoolSize = configuration.getMeasurementCollectionThreadPoolSize(); long collectionInitialDelaySecs = configuration.getMeasurementCollectionInitialDelay(); if (configuration.isInsideAgent()) { this.collectorThreadPool = new ScheduledThreadPoolExecutor(threadPoolSize, new LoggingThreadFactory(COLLECTOR_THREAD_POOL_NAME, true)); this.senderThreadPool = new ScheduledThreadPoolExecutor(2, new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true)); this.measurementSenderRunner = new MeasurementSenderRunner(this); this.measurementCollectorRunner = new MeasurementCollectorRunner(this); // Schedule the measurement sender to send measurement reports periodically. this.senderThreadPool.scheduleAtFixedRate(measurementSenderRunner, collectionInitialDelaySecs, 30, TimeUnit.SECONDS); // Schedule the measurement collector to collect metrics periodically, whenever there are one or more // metrics due to be collected. this.collectorThreadPool.schedule(new MeasurementCollectionRequester(), collectionInitialDelaySecs, TimeUnit.SECONDS); // Load persistent measurement schedules from the InventoryManager and reconstitute them. Resource platform = PluginContainer.getInstance().getInventoryManager().getPlatform(); reschedule(platform); } }
From source file:org.wso2.andes.kernel.registry.StorageQueueRegistry.java
private boolean isMbeanRegistered(String storageQueue) { Hashtable<String, String> tab = getMbeanObjectnameProp(storageQueue); boolean isRegistered = false; try {/*from w ww.j ava 2s .c o m*/ isRegistered = ManagementFactory.getPlatformMBeanServer() .isRegistered(new ObjectName(ANDES_DOMAIN, tab)); } catch (Exception e) { log.error("Unable to check if an mbean is registered!", e); } return isRegistered; }
From source file:org.apache.hadoop.hdfs.tools.JMXGet.java
/** * @throws Exception// w w w. j ava2 s . co m * initializes MBeanServer */ public void init() throws Exception { err("init: server=" + server + ";port=" + port + ";service=" + service + ";localVMUrl=" + localVMUrl); String url_string = null; // build connection url if (localVMUrl != null) { // use // jstat -snap <vmpid> | grep sun.management.JMXConnectorServer.address // to get url url_string = localVMUrl; err("url string for local pid = " + localVMUrl + " = " + url_string); } else if (!port.isEmpty() && !server.isEmpty()) { // using server and port url_string = "service:jmx:rmi:///jndi/rmi://" + server + ":" + port + "/jmxrmi"; } // else url stays null // Create an RMI connector client and // connect it to the RMI connector server if (url_string == null) { // assume local vm (for example for Testing) mbsc = ManagementFactory.getPlatformMBeanServer(); } else { JMXServiceURL url = new JMXServiceURL(url_string); err("Create RMI connector and connect to the RMI connector server" + url); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); // Get an MBeanServerConnection // err("\nGet an MBeanServerConnection"); mbsc = jmxc.getMBeanServerConnection(); } // Get domains from MBeanServer // err("\nDomains:"); String domains[] = mbsc.getDomains(); Arrays.sort(domains); for (String domain : domains) { err("\tDomain = " + domain); } // Get MBeanServer's default domain // err("\nMBeanServer default domain = " + mbsc.getDefaultDomain()); // Get MBean count // err("\nMBean count = " + mbsc.getMBeanCount()); // Query MBean names for specific domain "hadoop" and service ObjectName query = new ObjectName("Hadoop:service=" + service + ",*"); hadoopObjectNames = new ArrayList<>(5); err("\nQuery MBeanServer MBeans:"); Set<ObjectName> names = new TreeSet<>(mbsc.queryNames(query, null)); for (ObjectName name : names) { hadoopObjectNames.add(name); err("Hadoop service: " + name); } }
From source file:org.apache.streams.local.queues.ThroughputQueue.java
/** * Creates a bounded, registered {@code ThroughputQueue} * * @param maxSize maximum capacity of queue, if maxSize < 1 then unbounded * @param id unique id for this queue to be registered with. if id == NULL then not registered *///ww w. ja v a 2 s. c o m public ThroughputQueue(int maxSize, String id, String streamIdentifier, long startedAt) { if (maxSize < 1) { this.underlyingQueue = new LinkedBlockingQueue<>(); } else { this.underlyingQueue = new LinkedBlockingQueue<>(maxSize); } this.elementsAdded = new AtomicLong(0); this.elementsRemoved = new AtomicLong(0); this.startTime = new AtomicLong(-1); this.active = false; this.maxQueuedTime = 0; this.maxQueueTimeLock = new ReentrantReadWriteLock(); this.totalQueueTime = new AtomicLong(0); if (id != null) { try { ObjectName name = new ObjectName(String.format(NAME_TEMPLATE, id, streamIdentifier, startedAt)); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(this, name); } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { LOGGER.error("Failed to register MXBean : {}", e); throw new RuntimeException(e); } } }
From source file:org.sakaiproject.nakamura.cluster.ClusterTrackingServiceImpl.java
/** * Activate the service, getting the id of the jvm instance and register the instance. * * @param ctx/*from ww w.ja va 2s. c om*/ * @throws Exception */ @SuppressWarnings("unchecked") protected void activate(ComponentContext ctx) throws Exception { Dictionary<String, Object> properties = ctx.getProperties(); thisSecureUrl = (String) properties.get(PROP_SECURE_HOST_URL); componentStartTime = String.valueOf(System.currentTimeMillis()); MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName("java.lang:type=Runtime"); serverId = ((String) mbeanServer.getAttribute(name, "Name")).replace("@", "-"); isActive = true; pingInstance(); isReady = true; }
From source file:org.jboss.seam.wiki.util.MonitoringEHCacheProvider.java
/** * Callback to perform any necessary initialization of the underlying cache implementation * during SessionFactory construction.// w ww . j av a2s .com * * @param properties current configuration settings. */ public void start(Properties properties) throws CacheException { if (manager != null) { log.warn("Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() " + " between repeated calls to buildSessionFactory. Using previously created EhCacheProvider." + " If this behaviour is required, consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider."); return; } try { String configurationResourceName = null; if (properties != null) { configurationResourceName = (String) properties.get(Environment.CACHE_PROVIDER_CONFIG); } if (StringHelper.isEmpty(configurationResourceName)) { manager = new CacheManager(); } else { URL url = loadResource(configurationResourceName); manager = new CacheManager(url); } // Register statistics MBean of EHCache on the current MBean server log.info("registering EHCache monitoring MBean"); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true); } catch (net.sf.ehcache.CacheException e) { //yukky! Don't you have subclasses for that! //TODO race conditions can happen here if (e.getMessage() .startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " + "CacheManager using the diskStorePath")) { throw new CacheException( "Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() " + " between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider.", e); } else { throw e; } } }
From source file:io.github.tfahub.dropwizard.logging.XmlBasedLoggingFactory.java
void registerJmxConfiguratorMBean() throws JMException { final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final ObjectName objectName = new ObjectName("io.dropwizard:type=Logging"); if (!server.isRegistered(objectName)) { server.registerMBean(new JMXConfigurator(loggerContext, server, objectName), objectName); }//from w w w . j a va 2 s . com }
From source file:com.tesora.dve.server.bootstrap.BootstrapHost.java
@Override protected void registerMBeans() { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try {//from w w w .ja v a2 s .c o m server.registerMBean(this, new ObjectName(MBEAN_BOOTSTRAP_HOST)); } catch (Exception e) { logger.error("Unable to register " + MBEAN_BOOTSTRAP_HOST + " mbean", e); } try { HierarchyDynamicMBean hdm = new HierarchyDynamicMBean(); server.registerMBean(hdm, new ObjectName(MBEAN_LOG4J_HIERARCHY)); // Add the root logger to the Hierarchy MBean hdm.addLoggerMBean(Logger.getRootLogger().getName()); LoggerRepository r = LogManager.getLoggerRepository(); @SuppressWarnings("rawtypes") Enumeration loggers = r.getCurrentLoggers(); while (loggers.hasMoreElements()) { hdm.addLoggerMBean(((Logger) loggers.nextElement()).getName()); } } catch (Exception e) { logger.error("Unable to register " + MBEAN_LOG4J_HIERARCHY + " mbean", e); } super.registerMBeans(); }