List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.rhq.plugins.platform.PlatformComponent.java
public OperationResult invokeOperation(String name, Configuration parameters) throws Exception { if ("discovery".equals(name)) { Boolean detailed = parameters.getSimple("detailedDiscovery").getBooleanValue(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String results = (String) mbs.invoke(new ObjectName("rhq.pc:type=PluginContainer"), "executeDiscovery", new Object[] { detailed }, new String[] { Boolean.class.getName() }); return new OperationResult(results); } else if ("viewProcessList".equals(name)) { OperationResult result = new OperationResult(); List<ProcessInfo> processes = this.resourceContext.getSystemInformation().getAllProcesses(); PropertyList processList = new PropertyList("processList"); for (ProcessInfo process : processes) { PropertyMap pm = new PropertyMap("process"); pm.put(new PropertySimple("pid", process.getPid())); pm.put(new PropertySimple("name", process.getBaseName())); pm.put(new PropertySimple("size", (process.getMemory() != null) ? process.getMemory().getSize() : "0")); pm.put(new PropertySimple("userTime", (process.getTime() != null) ? process.getTime().getUser() : "0")); pm.put(new PropertySimple("kernelTime", (process.getTime() != null) ? process.getTime().getSys() : "0")); processList.add(pm);/*from w w w . j a va2s . com*/ } result.getComplexResults().put(processList); return result; } throw new UnsupportedOperationException( "Operation [" + name + "] not supported on " + resourceContext.getResourceType() + "."); }
From source file:org.opennms.netmgt.vmmgr.Starter.java
private void start() { LOG.debug("Beginning startup"); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Invoker invoker = new Invoker(); invoker.setServer(server);/*from ww w . j av a2 s . com*/ invoker.setAtType(InvokeAtType.START); List<InvokerService> services = InvokerService.createServiceList(new ServiceConfigFactory().getServices()); invoker.setServices(services); invoker.instantiateClasses(); List<InvokerResult> resultInfo = invoker.invokeMethods(); for (InvokerResult result : resultInfo) { if (result != null && result.getThrowable() != null) { Service service = result.getService(); String name = service.getName(); String className = service.getClassName(); String message = "An error occurred while attempting to start the \"" + name + "\" service (class " + className + "). " + "Shutting down and exiting."; LOG.error(message, result.getThrowable()); System.err.println(message); result.getThrowable().printStackTrace(); Manager manager = new Manager(); manager.stop(); manager.doSystemExit(); // Shouldn't get here return; } } LOG.debug("Startup complete"); }
From source file:org.wso2.carbon.business.messaging.core.internal.BrokerServiceComponent.java
/** * Check if the broker is up and running * * @return true if the broker is running or false otherwise *//*from ww w .ja v a2 s . c o m*/ private boolean isBrokerRunning() { boolean response = false; try { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(BrokerConstants.VIRTUAL_HOST_MBEAN), null); if (set.size() > 0) { // Virtual hosts created, hence broker running. response = true; } } catch (MalformedObjectNameException e) { //We do not propagate the exception further since the framework would re attempt to activate the bundle String error = "Error checking if broker is running."; log.error(error, e); } return response; }
From source file:com.liferay.portal.dao.jdbc.DataSourceFactoryImpl.java
protected DataSource initDataSourceTomcat(Properties properties) throws Exception { PoolProperties poolProperties = new PoolProperties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); // Ignore Liferay properties if (isPropertyLiferay(key)) { continue; }//w ww .j a v a 2 s . c o m // Ignore C3P0 properties if (isPropertyC3PO(key)) { continue; } // Ignore Primrose properties if (isPropertyPrimrose(key)) { continue; } try { BeanUtil.setProperty(poolProperties, key, value); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Property " + key + " is not a valid Tomcat JDBC " + "Connection Pool property"); } } } String poolName = PwdGenerator.getPassword(PwdGenerator.KEY2, 8); poolProperties.setName(poolName); org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource( poolProperties); if (poolProperties.isJmxEnabled()) { org.apache.tomcat.jdbc.pool.ConnectionPool jdbcConnectionPool = dataSource.createPool(); ConnectionPool jmxConnectionPool = jdbcConnectionPool.getJmxPool(); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(_TOMCAT_JDBC_POOL_OBJECT_NAME_PREFIX + poolName); mBeanServer.registerMBean(jmxConnectionPool, objectName); } return dataSource; }
From source file:com.qwazr.server.GenericServer.java
@Override public synchronized void close() { LOGGER.info("The server is stopping..."); executeListener(shutdownListeners, LOGGER); if (udpServer != null) { try {/*from ww w . j a v a 2 s . c o m*/ udpServer.shutdown(); } catch (InterruptedException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } for (final DeploymentManager manager : deploymentManagers) { try { if (manager.getState() == DeploymentManager.State.STARTED) manager.stop(); if (manager.getState() == DeploymentManager.State.DEPLOYED) manager.undeploy(); } catch (Exception e) { LOGGER.log(Level.WARNING, e, () -> "Cannot stop the manager: " + e.getMessage()); } } for (final Undertow undertow : undertows) { try { undertow.stop(); } catch (Exception e) { LOGGER.log(Level.WARNING, e, () -> "Cannot stop Undertow: " + e.getMessage()); } } if (!executorService.isTerminated()) { if (!executorService.isShutdown()) executorService.shutdown(); try { executorService.awaitTermination(2, TimeUnit.MINUTES); } catch (InterruptedException e) { LOGGER.log(Level.WARNING, e, () -> "Executor shutdown failed: " + e.getMessage()); } } // Unregister MBeans if (registeredObjectNames != null && !registeredObjectNames.isEmpty()) { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); for (ObjectName objectName : registeredObjectNames) { try { mbs.unregisterMBean(objectName); } catch (InstanceNotFoundException | MBeanRegistrationException e) { LOGGER.log(Level.WARNING, e, e::getMessage); } } registeredObjectNames.clear(); } LOGGER.info("The server is stopped."); }
From source file:com.mustardgrain.solr.SolrClient.java
private void registerMBean() { String name = getClass().getPackage().getName() + ":type=" + getClass().getSimpleName() + "-" + objectNameIdCounter.incrementAndGet(); try {//from ww w.jav a 2s . c o m objectName = new ObjectName(name); name = objectName.toString(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(this, new ObjectName(name)); if (LOG.isInfoEnabled()) LOG.info("Registered " + objectName); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Couldn't add MBean " + name); } }
From source file:com.enioka.jqm.tools.JndiContext.java
void resetSingletons() { jqmlogger.info("Resetting singleton JNDI resource cache"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); for (ObjectName n : this.jmxNames) { try {// ww w . j a v a 2 s .com mbs.unregisterMBean(n); } catch (Exception e) { jqmlogger.error("could not unregister bean", e); } } this.jmxNames = new ArrayList<ObjectName>(); this.singletons = new HashMap<String, Object>(); }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java
/** * This command try to get Port which the service is listening to. The port should be in the parameter -httpPort when running, or Tomcat port * * @return//w w w . java 2 s . c o m */ public static String getPort() { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))); for (ObjectName obj : objs) { String port = obj.getKeyProperty("port"); return port; } } catch (MalformedObjectNameException e) { EngineLogger.logger .error("Cannot get listening port of salsa-engine service. return 8080 as default. Error: " + e.toString()); } EngineLogger.logger.error("Cannot find listening port of salsa-engine service. return 8080 as default"); return "8080"; }
From source file:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java
private void writeJmx(BundleWriter writer) throws IOException { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); try (JsonGenerator generator = writer.createGenerator("runtime/jmx.json")) { generator.useDefaultPrettyPrinter(); generator.writeStartObject();/*from w w w . j av a 2s . c om*/ generator.writeArrayFieldStart("beans"); for (ObjectName objectName : mBeanServer.queryNames(null, null)) { MBeanInfo info; try { info = mBeanServer.getMBeanInfo(objectName); } catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) { LOG.warn("Exception accessing MBeanInfo ", ex); continue; } generator.writeStartObject(); generator.writeStringField("name", objectName.toString()); generator.writeObjectFieldStart("attributes"); for (MBeanAttributeInfo attr : info.getAttributes()) { try { writeAttribute(generator, attr.getName(), mBeanServer.getAttribute(objectName, attr.getName())); } catch (MBeanException | AttributeNotFoundException | InstanceNotFoundException | ReflectionException | RuntimeMBeanException ex) { generator.writeStringField(attr.getName(), "Exception: " + ex.toString()); } } generator.writeEndObject(); generator.writeEndObject(); writer.writeLn(""); } generator.writeEndArray(); generator.writeEndObject(); } finally { writer.markEndOfFile(); } }
From source file:com.mustardgrain.solr.SolrClient.java
private void unregisterMBean() { if (objectName == null) return;/* www. jav a2s .co m*/ try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.unregisterMBean(objectName); if (LOG.isInfoEnabled()) LOG.info("Unregistered " + objectName); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Couldn't remove MBean " + objectName.toString()); } }