List of usage examples for javax.management.openmbean CompositeDataSupport getCompositeType
public CompositeType getCompositeType()
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public List<KeyResponse> getJmxKeys(String name, String attributeName) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { List<KeyResponse> response = new ArrayList<KeyResponse>(); ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); if (objectNameList != null && objectNameList.size() > 0) { objectName = objectNameList.iterator().next(); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; CompositeType type = cds.getCompositeType(); Set<String> listKey = type.keySet(); for (Object key : listKey) { if (key instanceof String) { Object value = cds.get((String) key); KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(key.toString()); keyResponse.setValue(value.toString()); response.add(keyResponse); }//from w w w. ja v a 2s . c o m } } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setValue(attr.toString()); response.add(keyResponse); } } return response; }
From source file:fr.openfarm.jmx.service.JMXQuery.java
@Override public GetMultiObjectKeysResponse getWildcardJmxKeys(String name, String attributeName) throws MalformedObjectNameException, NullPointerException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, IOException { GetMultiObjectKeysResponse reponse = new GetMultiObjectKeysResponse(); ArrayList<MultiObjectKeys> multiObjectKeysList = new ArrayList<MultiObjectKeys>(); ObjectName objectName = new ObjectName(name); Set<ObjectName> objectNameList = connection.queryNames(objectName, null); for (ObjectName iterObject : objectNameList) { objectName = iterObject;/*from w w w .j av a 2s . co m*/ List<KeyResponse> keyList = new ArrayList<KeyResponse>(); Object attr = connection.getAttribute(objectName, attributeName); if (attr instanceof CompositeDataSupport) { CompositeDataSupport cds = (CompositeDataSupport) attr; CompositeType type = cds.getCompositeType(); Set<String> listKey = type.keySet(); for (Object key : listKey) { if (key instanceof String) { Object value = cds.get((String) key); KeyResponse keyResponse = new KeyResponse(); keyResponse.setKey(key.toString()); keyResponse.setValue(value.toString()); keyList.add(keyResponse); } } } else { KeyResponse keyResponse = new KeyResponse(); keyResponse.setValue(attr.toString()); keyList.add(keyResponse); } MultiObjectKeys multiObjectKeys = new MultiObjectKeys(); multiObjectKeys.setJmxKeys(keyList); multiObjectKeys.setObjectName(objectName.getCanonicalName()); multiObjectKeysList.add(multiObjectKeys); } reponse.setMultiObjectKeys(multiObjectKeysList); return reponse; }
From source file:it.jnrpe.plugin.jmx.CCheckJMX.java
@Override protected Collection<Metric> gatherMetrics(ICommandLine cl) throws MetricGatheringException { Collection<Metric> metrics = new ArrayList<Metric>(super.gatherMetrics(cl)); if (this.getInfoData() == null || this.getVerbatim() >= 2) { String metricName = getCheckName(); if (this.getCheckData() instanceof Number) { metrics.add(/*w w w . j a v a 2 s . co m*/ MetricBuilder.forMetric(metricName).withMessage(metricName + " is {0}", this.getCheckData()) .withValue((Number) this.getCheckData()).build()); } else { metrics.add(MetricBuilder.forMetric(metricName) .withMessage(metricName + " is {0}", this.getCheckData()).withValue(0).build()); } LOG.debug(getContext(), "Created metric : " + metricName); } if (this.getInfoData() != null) { String metricName = getInfo_attribute(); if (this.getInfoData() instanceof CompositeDataSupport) { CompositeDataSupport data = (CompositeDataSupport) this.getInfoData(); CompositeType type = data.getCompositeType(); for (Iterator<String> it = type.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); if (data.containsKey(key) && !getCheckName().equals(metricName + "." + key)) { if (data.get(key) instanceof Number) { metrics.add(MetricBuilder.forMetric(metricName + "." + key) .withMessage(metricName + "." + key + " is {0}", data.get(key)) .withValue((Number) data.get(key)).build()); } else { metrics.add(MetricBuilder.forMetric(metricName + "." + key) .withMessage(metricName + "." + key + " is {0}", data.get(key)).withValue(0) .build()); } LOG.debug(getContext(), "Created metric : " + metricName + "." + key); } } } else { if (this.getInfoData() instanceof Number) { metrics.add(MetricBuilder.forMetric(metricName) .withMessage("info is {0}", this.getCheckData().toString()) .withValue((Number) this.getInfoData()).build()); } else { metrics.add(MetricBuilder.forMetric(metricName) .withMessage("info is {0}", this.getCheckData().toString()).withValue(0).build()); } LOG.debug(getContext(), "Created metric : " + "info"); } } return metrics; }
From source file:org.cloudfoundry.identity.statsd.MBeanMap.java
private Object getCompositeWrapper(Object value, boolean prettifyKeys) { if (value instanceof CompositeDataSupport) { Map<Object, Object> map = new HashMap<Object, Object>(); CompositeDataSupport composite = (CompositeDataSupport) value; for (String key : composite.getCompositeType().keySet()) { safePut(map, key, composite.get(key)); }//from www .j a va 2 s .c om return map; } if (value instanceof LazyCompositeData) { Map<Object, Object> map = new HashMap<Object, Object>(); LazyCompositeData composite = (LazyCompositeData) value; for (String key : composite.getCompositeType().keySet()) { safePut(map, key, composite.get(key)); } return map; } if (value instanceof TabularDataSupport) { Map<Object, Object> map = new HashMap<Object, Object>(); TabularDataSupport composite = (TabularDataSupport) value; for (Entry<Object, Object> entry : composite.entrySet()) { Object wrapper = getCompositeWrapper(entry.getValue()); if (isKeyValuePair(wrapper)) { String key = getKey(wrapper); safePut(map, key, getValue(wrapper), prettifyKeys); } else { safePut(map, getCompositeWrapper(entry.getKey()), wrapper, prettifyKeys); } } return map; } if (value instanceof Collection) { Collection<?> composite = (Collection<?>) value; List<Object> list = new ArrayList<Object>(); for (Object element : composite) { list.add(getCompositeWrapper(element)); } return list; } if (value.getClass().isArray()) { List<Object> list = new ArrayList<Object>(); for (Object element : (Object[]) value) { list.add(getCompositeWrapper(element)); } return list; } return value; }
From source file:org.jwatch.util.JMXUtil.java
/** * Return the value already cast to a type. * <p/>/*from w ww . ja v a 2 s .c om*/ * - BIGDECIMAL = new SimpleType("java.math.BigDecimal"); * - BIGINTEGER = new SimpleType("java.math.BigInteger"); * - BOOLEAN = new SimpleType("java.lang.Boolean"); * - BYTE = new SimpleType("java.lang.Byte"); * - CHARACTER = new SimpleType("java.lang.Character"); * - DATE = new SimpleType("java.util.Date"); * - DOUBLE = new SimpleType("java.lang.Double"); * - FLOAT = new SimpleType("java.lang.Float"); * - INTEGER = new SimpleType("java.lang.Integer"); * - LONG = new SimpleType("java.lang.Long"); * - OBJECTNAME = new SimpleType("javax.management.ObjectName"); * - SHORT = new SimpleType("java.lang.Short"); * - STRING = new SimpleType("java.lang.String"); * - VOID = new SimpleType("java.lang.Void"); * + BIGDECIMAL = new SimpleType<BigDecimal>("java.math.BigDecimal"); * + BIGINTEGER = new SimpleType<BigInteger>("java.math.BigInteger"); * + BOOLEAN = new SimpleType<Boolean>("java.lang.Boolean"); * + BYTE = new SimpleType<Byte>("java.lang.Byte"); * + CHARACTER = new SimpleType<Character>("java.lang.Character"); * + DATE = new SimpleType<Date>("java.util.Date"); * + DOUBLE = new SimpleType<Double>("java.lang.Double"); * + FLOAT = new SimpleType<Float>("java.lang.Float"); * + INTEGER = new SimpleType<Integer>("java.lang.Integer"); * + LONG = new SimpleType<Long>("java.lang.Long"); * + OBJECTNAME = * + new SimpleType<ObjectName>("javax.management.ObjectName"); * + SHORT = new SimpleType<Short>("java.lang.Short"); * + STRING = new SimpleType<String>("java.lang.String"); * + VOID = new SimpleType<Void>("java.lang.Void"); */ public static Object convertToType(CompositeDataSupport compositeDataSupport, String key) { if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.lang.String")) { return StringUtils.trimToEmpty((String) compositeDataSupport.get(key)); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName() .equals("java.lang.Boolean")) { return compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.util.Date")) { return (Date) compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName() .equals("java.lang.Integer")) { return (Integer) compositeDataSupport.get(key); } else if (compositeDataSupport.getCompositeType().getType(key).getClassName().equals("java.lang.Long")) { return (Long) compositeDataSupport.get(key); } return new Object(); }