List of usage examples for javax.management MBeanServer getMBeanInfo
public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException;
From source file:com.googlecode.psiprobe.tools.JmxTools.java
public static boolean hasAttribute(MBeanServer server, ObjectName mbean, String attrName) throws Exception { MBeanInfo info = server.getMBeanInfo(mbean); MBeanAttributeInfo[] ai = info.getAttributes(); for (int i = 0; i < ai.length; i++) { if (ai[i].getName().equals(attrName)) { return true; }/*ww w. ja v a 2 s .c om*/ } return false; }
From source file:com.flexive.shared.mbeans.MBeanHelper.java
/** * Searches all available MBean servers for the given object name. * * @param name the object name/*from w w w . j a v a2 s. c o m*/ * @return the MBeanInfo of the first server that contains an entry of this name * @throws javax.management.InstanceNotFoundException if the given object was not found on any server * @throws javax.management.IntrospectionException thrown by server factory * @throws javax.management.ReflectionException thrown by server factory */ public static Pair<MBeanServer, MBeanInfo> getMBeanInfo(ObjectName name) throws ReflectionException, IntrospectionException, InstanceNotFoundException { InstanceNotFoundException notFoundException = null; for (MBeanServer server : findMBeanServers()) { try { return new Pair<MBeanServer, MBeanInfo>(server, server.getMBeanInfo(name)); } catch (InstanceNotFoundException e) { notFoundException = e; } } throw notFoundException; }
From source file:Utilities.java
private static MBeanInfo getMBeanInfoSafely(VarOutputSink sink, MBeanServer mbs, ObjectName objectName) { MBeanInfo info = null;//w ww . jav a2 s . co m try { info = mbs.getMBeanInfo(objectName); } catch (InstanceNotFoundException e) { sink.printVariable("ObjectName", "Not found"); } catch (IntrospectionException e) { sink.printVariable("ObjectName", "IntrospectionException"); } catch (ReflectionException e) { sink.printVariable("ObjectName", "ReflectionException"); } return info; }
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
public static void RegisterJmxBean(Object bean, String beanName, String jmxAppName) { try {/* w w w .ja v a 2 s .c o m*/ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); if (!StringUtils.isBlank(jmxAppName)) beanName += ",app=" + jmxAppName; ObjectName name = new ObjectName(beanName); // Make sure the bean doesn't already exist. If it does, unregister it. try { mbs.getMBeanInfo(name); // Throws InstanceNotFoundException if not found. mbs.unregisterMBean(name); // Unregister a bean if it exists. } catch (InstanceNotFoundException e) { // If we get here then the mbean isn't currently registered. This is valid // so we'll ignore it. } mbs.registerMBean(bean, name); } catch (Exception e) { throw ZeidonException.wrapException(e).appendMessage("Bean Name = %s, app=%s", beanName, jmxAppName) .appendMessage("Bean class = %s", bean.getClass().getName()); } }
From source file:com.mtgi.analytics.aop.config.v11.PersisterChainConfigurationTest.java
@Test public void testXmlPersisterConfiguration() throws Exception { assertNotNull("custom tracking manager configured", multiTracking); assertEquals("application name set", "testApp", multiTracking.getApplication()); assertEquals("correct persister type provided", ChainingEventPersisterImpl.class, multiTracking.getPersister().getClass()); ChainingEventPersisterImpl persister = (ChainingEventPersisterImpl) multiTracking.getPersister(); BehaviorEventPersister[] delegates = persister.getDelegates().toArray(new BehaviorEventPersister[0]); assertEquals("all delegates registered", 3, delegates.length); assertEquals("first delegate has correct type", XmlBehaviorEventPersisterImpl.class, delegates[0].getClass());//w ww . ja v a 2 s .co m assertEquals("second delegate has correct type", StatisticsMBeanEventPersisterImpl.class, delegates[1].getClass()); assertSame("third delegate is reference to top-level bean", customPersister, delegates[2]); //verify that MBeans have been registered MBeanServer server = JmxUtils.locateMBeanServer(); assertNotNull("manager mbean found", server.getMBeanInfo( new ObjectName("testApp:package=com.mtgi.analytics,group=multiTracking,name=BeetManager"))); }
From source file:com.mtgi.analytics.aop.config.v11.XmlPersisterConfigurationTest.java
@Test public void testXmlPersisterConfiguration() throws Exception { assertNotNull("custom tracking manager configured", xmlTracking); assertEquals("application name set", "testApp", xmlTracking.getApplication()); assertEquals("correct persister type provided", XmlBehaviorEventPersisterImpl.class, xmlTracking.getPersister().getClass()); XmlBehaviorEventPersisterImpl persister = (XmlBehaviorEventPersisterImpl) xmlTracking.getPersister(); assertFalse("default setting overridden", persister.isBinary()); assertFalse("default setting overridden", persister.isCompress()); File location = new File(persister.getFile()); assertTrue("custom file name [" + persister.getFile() + "]", location.getName().startsWith("xml-tracking")); assertEquals("custom XML attributes can be post-processed by property resolver", new File(System.getProperty("java.io.tmpdir")).getCanonicalPath(), location.getParentFile().getCanonicalPath()); TaskExecutor executor = xmlTracking.getExecutor(); assertSame("application executor is used", testExecutor, executor); List<String> triggers = Arrays.asList(testScheduler.getTriggerNames("beet")); assertEquals("flush and rotate jobs scheduled in application scheduler", 2, triggers.size()); assertTrue("flush job scheduled", triggers.contains("xmlTracking_flush_trigger")); assertTrue("rotate job scheduled", triggers.contains("org.springframework.scheduling.quartz.CronTriggerBean_rotate_trigger")); SchedulerFactory factory = new StdSchedulerFactory(); assertEquals("private scheduler was not created", 1, factory.getAllSchedulers().size()); assertSame(testScheduler, factory.getAllSchedulers().iterator().next()); //verify that MBeans have been registered MBeanServer server = JmxUtils.locateMBeanServer(); assertNotNull("manager mbean found", server.getMBeanInfo( new ObjectName("testApp:package=com.mtgi.analytics,group=xmlTracking,name=BeetManager"))); ObjectName logName = new ObjectName("testApp:package=com.mtgi.analytics,group=xmlTracking,name=BeetLog"); assertNotNull("log mbean found", server.getMBeanInfo(logName)); assertEquals(persister.getFileSize(), server.getAttribute(logName, "FileSize")); }
From source file:info.archinnov.achilles.embedded.ServerStarter.java
private boolean isAlreadyRunning() { log.trace("Check whether an embedded Cassandra is already running"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try {// w w w . j a v a2 s .c o m MBeanInfo mBeanInfo = mbs.getMBeanInfo(new ObjectName("org.apache.cassandra.db:type=StorageService")); if (mBeanInfo != null) { return true; } return false; } catch (InstanceNotFoundException e) { return false; } catch (IntrospectionException e) { throw new IllegalStateException("Cannot check if cassandra is already running", e); } catch (MalformedObjectNameException e) { throw new IllegalStateException("Cannot check if cassandra is already running", e); } catch (ReflectionException e) { throw new IllegalStateException("Cannot check if cassandra is already running", e); } }
From source file:org.apache.streams.jackson.MemoryUsageDeserializer.java
@Override public MemoryUsageBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {//from w w w . java 2 s. c om MBeanServer server = ManagementFactory.getPlatformMBeanServer(); MemoryUsageBroadcast memoryUsageBroadcast = new MemoryUsageBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); memoryUsageBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { switch (attribute.getName()) { case "Verbose": memoryUsageBroadcast.setVerbose((boolean) server.getAttribute(name, attribute.getName())); break; case "ObjectPendingFinalizationCount": memoryUsageBroadcast.setObjectPendingFinalizationCount( Long.parseLong(server.getAttribute(name, attribute.getName()).toString())); break; case "HeapMemoryUsage": memoryUsageBroadcast.setHeapMemoryUsage( (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName())) .get("used")); break; case "NonHeapMemoryUsage": memoryUsageBroadcast.setNonHeapMemoryUsage( (Long) ((CompositeDataSupport) server.getAttribute(name, attribute.getName())) .get("used")); break; } } return memoryUsageBroadcast; } catch (Exception e) { LOGGER.error("Exception trying to deserialize MemoryUsageDeserializer object: {}", e); return null; } }
From source file:org.apache.streams.jackson.DatumStatusCounterDeserializer.java
@Override public DatumStatusCounterBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {/* w w w. j av a 2 s. c o m*/ MBeanServer server = ManagementFactory.getPlatformMBeanServer(); DatumStatusCounterBroadcast datumStatusCounterBroadcast = new DatumStatusCounterBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); datumStatusCounterBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "Failed": datumStatusCounterBroadcast .setFailed((boolean) server.getAttribute(name, attribute.getName())); break; case "Passed": datumStatusCounterBroadcast .setPassed((boolean) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e); } } return datumStatusCounterBroadcast; } catch (Exception e) { LOGGER.error("Exception trying to deserialize DatumStatusCounterBroadcast object: {}", e); return null; } }
From source file:org.apache.streams.jackson.ThroughputQueueDeserializer.java
@Override public ThroughputQueueBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {//ww w . j av a 2 s . c o m MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ThroughputQueueBroadcast throughputQueueBroadcast = new ThroughputQueueBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); throughputQueueBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "CurrentSize": throughputQueueBroadcast .setCurrentSize((long) server.getAttribute(name, attribute.getName())); break; case "AvgWait": throughputQueueBroadcast .setAvgWait((double) server.getAttribute(name, attribute.getName())); break; case "MaxWait": throughputQueueBroadcast.setMaxWait((long) server.getAttribute(name, attribute.getName())); break; case "Removed": throughputQueueBroadcast.setRemoved((long) server.getAttribute(name, attribute.getName())); break; case "Added": throughputQueueBroadcast.setAdded((long) server.getAttribute(name, attribute.getName())); break; case "Throughput": throughputQueueBroadcast .setThroughput((double) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception while trying to deserialize ThroughputQueueBroadcast object: {}", e); } } return throughputQueueBroadcast; } catch (Exception e) { return null; } }