List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:net.tzolov.geode.jmx.JmxInfluxLoader.java
private String[] attributeNames(MBeanServerConnection connection, String objectName, MBeanAttributeInfoFilter attributeFilter) { try {/* w w w. j a v a 2 s.co m*/ ImmutableList.Builder<String> builder = ImmutableList.builder(); for (MBeanAttributeInfo attr : connection.getMBeanInfo(new ObjectName(objectName)).getAttributes()) { if (!attributeFilter.filter(attr)) { builder.add(attr.getName()); } } ImmutableList<String> names = builder.build(); return names.toArray(new String[names.size()]); } catch (Exception ex) { throw new RuntimeException((ex)); } }
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; }/* ww w. j av a2s. co 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.mustardgrain.solr.SolrClient.java
private void registerMBean() { String name = getClass().getPackage().getName() + ":type=" + getClass().getSimpleName() + "-" + objectNameIdCounter.incrementAndGet(); try {// w ww .j ava2 s. 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:io.github.albertopires.mjc.JConsoleM.java
public long getEdenUsage(ServerConfiguration serverConfiguration) throws Exception { ObjectName mbeanName = null;//from ww w. j a va 2 s .c o m if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK6)) { mbeanName = new ObjectName("java.lang:type=MemoryPool,name=Par Eden Space"); } else if (serverConfiguration.getJdkVersion().equals(JdkVersion.JDK8)) { mbeanName = new ObjectName("java.lang:type=MemoryPool,name=G1 Eden Space"); } CompositeDataSupport o; o = (CompositeDataSupport) mbsc.getAttribute(mbeanName, "Usage"); return ((Long) o.get("used")).longValue(); }
From source file:eu.itesla_project.online.tools.RunForecastErrorsAnalysisMpiTool.java
@Override public void run(CommandLine line) throws Exception { OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault(); String host = line.getOptionValue(OnlineWorkflowCommand.HOST); String port = line.getOptionValue(OnlineWorkflowCommand.PORT); String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS); if (host != null) startconfig.setJmxHost(host);/*from w w w. j av a 2 s . c o m*/ if (port != null) startconfig.setJmxPort(Integer.valueOf(port)); if (threads != null) startconfig.setThreads(Integer.valueOf(threads)); String analysisId = line.getOptionValue("analysis"); DateTime baseCaseDate = line.hasOption("base-case-date") ? DateTime.parse(line.getOptionValue("base-case-date")) : getDefaultParameters().getBaseCaseDate(); Interval histoInterval = line.hasOption("history-interval") ? Interval.parse(line.getOptionValue("history-interval")) : getDefaultParameters().getHistoInterval(); double ir = line.hasOption("ir") ? Double.parseDouble(line.getOptionValue("ir")) : getDefaultParameters().getIr(); int flagPQ = line.hasOption("flagPQ") ? Integer.parseInt(line.getOptionValue("flagPQ")) : getDefaultParameters().getFlagPQ(); int method = line.hasOption("method") ? Integer.parseInt(line.getOptionValue("method")) : getDefaultParameters().getMethod(); Integer nClusters = line.hasOption("nClusters") ? Integer.parseInt(line.getOptionValue("nClusters")) : getDefaultParameters().getnClusters(); double percentileHistorical = line.hasOption("percentileHistorical") ? Double.parseDouble(line.getOptionValue("percentileHistorical")) : getDefaultParameters().getPercentileHistorical(); Integer modalityGaussian = line.hasOption("modalityGaussian") ? Integer.parseInt(line.getOptionValue("modalityGaussian")) : getDefaultParameters().getModalityGaussian(); Integer outliers = line.hasOption("outliers") ? Integer.parseInt(line.getOptionValue("outliers")) : getDefaultParameters().getOutliers(); Integer conditionalSampling = line.hasOption("conditionalSampling") ? Integer.parseInt(line.getOptionValue("conditionalSampling")) : getDefaultParameters().getConditionalSampling(); Integer nSamples = line.hasOption("nSamples") ? Integer.parseInt(line.getOptionValue("nSamples")) : getDefaultParameters().getnSamples(); Set<Country> countries = line.hasOption("countries") ? Arrays.stream(line.getOptionValue("countries").split(",")).map(Country::valueOf).collect( Collectors.toSet()) : getDefaultParameters().getCountries(); CaseType caseType = line.hasOption("case-type") ? CaseType.valueOf(line.getOptionValue("case-type")) : getDefaultParameters().getCaseType(); ForecastErrorsAnalysisParameters parameters = new ForecastErrorsAnalysisParameters(baseCaseDate, histoInterval, analysisId, ir, flagPQ, method, nClusters, percentileHistorical, modalityGaussian, outliers, conditionalSampling, nSamples, countries, caseType); String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":" + startconfig.getJmxPort() + "/jmxrmi"; JMXServiceURL serviceURL = new JMXServiceURL(urlString); Map<String, String> jmxEnv = new HashMap<>(); JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv); MBeanServerConnection mbsc = connector.getMBeanServerConnection(); ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME); LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name, LocalOnlineApplicationMBean.class, false); String timeHorizonS = ""; if (line.hasOption("time-horizon")) { timeHorizonS = line.getOptionValue("time-horizon"); } application.runFeaAnalysis(startconfig, parameters, timeHorizonS); }
From source file:com.athena.dolly.console.module.jmx.JmxClientManager.java
public static HashMap<String, Object> getCacheManagerInfo(String nodeName) { try {/*from ww w . j ava 2 s . c o m*/ ObjectName cacheManagerObjectName = new ObjectName( "jboss.infinispan:type=CacheManager,name=\"clustered\",component=CacheManager"); HashMap<String, Object> cacheManagerMap = getObjectNameInfo(cacheManagerObjectName, nodeName); return cacheManagerMap; } catch (Exception e) { logger.error("unhandled exception has errored : ", e); } return null; }
From source file:VerboseGC.java
/** * Constructs a PrintGCStat object to monitor a remote JVM. *///from w ww . j a v a2 s . co m public PrintGCStat(MBeanServerConnection server) throws IOException { // Create the platform mxbean proxies this.rmbean = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); this.mmbean = newPlatformMXBeanProxy(server, MEMORY_MXBEAN_NAME, MemoryMXBean.class); ObjectName poolName = null; ObjectName gcName = null; try { poolName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"); gcName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"); } catch (MalformedObjectNameException e) { // should not reach here assert (false); } Set mbeans = server.queryNames(poolName, null); if (mbeans != null) { pools = new ArrayList<MemoryPoolMXBean>(); Iterator iterator = mbeans.iterator(); while (iterator.hasNext()) { ObjectName objName = (ObjectName) iterator.next(); MemoryPoolMXBean p = newPlatformMXBeanProxy(server, objName.getCanonicalName(), MemoryPoolMXBean.class); pools.add(p); } } mbeans = server.queryNames(gcName, null); if (mbeans != null) { gcmbeans = new ArrayList<GarbageCollectorMXBean>(); Iterator iterator = mbeans.iterator(); while (iterator.hasNext()) { ObjectName objName = (ObjectName) iterator.next(); GarbageCollectorMXBean gc = newPlatformMXBeanProxy(server, objName.getCanonicalName(), GarbageCollectorMXBean.class); gcmbeans.add(gc); } } }
From source file:org.jolokia.client.request.J4pReadIntegrationTest.java
@Test public void mbeanPattern() throws MalformedObjectNameException, J4pException { for (J4pReadRequest req : readRequests("*:type=attribute", "LongSeconds")) { J4pReadResponse resp = j4pClient.execute(req); assertEquals(1, resp.getObjectNames().size()); Map respVal = resp.getValue(); assertTrue(respVal.containsKey(itSetup.getAttributeMBean())); Map attrs = (Map) respVal.get(itSetup.getAttributeMBean()); assertEquals(1, attrs.size());//from ww w . j av a2 s.co m assertTrue(attrs.containsKey("LongSeconds")); Set<String> attrSet = new HashSet<String>( resp.getAttributes(new ObjectName(itSetup.getAttributeMBean()))); assertEquals(1, attrSet.size()); assertTrue(attrSet.contains("LongSeconds")); try { resp.getAttributes(new ObjectName("blub:type=bla")); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("blub:type=bla")); } try { resp.getAttributes(); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("*:type=attribute")); } try { resp.getValue("LongSeconds"); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("non-pattern")); } } }
From source file:net.sf.ehcache.management.ManagementService.java
/** * Stop the listener and free any resources. * Removes registered ObjectNames/*ww w . j av a 2 s .com*/ * * @throws net.sf.ehcache.CacheException - all exceptions are wrapped in CacheException */ public void dispose() throws CacheException { Set registeredObjectNames = null; try { //CacheManager MBean registeredObjectNames = mBeanServer.queryNames(CacheManager.createObjectName(backingCacheManager), null); //Other MBeans for this CacheManager registeredObjectNames.addAll(mBeanServer.queryNames( new ObjectName("net.sf.ehcache:*,CacheManager=" + backingCacheManager.toString()), null)); } catch (MalformedObjectNameException e) { //this should not happen LOG.error("Error querying MBeanServer. Error was " + e.getMessage(), e); } for (Iterator iterator = registeredObjectNames.iterator(); iterator.hasNext();) { ObjectName objectName = (ObjectName) iterator.next(); try { mBeanServer.unregisterMBean(objectName); } catch (Exception e) { LOG.error("Error unregistering object instance " + objectName + " . Error was " + e.getMessage(), e); } } status = Status.STATUS_SHUTDOWN; }
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/*from w ww. jav a 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"; }