@Override public Map apply(CompositeData input) { return compositeDataToMap(input); }}; }
@Override public Map apply(TabularData input) { return tabularDataToMap(input); } }
@Override public Map apply(TabularData input) { return tabularDataToMapOfMaps(input); }}; }
@Override public Map apply(CompositeData input) { return compositeDataToMap(input); } }
@Override public Map apply(TabularData input) { return tabularDataToMap(input); }}; }
@Override public Map apply(TabularData input) { return tabularDataToMapOfMaps(input); } }
public static Map<List<?>, Map<String, Object>> tabularDataToMapOfMaps(TabularData table) { Map<List<?>, Map<String, Object>> result = Maps.newLinkedHashMap(); for (Object k : table.keySet()) { final Object[] kValues = ((List<?>)k).toArray(); CompositeData v = table.get(kValues); result.put((List<?>)k, compositeDataToMap(v)); } return result; }
@Test public void testTabularDataToMap() throws Exception { CompositeType rowType = new CompositeType( "MyRowType", "my row descr", new String[] {"key1", "key2"}, new String[] {"key1 descr", "key2 descr"}, new OpenType[] {SimpleType.STRING, SimpleType.STRING}); TabularType tabularType = new TabularType( "MyTabularType", "my table descr", rowType, new String[] {"key1"}); Map<String, ?> row1 = ImmutableMap.of( "key1", "row1.val1", "key2", "row1.val2"); Map<String, ?> row2 = ImmutableMap.of( "key1", "row2.val1", "key2", "row2.val2"); TabularDataSupport table = new TabularDataSupport(tabularType); table.put(new CompositeDataSupport(rowType, row1)); table.put(new CompositeDataSupport(rowType, row2)); Map<?,?> result = JmxValueFunctions.tabularDataToMap(table); assertEquals(result, row2); Map<?,?> result2 = JmxValueFunctions.tabularDataToMap().apply(table); assertEquals(result2, row2); } }
@Test public void testTabularDataToMapOfMaps() throws Exception { CompositeType rowType = new CompositeType( "MyRowType", "my row descr", new String[] {"key1", "key2"}, new String[] {"key1 descr", "key2 descr"}, new OpenType[] {SimpleType.STRING, SimpleType.STRING}); TabularType tabularType = new TabularType( "MyTabularType", "my table descr", rowType, new String[] {"key1"}); Map<String, ?> row1 = ImmutableMap.of( "key1", "row1.val1", "key2", "row1.val2"); Map<String, ?> row2 = ImmutableMap.of( "key1", "row2.val1", "key2", "row2.val2"); TabularDataSupport table = new TabularDataSupport(tabularType); table.put(new CompositeDataSupport(rowType, row1)); table.put(new CompositeDataSupport(rowType, row2)); Map<List<?>, Map<String, Object>> result = JmxValueFunctions.tabularDataToMapOfMaps(table); assertEquals(result, ImmutableMap.of(ImmutableList.of("row1.val1"), row1, ImmutableList.of("row2.val1"), row2)); Map<?,?> result2 = JmxValueFunctions.tabularDataToMapOfMaps().apply(table); assertEquals(result2, ImmutableMap.of(ImmutableList.of("row1.val1"), row1, ImmutableList.of("row2.val1"), row2)); }
@Test public void testCompositeDataToMap() throws Exception { CompositeType compositeType = new CompositeType( "MyCompositeType", "my composite descr", new String[] {"key1", "key2"}, new String[] {"key1 descr", "key2 descr"}, new OpenType[] {SimpleType.STRING, SimpleType.STRING}); Map<String, ?> items = ImmutableMap.of( "key1", "val1", "key2", "val2"); CompositeData data = new CompositeDataSupport(compositeType, items); Map<String,?> result = JmxValueFunctions.compositeDataToMap(data); assertEquals(result, items); Map<?,?> result2 = JmxValueFunctions.compositeDataToMap().apply(data); assertEquals(result2, items); }
.objectName(objectName) .attributeName(attributeName) .onSuccess((Function)JmxValueFunctions.tabularDataToMap())) .build();