@Override public TabularData health() throws Exception { OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(HealthStatus.class); CompositeType ct = factory.getCompositeType(); TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[] { "healthId", "level", "message", "resource" }); TabularDataSupport rc = new TabularDataSupport(tt); List<HealthStatus> list = healthList(); for (HealthStatus healthStatus : list) { rc.put(new CompositeDataSupport(ct, factory.getFields(healthStatus))); } return rc; }
protected TabularDataSupport createTabularData(ActiveMQMessage m, TabularType type, Class valueType) throws IOException, OpenDataException { TabularDataSupport answer = new TabularDataSupport(type); Set<Map.Entry<String,Object>> entries = m.getProperties().entrySet(); for (Map.Entry<String, Object> entry : entries) { Object value = entry.getValue(); if (value instanceof UTF8Buffer && valueType.equals(String.class)) { String actual = value.toString(); CompositeDataSupport compositeData = createTabularRowValue(type, entry.getKey(), actual); answer.put(compositeData); } if (valueType.isInstance(value)) { CompositeDataSupport compositeData = createTabularRowValue(type, entry.getKey(), value); answer.put(compositeData); } } return answer; }
@Override public TabularData viewRemoteClusterStatus() { wanInfo.clear(); String[] wan = JMXProperties.getInstance().getProperty(getKey("wanInfo"), "").split(" "); int cnt = 0; while (wan.length >= (cnt + 2)) { try { wanInfo.put(buildWanInfoType(new String(wan[cnt]), Boolean.parseBoolean(wan[cnt + 1]))); } catch (OpenDataException e) { e.printStackTrace(); } cnt += 2; } return (TabularData) wanInfo.clone(); }
/** * Converts Map of strings into JMX tabular format. Every name/value pair considered as a separate tab * * @param props the source Map * @return the resulting JMX tabular structure */ public static TabularData propsToTabular(Map<String, String> props) { TabularData result = null; try { String typeName = "java.util.Map<java.lang.String, java.lang.String>"; String[] nameValue = new String[]{"name", "value"}; OpenType[] openTypes = new OpenType[]{SimpleType.STRING, SimpleType.STRING}; CompositeType rowType = new CompositeType(typeName, typeName, nameValue, nameValue, openTypes); TabularType tabularType = new TabularType(typeName, typeName, rowType, new String[]{"name"}); result = new TabularDataSupport(tabularType); if (props != null && props.size() > 0) { for (Map.Entry<String, String> prop : props.entrySet()) { result.put(new CompositeDataSupport(rowType, nameValue, new Object[]{prop.getKey(), prop.getValue()})); } } } catch (OpenDataException ex) { logger.error("propsToTabular. error: ", ex); } return result; }
@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; }
private Object getTableData(TabularType tabularType) throws MBeanException { TabularDataSupport tableData = new TabularDataSupport(tabularType); for (String[] rowData : TABLE_DATA) { try { tableData.put(new CompositeDataSupport(tabularType.getRowType(), COLUMN_NAMES, rowData)); } catch (OpenDataException exc) { throw new MBeanException(exc, "Error creating table data"); } } return tableData; }
static TabularData getConfigElementTable(Map<String, String> config) throws OpenDataException { TabularDataSupport table = new TabularDataSupport(FEATURE_CONFIG_ELEMENT_TABLE); for (Map.Entry<String, String> entry : config.entrySet()) { String[] itemNames = FeaturesServiceMBean.FEATURE_CONFIG_ELEMENT; Object[] itemValues = {entry.getKey(), entry.getValue()}; CompositeData element = new CompositeDataSupport(FEATURE_CONFIG_ELEMENT, itemNames, itemValues); table.put(element); } return table; }
Vector mappedClassNames = getMappedClassNames(); String mappedClassName; TabularDataSupport rowData = new TabularDataSupport(buildTabularTypeForClassSummaryDetails()); mappedClassName = (String)mappedClassNames.elementAt(index); String[] key = new String[] { mappedClassName }; rowData.put(key, buildDetailsFor(mappedClassName, rowData.getTabularType().getRowType()));
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); } }
@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; }
CompositeType rt = new CompositeType("a", "b", new String[] { "a" }, new String[] { javax.management.openmbean.SimpleType.INTEGER }); TabularType tt = new TabularType("a", "b", rt, new String[] { "a" }); TabularDataSupport t1 = new TabularDataSupport(tt); TabularDataSupport t2 = new TabularDataSupport(tt);
public TabularData getSlowConsumers() throws OpenDataException { OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(SlowConsumerEntry.class); CompositeType ct = factory.getCompositeType(); TabularType tt = new TabularType("SlowConsumers", "Table of current slow Consumers", ct, new String[] {"subscription" }); TabularDataSupport rc = new TabularDataSupport(tt); int index = 0; Map<Subscription, SlowConsumerEntry> slowConsumers = strategy.getSlowConsumers(); for (Map.Entry<Subscription, SlowConsumerEntry> entry : slowConsumers.entrySet()) { entry.getValue().setSubscription(broker.getSubscriberObjectName(entry.getKey())); rc.put(OpenTypeSupport.convert(entry.getValue())); } return rc; }
public static TabularData toTabularData(List<? extends Trigger> triggers) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); if (triggers != null) { ArrayList<CompositeData> list = new ArrayList<CompositeData>(); for (Trigger trigger : triggers) { list.add(toCompositeData(trigger)); } tData.putAll(list.toArray(new CompositeData[list.size()])); } return tData; }
private TabularData convertTabularDataFromFullRepresentation(JSONObject pValue, TabularType pType) { JSONAware jsonVal; jsonVal = (JSONAware) pValue.get("values"); if (!(jsonVal instanceof JSONArray)) { throw new IllegalArgumentException("Values for tabular data of type " + pType + " must given as JSON array, not " + jsonVal.getClass()); } TabularDataSupport tabularData = new TabularDataSupport(pType); for (Object val : (JSONArray) jsonVal) { if (!(val instanceof JSONObject)) { throw new IllegalArgumentException("Tabular-Data values must be given as JSON objects, not " + val.getClass()); } tabularData.put((CompositeData) getDispatcher().convertToObject(pType.getRowType(), val)); } return tabularData; }
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); } JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().convertToObject(type.getRowType(), jsonValue)); } } } }
private static TabularData deserialize(final TabularType type, final JsonNode rows, final ObjectCodec codec) throws IOException { final TabularData result = new TabularDataSupport(type); for(final JsonNode row: rows) result.put(deserialize(type.getRowType(), row, codec)); return result; }
public ServerObject(String name) { this.name = name; this.wanInfo = new TabularDataSupport(wanType); }
private TabularData createTabularDataFromLevelsMap(Map<String, String> levels) { TabularData loggerLevelList = new TabularDataSupport(LOGGER_LEVEL_TABULAR_TYPE); for (Map.Entry<String,String> entry : levels.entrySet()) { String loggerName = entry.getKey(); String level = entry.getValue(); CompositeData loggerData = createRow(loggerName, level); loggerLevelList.put(loggerData); } return loggerLevelList; }
/** {@inheritDoc} */ @Override Object convertToObject(TabularType pType, Object pFrom) { JSONObject value = getAsJsonObject(pFrom); // Convert simple map representation (with rowtype "key" and "value") if (checkForMapAttributeWithSimpleKey(pType)) { return convertToTabularTypeFromMap(pType, value); } // If it is given a a full representation (with "indexNames" and "values"), then parse this // accordingly if (checkForFullTabularDataRepresentation(value, pType)) { return convertTabularDataFromFullRepresentation(value, pType); } // Its a plain TabularData, which is tried to convert rom a maps of maps TabularDataSupport tabularData = new TabularDataSupport(pType); // Recursively go down the map and collect the values putRowsToTabularData(tabularData, value, pType.getIndexNames().size()); return tabularData; }