@Test(expected = Exception.class) public void testBadAttributeName() throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("JSDKTests:type=TestStub3"); TestStub testStub = new TestStub(1, 2.0, 3L); server.registerMBean(testStub, mxbeanName); List<JmxAttributeData> attributes = new ArrayList<JmxAttributeData>(); attributes.add(new JmxAttributeData("Int", "WrongNameIntSample")); attributes.add(new JmxAttributeData("Double", "WrongNameDoubleSample")); attributes.add(new JmxAttributeData("Long", "WrongNameLongSample")); JmxDataFetcher.fetch("JSDKTests:type=TestStub3", attributes); }
public static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes) throws Exception { Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null); if (objects.isEmpty()) { String errorMsg = String.format("Cannot find object name '%s'", objectName); throw new IllegalArgumentException(errorMsg); } for (JmxAttributeData attribute : attributes) { try { Collection<Object> resultForAttribute = fetch(server, objects, attribute.name); result.put(attribute.displayName, resultForAttribute); } catch (Exception e) { logger.warn("Failed to fetch JMX object '{}' with attribute '{}': ", objectName, attribute.name); throw e; } } return result; }
JmxDataFetcher { public static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes) throws Exception { Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null); if (objects.isEmpty()) { String errorMsg = String.format("Cannot find object name '%s'", objectName); throw new IllegalArgumentException(errorMsg); } for (JmxAttributeData attribute : attributes) { try { Collection<Object> resultForAttribute = fetch(server, objects, attribute.name); result.put(attribute.displayName, resultForAttribute); } catch (Exception e) { logger.warn("Failed to fetch JMX object '{}' with attribute '{}': ", objectName, attribute.name); throw e; } } return result; } }
JmxDataFetcher { public static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes) throws Exception { Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null); if (objects.isEmpty()) { String errorMsg = String.format("Cannot find object name '%s'", objectName); throw new IllegalArgumentException(errorMsg); } for (JmxAttributeData attribute : attributes) { try { Collection<Object> resultForAttribute = fetch(server, objects, attribute.name); result.put(attribute.displayName, resultForAttribute); } catch (Exception e) { logger.warn("Failed to fetch JMX object '{}' with attribute '{}': ", objectName, attribute.name); throw e; } } return result; } private  JmxDataFetcher(); }
JmxDataFetcher { public static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes) throws Exception { Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null); if (objects.isEmpty()) { String errorMsg = String.format("Cannot find object name '%s'", objectName); throw new IllegalArgumentException(errorMsg); } for (JmxAttributeData attribute : attributes) { try { Collection<Object> resultForAttribute = fetch(server, objects, attribute.name); result.put(attribute.displayName, resultForAttribute); } catch (Exception e) { logger.warn("Failed to fetch JMX object '{}' with attribute '{}': ", objectName, attribute.name); throw e; } } return result; } private  JmxDataFetcher(); static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes); }
JmxDataFetcher { public static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes) throws Exception { Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> objects = server.queryNames(new ObjectName(objectName), null); if (objects.isEmpty()) { String errorMsg = String.format("Cannot find object name '%s'", objectName); throw new IllegalArgumentException(errorMsg); } for (JmxAttributeData attribute : attributes) { try { Collection<Object> resultForAttribute = fetch(server, objects, attribute.name); result.put(attribute.displayName, resultForAttribute); } catch (Exception e) { logger.warn("Failed to fetch JMX object '{}' with attribute '{}': ", objectName, attribute.name); throw e; } } return result; } private  JmxDataFetcher(); static Map<String, Collection<Object>> fetch(String objectName, Collection<JmxAttributeData> attributes);  }