List of usage examples for javax.management MBeanAttributeInfo getName
public String getName()
From source file:org.apache.streams.jackson.DatumStatusCounterDeserializer.java
@Override public DatumStatusCounterBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {/*from w w w.ja v a2 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:com.clustercontrol.HinemosManagerCli.java
private void printMBeanInfo(MBeanInfo mbeanInfo) { MBeanAttributeInfo[] attributeInfos = mbeanInfo.getAttributes(); System.out.println("Attributes:"); for (MBeanAttributeInfo attributeInfo : attributeInfos) { System.out.println(String.format("\t%s: %s", attributeInfo.getName(), attributeInfo.getType())); }//from w ww. j a v a 2 s. com MBeanOperationInfo[] operationInfos = mbeanInfo.getOperations(); System.out.println("Operations:"); for (MBeanOperationInfo operationInfo : operationInfos) { MBeanParameterInfo[] paramInfos = operationInfo.getSignature(); StringBuffer paramStr = new StringBuffer(); for (MBeanParameterInfo paramInfo : paramInfos) { paramStr.append(paramInfo.getType() + ","); } if (paramStr.length() != 0) { paramStr.append(paramStr.substring(0, paramStr.length() - 1)); } System.out.println( String.format("\t%s %s(%s)", operationInfo.getReturnType(), operationInfo.getName(), paramStr)); } }
From source file:org.apache.streams.jackson.ThroughputQueueDeserializer.java
@Override public ThroughputQueueBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {/* w w 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; } }
From source file:org.apache.streams.jackson.StreamsTaskCounterDeserializer.java
@Override public StreamsTaskCounterBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { try {// w ww .j a v a 2s. com MBeanServer server = ManagementFactory.getPlatformMBeanServer(); StreamsTaskCounterBroadcast streamsTaskCounterBroadcast = new StreamsTaskCounterBroadcast(); JsonNode attributes = jsonParser.getCodec().readTree(jsonParser); ObjectName name = new ObjectName(attributes.get("canonicalName").asText()); MBeanInfo info = server.getMBeanInfo(name); streamsTaskCounterBroadcast.setName(name.toString()); for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) { try { switch (attribute.getName()) { case "ErrorRate": streamsTaskCounterBroadcast .setErrorRate((double) server.getAttribute(name, attribute.getName())); break; case "NumEmitted": streamsTaskCounterBroadcast .setNumEmitted((long) server.getAttribute(name, attribute.getName())); break; case "NumReceived": streamsTaskCounterBroadcast .setNumReceived((long) server.getAttribute(name, attribute.getName())); break; case "NumUnhandledErrors": streamsTaskCounterBroadcast .setNumUnhandledErrors((long) server.getAttribute(name, attribute.getName())); break; case "AvgTime": streamsTaskCounterBroadcast .setAvgTime((double) server.getAttribute(name, attribute.getName())); break; case "MaxTime": streamsTaskCounterBroadcast .setMaxTime((long) server.getAttribute(name, attribute.getName())); break; } } catch (Exception e) { LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e); } } return streamsTaskCounterBroadcast; } catch (Exception e) { LOGGER.error("Exception while trying to deserialize StreamsTaskCounterBroadcast object: {}", e); return null; } }
From source file:org.cloudfoundry.identity.varz.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }/*from ww w . j a va 2 s . c om*/ } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = VarzStringUtils.camelToUnderscore(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.cloudfoundry.identity.statsd.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }// w w w. j a v a 2 s.co m } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = StringUtils.camelToUnderscore(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.cloudfoundry.identity.uaa.varz.MBeanMap.java
@Override public Set<java.util.Map.Entry<String, Object>> entrySet() { if (!initialized && info != null) { MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attribute : attributes) { String key = attribute.getName(); try { Object value = server.getAttribute(name, key); verySafePut(map, key, value); } catch (Exception e) { logger.trace("Cannot extract attribute: " + key); }/*from w w w .j av a2s . com*/ } MBeanOperationInfo[] operations = info.getOperations(); for (MBeanOperationInfo operation : operations) { String key = operation.getName(); if (key.startsWith("get") && operation.getSignature().length == 0) { String attribute = MBeanMap.prettify(key.substring(3)); if (map.containsKey(attribute)) { continue; } try { Object value = server.invoke(name, key, null, null); verySafePut(map, attribute, value); } catch (Exception e) { logger.trace("Cannot extract operation: " + key); } } } } return map.entrySet(); }
From source file:org.hyperic.hq.product.jmx.MxLiveDataPlugin.java
private Object queryMBeans(String pattern, Properties props) throws PluginException { MBeanServerConnection mServer; try {// w w w. j a v a 2s . c o m mServer = MxUtil.getMBeanServer(props); } catch (Exception e) { throw new PluginException("getMBeanServer(" + props.getProperty(MxUtil.PROP_JMX_URL) + "): " + e, e); } ObjectName query; try { query = new ObjectName(pattern); } catch (Exception e) { throw new PluginException("Invalid query '" + pattern + "': " + e); } Map res = new HashMap(); try { Iterator beans = mServer.queryNames(query, null).iterator(); while (beans.hasNext()) { ObjectName obj = (ObjectName) beans.next(); Map bean = new HashMap(); Map attrs = new LinkedHashMap(); bean.put(PROP_ATTRIBUTE + "s", attrs); res.put(obj.toString(), bean); MBeanInfo info = mServer.getMBeanInfo(obj); MBeanAttributeInfo[] attrInfo = info.getAttributes(); for (int i = 0; i < attrInfo.length; i++) { MBeanAttributeInfo mia = attrInfo[i]; String name = mia.getName(); Map attr = new HashMap(); Object val; try { val = mServer.getAttribute(obj, name); } catch (Exception e) { continue; //XXX } if (val == null) { val = "-"; } attr.put("Value", val); attr.put("Description", mia.getDescription()); attr.put("isWritable", new Boolean(mia.isWritable())); attrs.put(name, attr); } bean.put(PROP_METHOD + "s", info.getOperations()); } } catch (Exception e) { throw new PluginException("Error in query '" + pattern + "': " + e, e); } return res; }
From source file:org.midonet.midolman.tools.MmStat.java
public void dumpMBeans(String jmxDomain, String filter, int count, int interval) { ObjectName on = null;// w ww . j av a 2 s. c o m try { on = new ObjectName(jmxDomain + ":*"); } catch (MalformedObjectNameException e) { System.err.println("Aborted: malformed domain " + jmxDomain); e.printStackTrace(); System.exit(1); } java.util.Set<ObjectInstance> beans = null; try { beans = mbsc.queryMBeans(on, null); } catch (IOException e) { System.err.println("Aborted: querying Mbeans failed " + e); e.printStackTrace(); } // Remember MBean instances to dump List<ObjectInstance> objectInstances = new ArrayList<>(); for (ObjectInstance oi : beans) { if (filter != null) { String objectName = oi.getObjectName().toString(); if (!objectName.contains(filter)) { continue; } } objectInstances.add(oi); } int attempt = 1; while (true) { // Header System.out.println("============================"); System.out.println(String.format("Reading at %s (%s/%s)", new Date().toString(), attempt, count)); System.out.println("============================"); try { for (ObjectInstance oi : objectInstances) { on = oi.getObjectName(); System.out.println("MBean: " + on.toString()); MBeanInfo info = mbsc.getMBeanInfo(on); for (MBeanAttributeInfo attr : info.getAttributes()) { System.out.print("\t" + attr.getName() + ": "); System.out.println(mbsc.getAttribute(on, attr.getName())); } } if (attempt == count) System.exit(0); attempt++; //* Sleep "interval" seconds" */ Thread.sleep(interval * 1000); } catch (IOException e) { System.err.println("Aborted: got IOException: " + e); e.printStackTrace(); System.exit(1); } catch (JMException e) { System.err.println("Aborted: got JMException: " + e); e.printStackTrace(); System.exit(1); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:org.jminix.console.resource.AttributeResource.java
@Override protected Map<String, Object> getModel() { String domain = getRequest().getAttributes().get("domain").toString(); String mbean = new EncoderBean().decode(getRequest().getAttributes().get("mbean").toString()); String attribute = new EncoderBean().decode(getRequest().getAttributes().get("attribute").toString()); Map<String, Object> model = new HashMap<String, Object>(); try {/* w ww .j a v a 2s . com*/ MBeanServerConnection server = getServer(); MBeanAttributeInfo info = null; for (MBeanAttributeInfo i : server.getMBeanInfo(new ObjectName(domain + ":" + mbean)).getAttributes()) { if (i.getName().equals(attribute)) { info = i; } } Object value = server.getAttribute(new ObjectName(domain + ":" + mbean), attribute); model.put("attribute", info); if (value == null) { model.put("value", "<null>"); } else if (value.getClass().isArray()) { templateName = "array-attribute"; model.put("items", value); } else if (value instanceof CompositeData) { templateName = "composite-attribute"; model.put("attribute", value); } else if (value instanceof TabularData) { templateName = "tabular-attribute"; model.put("attribute", value); } else { model.put("value", value); } return model; } catch (IOException e) { throw new RuntimeException(e); } catch (AttributeNotFoundException e) { throw new RuntimeException(e); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } catch (MBeanException e) { Exception targetException = e.getTargetException(); if (targetException instanceof RuntimeErrorException) { throw new RuntimeException(targetException.getCause()); } log.warn("Error accessing attribute", e); model.put("value", e.getTargetException().getCause().getMessage()); return model; } catch (ReflectionException e) { throw new RuntimeException(e); } catch (IntrospectionException e) { throw new RuntimeException(e); } catch (RuntimeException e) { model.put("value", e.getMessage()); log.warn("Error accessing attribute", e); return model; } }