List of usage examples for javax.management.openmbean CompositeData getCompositeType
public CompositeType getCompositeType();
From source file:com.proofpoint.jmx.JmxHttpModule.java
private static Map<String, Object> toMap(CompositeData data) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); // never trust JMX to do the right thing Set<String> keySet = data.getCompositeType().keySet(); if (keySet != null) { for (String key : keySet) { if (key != null) { Object value = data.get(key); if (value != null) { builder.put(key, value); }/*from w ww . jav a 2s . com*/ } } } return builder.build(); }
From source file:org.apache.hadoop.hbase.util.JSONBean.java
private static void writeObject(final JsonGenerator jg, final boolean description, Object value) throws IOException { if (value == null) { jg.writeNull();//from www. j av a2s . c o m } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, description, item); } jg.writeEndArray(); } else if (value instanceof Number) { Number n = (Number) value; jg.writeNumber(n.toString()); } else if (value instanceof Boolean) { Boolean b = (Boolean) value; jg.writeBoolean(b); } else if (value instanceof CompositeData) { CompositeData cds = (CompositeData) value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for (String key : keys) { writeAttribute(jg, key, null, cds.get(key)); } jg.writeEndObject(); } else if (value instanceof TabularData) { TabularData tds = (TabularData) value; jg.writeStartArray(); for (Object entry : tds.values()) { writeObject(jg, description, entry); } jg.writeEndArray(); } else { jg.writeString(value.toString()); } } }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Dumps the details of a single CompositeData object. * //from w ww. j av a 2 s . c o m * @param composite * the composite object * @param out * PrintWriter to write the output to * @param nestLevel * the nesting level * @throws IOException * Signals that an I/O exception has occurred. */ @SuppressWarnings("unchecked") public static void printCompositeInfo(CompositeData composite, PrintWriter out, int nestLevel) throws IOException { Map<String, Object> attributes = new TreeMap<String, Object>(); for (String key : (Set<String>) composite.getCompositeType().keySet()) { Object value; try { value = composite.get(key); } catch (Exception e) { value = JmxDumpUtil.UNREADABLE_VALUE; } attributes.put(key, value); } tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, nestLevel); }
From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.metrics.MetricsReporter.java
protected static PropertySnapshot processAttrValue(PropertySnapshot snapshot, PropertyNameBuilder propName, Object value) {//from ww w .j a v a 2 s . c o m if (value instanceof CompositeData) { CompositeData cdata = (CompositeData) value; Set<String> keys = cdata.getCompositeType().keySet(); boolean isKVSet = keys.contains("key") && keys.contains("value"); // NON-NLS for (String key : keys) { Object cVal = cdata.get(key); if (isKVSet && "key".equals(key)) { // NON-NLS propName.append(Utils.toString(cVal)); } else if (isKVSet && "value".equals(key)) { // NON-NLS processAttrValue(snapshot, propName, cVal); } else { processAttrValue(snapshot, propName.append(key), cVal); } } propName.popLevel(); } else if (value instanceof TabularData) { TabularData tData = (TabularData) value; Collection<?> values = tData.values(); int row = 0; for (Object tVal : values) { processAttrValue(snapshot, tVal instanceof CompositeData ? propName : propName.append(padNumber(++row)), tVal); } propName.popLevel(); } else { snapshot.add(propName.propString(), value); } return snapshot; }
From source file:org.jolokia.converter.json.CompositeDataExtractor.java
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (String key : (Set<String>) pData.getCompositeType().keySet()) { Stack<String> path = (Stack<String>) pPath.clone(); try {/*w w w . j a va 2s. com*/ ret.put(key, pConverter.extractObject(pData.get(key), path, true)); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignore this key; } } if (ret.isEmpty()) { // If every key was filtered, this composite data should be skipped completely throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
From source file:org.hyperic.hq.product.jmx.MxLiveDataPlugin.java
private Map convertCompositeData(CompositeData data) { Map retval = new HashMap(); for (Iterator i = data.getCompositeType().keySet().iterator(); i.hasNext();) { String key = (String) i.next(); Object val = data.get(key); retval.put(key, val); }// w ww . java 2 s . c om return retval; }
From source file:org.springframework.integration.jmx.DefaultMBeanObjectConverter.java
/** * @param input//from www . j av a 2s .co m * @return recursively mapped object */ private Object checkAndConvert(Object input) { if (input == null) { return input; } else if (input.getClass().isArray()) { if (CompositeData.class.isAssignableFrom(input.getClass().getComponentType())) { List<Object> converted = new ArrayList<Object>(); int length = Array.getLength(input); for (int i = 0; i < length; i++) { Object value = checkAndConvert(Array.get(input, i)); converted.add(value); } return converted; } if (TabularData.class.isAssignableFrom(input.getClass().getComponentType())) { // TODO haven't hit this yet, but expect to log.warn("TabularData.isAssignableFrom(getComponentType) for " + input.toString()); } } else if (input instanceof CompositeData) { CompositeData data = (CompositeData) input; if (data.getCompositeType().isArray()) { // TODO? I haven't found an example where this gets thrown - but need to test it on Tomcat/Jetty or // something log.warn("(data.getCompositeType().isArray for " + input.toString()); } else { Map<String, Object> returnable = new HashMap<String, Object>(); Set<String> keys = data.getCompositeType().keySet(); for (String key : keys) { // we don't need to repeat name of this as an attribute if ("ObjectName".equals(key)) { continue; } Object value = checkAndConvert(data.get(key)); returnable.put(key, value); } return returnable; } } else if (input instanceof TabularData) { TabularData data = (TabularData) input; if (data.getTabularType().isArray()) { // TODO? I haven't found an example where this gets thrown, so might not be required log.warn("TabularData.isArray for " + input.toString()); } else { Map<Object, Object> returnable = new HashMap<Object, Object>(); @SuppressWarnings("unchecked") Set<List<?>> keySet = (Set<List<?>>) data.keySet(); for (List<?> keys : keySet) { CompositeData cd = data.get(keys.toArray()); Object value = checkAndConvert(cd); if (keys.size() == 1 && (value instanceof Map) && ((Map<?, ?>) value).size() == 2) { Object actualKey = keys.get(0); Map<?, ?> valueMap = (Map<?, ?>) value; if (valueMap.containsKey("key") && valueMap.containsKey("value") && actualKey.equals(valueMap.get("key"))) { returnable.put(valueMap.get("key"), valueMap.get("value")); } else { returnable.put(actualKey, value); } } else { returnable.put(keys, value); } } return returnable; } } return input; }
From source file:com.tribloom.module.JmxClient.java
private void addCompositeData(Map<String, Object> model, CompositeData data, String name) { CompositeType type = data.getCompositeType(); String typeName = type.getTypeName(); echo("\naddCompositeData with type " + typeName); if (typeName.contains("MemoryUsage")) { model.put(name + "Committed", data.get("committed")); model.put(name + "Init", data.get("init")); model.put(name + "Max", data.get("max")); model.put(name + "Used", data.get("used")); } else if (typeName.contains("GcInfo")) { model.put(name + "Duration", data.get("duration")); model.put(name + "EndTime", data.get("endTime")); model.put(name + "StartTime", data.get("startTime")); model.put(name + "Id", data.get("id")); // TabularData memUsageAfterGc = (TabularData) data.get("memoryUsageAfterGc"); // addTabularData(model, memUsageAfterGc, name + "MemoryUsageAfterGc"); // TabularData memoryUsageBeforeGc = (TabularData) data.get("memoryUsageBeforeGc"); // addTabularData(model, memoryUsageBeforeGc, name + "MemoryUsageBeforeGc"); }//w w w . j ava 2s .c om }
From source file:com.tomcat.monitor.jmx.obj.bean.MServer.java
/** * getValue form OpenMBean Value FIXME: SimpleType Umwandlung in skalare * Datentypen FIXME: Suche eine elegante Moeglichkeit an den Wert eines * Attributes in einem OpenMBean heranzukommen (BeanUtils...)? * <p/>// w ww .ja v a 2s . c o m * <p/> * Beispiele: attribute1 [key1] attribute1.attribute2 [key].attribute1 * [key1].[key2] [key1].attribute1.[key2].attribute2 * * @param attributePath * path to Mbean OpenMbean attribute * @param bean * current value */ public Object accessValue(String attributePath, Object bean) { if (attributePath == null || "".equals(attributePath)) return null; if (bean instanceof CompositeDataSupport) { CompositeDataSupport data = (CompositeDataSupport) bean; // FIXME This only supports direct key access return data.get(attributePath); } else if (bean instanceof TabularDataSupport) { TabularDataSupport data = (TabularDataSupport) bean; if (attributePath.startsWith("[")) { int endIndex = attributePath.indexOf("]"); if (endIndex > 1) { String attributeKey = attributePath.substring(1, endIndex); CompositeData valuedata = data.get(new Object[] { attributeKey }); Object value = valuedata.get("value"); OpenType<?> type = valuedata.getCompositeType().getType("value"); if (type instanceof SimpleType) { // FIXME Es fehlt noch die Prfung ob attributePath // nicht false ist, sprich das nach [].<xxxx> gefragt // wahr. return value; } else { String nextAttributePath = attributePath.substring(endIndex); if (nextAttributePath.startsWith(".")) { // FIXME stimmt das oder endIndex return accessValue(attributePath.substring(endIndex + 1), value); } } } } } return null; }
From source file:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java
private void writeObject(JsonGenerator jg, Object value) throws IOException { if (value == null) { jg.writeNull();/* w w w . j av a2 s .co m*/ } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if (value instanceof Number) { Number n = (Number) value; if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) { jg.writeString(n.toString()); } else { jg.writeNumber(n.toString()); } } else if (value instanceof Boolean) { Boolean b = (Boolean) value; jg.writeBoolean(b); } else if (value instanceof CompositeData) { CompositeData cds = (CompositeData) value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for (String key : keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if (value instanceof TabularData) { TabularData tds = (TabularData) value; jg.writeStartArray(); for (Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else if (value instanceof GaugeValue) { ((GaugeValue) value).serialize(jg); } else { jg.writeString(value.toString()); } } }