} 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)); TabularData tds = (TabularData)value; jg.writeStartArray(); for(Object entry : tds.values()) { writeObject(jg, description, entry);
lastCount = count; StringBuilder builder = new StringBuilder(); int id = ((Number) lastGC.get("id")).intValue(); long dur = (Long) lastGC.get("duration"); long startTs = (Long) lastGC.get("startTime"); CompositeData mbefore = (CompositeData) ((TabularData)beforeGC).get(poolKey).get("value"); CompositeData mafter = (CompositeData) ((TabularData)afterGC).get(poolKey).get("value"); long before = (Long) mbefore.get("used"); long after = (Long) mafter.get("used");
@Override public TabularData getConnectionList() throws JMException { CompositeType rowType = JdbcConnectionStat.Entry.getCompositeType(); String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]); TabularType tabularType = new TabularType("ConnectionListStatistic", "ConnectionListStatistic", rowType, indexNames); TabularData data = new TabularDataSupport(tabularType); for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : getConnections().entrySet()) { data.put(entry.getValue().getCompositeData()); } return data; }
/** * Add results from a value of type tabular data. * This is a recursive function. */ private void add(String attributeName, ImmutableList.Builder<String> valuePath, TabularData tds) { // @see TabularData#keySet JavaDoc: // "Set<List<?>>" but is declared as a {@code Set<?>} for // compatibility reasons. The returned set can be used to iterate // over the keys." Set<List<?>> keys = (Set<List<?>>) tds.keySet(); for (List<?> key : keys) { // ie: attributeName=LastGcInfo.Par Survivor Space // i haven't seen this be smaller or larger than List<1>, but // might as well loop it. CompositeData compositeData = tds.get(key.toArray()); String attributeName2 = Joiner.on('.').join(key); add(attributeName, newValuePath(valuePath, attributeName2), compositeData); } }
for(String f: td[0].getCompositeType().keySet()) { if (!header.contains(f)) { header.add(f); td.getTabularType().getIndexNames(); List<String> header = new ArrayList<String>(td.getTabularType().getIndexNames()); for(String f: td.getTabularType().getRowType().keySet()) { if (!header.contains(f)) { header.add(f); for(Object row: td.values()) { content.add(formatRow((CompositeData)row, header)); CompositeData cd = (CompositeData)v; List<String[]> content = new ArrayList<String[]>(); for(String field: cd.getCompositeType().keySet()) { String val = formatLine(cd.get(field), cd.getCompositeType().getType(field).getClassName()); content.add(new String[]{field + ": ", val});
TabularData td = (TabularData)v; StringBuilder sb = new StringBuilder(); for(Object c: td.values()) { sb.append(formatLine(c, td.getTabularType().getRowType().getClassName())); sb.append(","); StringBuilder sb = new StringBuilder(); for(Object c: td) { sb.append(formatLine(c, ((CompositeData)c).getCompositeType().getClassName())); sb.append(","); StringBuilder sb = new StringBuilder(); sb.append("{"); for(String attr: cdata.getCompositeType().keySet()) { sb.append(attr).append("="); sb.append(formatLine(cdata.get(attr), cdata.getCompositeType().getType(attr).getClassName())); sb.append(',');
@Override public TabularData getJobs() throws MBeanException { try { CompositeType jobType = new CompositeType("Job", "Scheduler job", new String[]{ "Job", "Schedule" }, new String[]{ "Job Name", "Job Scheduling" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING }); TabularType tableType = new TabularType("Jobs", "Tables of all jobs", jobType, new String[]{ "Job" }); TabularData table = new TabularDataSupport(tableType); Map<Object, ScheduleOptions> jobs = scheduler.getJobs(); for (Map.Entry<Object, ScheduleOptions> entry : jobs.entrySet()) { CompositeData data = new CompositeDataSupport(jobType, new String[]{ "Job", "Schedule" }, new Object[]{ entry.getValue().name(), entry.getValue().schedule()}); table.put(data); } return table; } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
public static void appendTabularMap(Map map, CompositeData cdata, String fieldName) { Object tabularObject = cdata.get(fieldName); if (tabularObject instanceof TabularData) { TabularData tabularData = (TabularData) tabularObject; Collection<CompositeData> values = (Collection<CompositeData>) tabularData.values(); for (CompositeData compositeData : values) { Object key = compositeData.get("key"); Object value = compositeData.get("value"); map.put(key, value); } } }
public TabularData getMissingPersistentMembersJMX() throws AdminException { try { Set<PersistentID> members = super.getMissingPersistentMembers(); TabularData results = new TabularDataSupport(PERSISTENT_ID_TABLE_TYPE); int index = 0; for (PersistentID id : members) { CompositeData idData = new CompositeDataSupport(PERSISTENT_ID_TYPE, PERSISTENT_ID_FIELDS, new Object[] {id.getHost().toString(), id.getDirectory(), id.getUUID().toString()}); results.put(idData); index++; } return results; } catch (OpenDataException e) { logger.warn("Exception occurred while getting missing persistent members.", e); throw new AdminException(e); } }
@ManagedOperation(description = "Information about Camel Reactive subscribers") public TabularData camelSubscribers() { try { final TabularData answer = new TabularDataSupport(subscribersTabularType()); subscribers.forEach((k, v) -> { try { String name = k; long inflight = v.getInflightCount(); long requested = v.getRequested(); CompositeType ct = subscribersCompositeType(); CompositeData data = new CompositeDataSupport(ct, new String[] {"name", "inflight", "requested"}, new Object[] {name, inflight, requested}); answer.put(data); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }); return answer; } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
for(String f: td[0].getCompositeType().keySet()) { if (!header.contains(f)) { header.add(f); CompositeData cd = (CompositeData) v; List<String> header = new ArrayList<String>(); for(String f: cd.getCompositeType().keySet()) { if (!header.contains(f)) { header.add(f); td.getTabularType().getIndexNames(); List<String> header = new ArrayList<String>(td.getTabularType().getIndexNames()); for(String f: td.getTabularType().getRowType().keySet()) { if (!header.contains(f)) { header.add(f); for(Object row: td.values()) { table.append(hdr, formatRow((CompositeData)row, header));
@Override Object toNonNullOpenValue(Object value) throws OpenDataException { final Map<Object, Object> valueMap = (Map<Object, Object>) value; if (valueMap instanceof SortedMap) { Comparator comparator = ((SortedMap) valueMap).comparator(); if (comparator != null) { final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator; IllegalArgumentException iae = new IllegalArgumentException(msg); OpenDataException ode = new OpenDataException(msg); ode.initCause(iae); throw ode; } } final TabularType tabularType = (TabularType) getOpenType(); final TabularData table = new TabularDataSupport(tabularType); final CompositeType rowType = tabularType.getRowType(); for (Map.Entry entry : valueMap.entrySet()) { final Object openKey = keyConverter.toOpenValue(entry.getKey()); final Object openValue = valueConverter.toOpenValue(entry.getValue()); final CompositeData row; row = new CompositeDataSupport(rowType, keyValueArray, new Object[] {openKey, openValue}); table.put(row); } return table; }
private void populateSubAttributeList(Object value) { TabularData data = (TabularData) value; for (Object rowKey : data.keySet()) { Collection keys = (Collection) rowKey; CompositeData compositeData = data.get(keys.toArray()); String pathKey = getMultiKey(keys); HashMap<String, HashMap<String, Object>> subAttributes = new HashMap<String, HashMap<String, Object>>(); for (String key : compositeData.getCompositeType().keySet()) { if (compositeData.get(key) instanceof CompositeData) { for (String subKey : ((CompositeData) compositeData.get(key)).getCompositeType().keySet()) { subAttributes.put(key + "." + subKey, new HashMap<String, Object>()); } } else { subAttributes.put(key, new HashMap<String, Object>()); } } subAttributeList.put(pathKey, subAttributes); } }
@Override public void execute(NodeProbe probe) { TabularData data = probe.getFailureDetectorPhilValues(); System.out.printf("%10s,%16s%n", "Endpoint", "Phi"); for (Object o : data.keySet()) { @SuppressWarnings({ "rawtypes", "unchecked" }) CompositeData datum = data.get(((List) o).toArray(new Object[((List) o).size()])); System.out.printf("%10s,%16.8f%n",datum.get("Endpoint"), datum.get("PHI")); } } }
private static MBeanDump.MBeanValue getTabularDataValue(TabularData tabularData) { Set<String> attributeNames = tabularData.getTabularType().getRowType().keySet(); for (Object key : tabularData.keySet()) { String keyString = Joiner.on(", ").join(keyList); @SuppressWarnings("argument.type.incompatible") CompositeData compositeData = tabularData.get(keyList.toArray()); innerEntries.add(MBeanDump.MBeanValueMapEntry.newBuilder() .setKey(attributeName) .setValue(getMBeanAttributeValue(compositeData.get(attributeName))) .build());
/** * fromTabularData */ public static EntityStats[] fromTabularData(final TabularData tabularData) { final List<EntityStats> countList = new ArrayList(tabularData.size()); for (final Iterator pos = tabularData.values().iterator(); pos.hasNext();) { countList.add(new EntityStats((CompositeData) pos.next())); } return countList.toArray(new EntityStats[countList.size()]); }
private Object convertToMaps(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); TabularType type = pTd.getTabularType(); List<String> indexNames = type.getIndexNames(); boolean found = false; for (CompositeData cd : (Collection<CompositeData>) pTd.values()) { Stack<String> path = (Stack<String>) pExtraArgs.clone(); try { JSONObject targetJSONObject = ret; // TODO: Check whether all keys can be represented as simple types. If not, well // we dont do any magic and return the tabular data as an array. for (int i = 0; i < indexNames.size() - 1; i++) { Object indexValue = pConverter.extractObject(cd.get(indexNames.get(i)), null, true); targetJSONObject = getNextMap(targetJSONObject, indexValue); } Object row = pConverter.extractObject(cd, path, true); String finalIndex = indexNames.get(indexNames.size() - 1); Object finalIndexValue = pConverter.extractObject(cd.get(finalIndex), null, true); targetJSONObject.put(finalIndexValue, row); found = true; } catch (ValueFaultHandler.AttributeFilteredException exp) { // Ignoring filtered attributes } } if (!pTd.isEmpty() && !found) { throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
public Header[] getHeaders() { TabularData headers = (TabularData) data.get(HEADERS); Header[] hdr = new Header[headers.size()]; int i = 0; for (CompositeData data : (Collection<CompositeData>) headers.values()) { String key = data.get(JmxConstants.KEY).toString(); String value = data.get(JmxConstants.VALUE).toString(); hdr[i++] = new HeaderImpl(key, value); } return hdr; }
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter) throws AttributeNotFoundException { JSONObject ret = new JSONObject(); for (Object rowObject : pTd.values()) { CompositeData row = (CompositeData) rowObject; Stack<String> path = (Stack<String>) pExtraArgs.clone(); Object keyObject = row.get("key"); if (keyObject != null) { try { Object value = pConverter.extractObject(row.get("value"), path, true); ret.put(keyObject.toString(), value); } catch (ValueFaultHandler.AttributeFilteredException exp) { // Skip to next object since attribute was filtered } } } if (!pTd.isEmpty() && ret.isEmpty()) { // Bubble up if not a single thingy has been found throw new ValueFaultHandler.AttributeFilteredException(); } return ret; }
cd != null && checkForMxBeanMap(td.getTabularType()) ? cd.get("value") : cd, pPathParts, pJsonify); } catch (AttributeNotFoundException exp) { return checkForMxBeanMap(td.getTabularType()) ? convertMxBeanMapToJson(td,pPathParts,pConverter) : convertTabularDataToJson(td, pPathParts, pConverter);