Java Code Examples for javax.management.openmbean.TabularData#values()

The following examples show how to use javax.management.openmbean.TabularData#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPipelineManagerMXBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private void verifyEquals(TabularData actualData, Map<String, Integer>
    expectedData) {
  if (actualData == null || expectedData == null) {
    fail("Data should not be null.");
  }
  for (Object obj : actualData.values()) {
    assertTrue(obj instanceof CompositeData);
    CompositeData cds = (CompositeData) obj;
    assertEquals(2, cds.values().size());
    Iterator<?> it = cds.values().iterator();
    String key = it.next().toString();
    String value = it.next().toString();
    long num = Long.parseLong(value);
    assertTrue(expectedData.containsKey(key));
    assertEquals(expectedData.remove(key).longValue(), num);
  }
  assertTrue(expectedData.isEmpty());
}
 
Example 2
Source File: TestSCMNodeManagerMXBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private void verifyEquals(TabularData actualData, Map<String, Long>
    expectedData) {
  if (actualData == null || expectedData == null) {
    fail("Data should not be null.");
  }
  for (Object obj : actualData.values()) {
    assertTrue(obj instanceof CompositeData);
    CompositeData cds = (CompositeData) obj;
    assertEquals(2, cds.values().size());
    Iterator<?> it = cds.values().iterator();
    String key = it.next().toString();
    String value = it.next().toString();
    long num = Long.parseLong(value);
    assertTrue(expectedData.containsKey(key));
    assertEquals(expectedData.remove(key).longValue(), num);
  }
  assertTrue(expectedData.isEmpty());
}
 
Example 3
Source File: TestSCMMXBean.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * An internal function used to compare a TabularData returned
 * by JMX with the expected data in a Map.
 */
private void verifyEquals(TabularData actualData,
    Map<String, Integer> expectedData) {
  if (actualData == null || expectedData == null) {
    fail("Data should not be null.");
  }
  for (Object obj : actualData.values()) {
    // Each TabularData is a set of CompositeData
    assertTrue(obj instanceof CompositeData);
    CompositeData cds = (CompositeData) obj;
    assertEquals(2, cds.values().size());
    Iterator<?> it = cds.values().iterator();
    String key = it.next().toString();
    String value = it.next().toString();
    int num = Integer.parseInt(value);
    assertTrue(expectedData.containsKey(key));
    assertEquals(expectedData.remove(key).intValue(), num);
  }
  assertTrue(expectedData.isEmpty());
}
 
Example 4
Source File: ConfigurationInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Map<String, String> createMap(Object o) {
    if (o instanceof TabularData) {
        TabularData td = (TabularData) o;
        Collection<?> values = td.values();
        Map<String, String> map = new HashMap<>(values.size());
        for (Object value : td.values()) {
            if (value instanceof CompositeData) {
                CompositeData cdRow = (CompositeData) value;
                Object k = cdRow.get("key");
                Object v = cdRow.get("value");
                if (k instanceof String && v instanceof String) {
                    map.put((String) k, (String) v);
                }
            }
        }
        return Collections.unmodifiableMap(map);
    }
    return Collections.emptyMap();
}
 
Example 5
Source File: ConfigurationInfo.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Map<String, String> createMap(Object o) {
    if (o instanceof TabularData) {
        TabularData td = (TabularData) o;
        Collection<?> values = td.values();
        Map<String, String> map = new HashMap<>(values.size());
        for (Object value : td.values()) {
            if (value instanceof CompositeData) {
                CompositeData cdRow = (CompositeData) value;
                Object k = cdRow.get("key");
                Object v = cdRow.get("value");
                if (k instanceof String && v instanceof String) {
                    map.put((String) k, (String) v);
                }
            }
        }
        return Collections.unmodifiableMap(map);
    }
    return Collections.emptyMap();
}
 
Example 6
Source File: Client.java    From vjtools with Apache License 2.0 6 votes vote down vote up
protected static StringBuffer recurseTabularData(StringBuffer buffer, String indent, String name,
		TabularData data) {
	addNameToBuffer(buffer, indent, name);
	java.util.Collection c = data.values();
	for (Iterator i = c.iterator(); i.hasNext();) {
		Object obj = i.next();
		if (obj instanceof CompositeData) {
			recurseCompositeData(buffer, indent + " ", "", (CompositeData) obj);
		} else if (obj instanceof TabularData) {
			recurseTabularData(buffer, indent, "", (TabularData) obj);
		} else {
			buffer.append(obj);
		}
	}
	return buffer;
}
 
Example 7
Source File: Client.java    From vjtools with Apache License 2.0 6 votes vote down vote up
protected static StringBuffer recurseTabularData(StringBuffer buffer, String indent, String name,
		TabularData data) {
	addNameToBuffer(buffer, indent, name);
	java.util.Collection c = data.values();
	for (Iterator i = c.iterator(); i.hasNext();) {
		Object obj = i.next();
		if (obj instanceof CompositeData) {
			recurseCompositeData(buffer, indent + " ", "", (CompositeData) obj);
		} else if (obj instanceof TabularData) {
			recurseTabularData(buffer, indent, "", (TabularData) obj);
		} else {
			buffer.append(obj);
		}
	}
	return buffer;
}
 
Example 8
Source File: ConfigurationInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static Map<String, String> createMap(Object o) {
    if (o instanceof TabularData) {
        TabularData td = (TabularData) o;
        Collection<?> values = td.values();
        Map<String, String> map = new HashMap<>(values.size());
        for (Object value : td.values()) {
            if (value instanceof CompositeData) {
                CompositeData cdRow = (CompositeData) value;
                Object k = cdRow.get("key");
                Object v = cdRow.get("value");
                if (k instanceof String && v instanceof String) {
                    map.put((String) k, (String) v);
                }
            }
        }
        return Collections.unmodifiableMap(map);
    }
    return Collections.emptyMap();
}
 
Example 9
Source File: JSONWriter.java    From quartz-web with Apache License 2.0 6 votes vote down vote up
public void writeTabularData(TabularData tabularData) {
    if (tabularData == null) {
        writeNull();
        return;
    }

    int entryIndex = 0;
    write('[');

    for (Object item : tabularData.values()) {
        if (entryIndex != 0) {
            write(',');
        }
        CompositeData row = (CompositeData) item;
        writeCompositeData(row);

        entryIndex++;
    }
    write(']');
}
 
Example 10
Source File: JMXJsonServlet.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } 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;
      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 {
      jg.writeString(value.toString());
    }
  }
}
 
Example 11
Source File: JMXJsonServlet.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } 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;
      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 {
      jg.writeString(value.toString());
    }
  }
}
 
Example 12
Source File: AttributeHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
private static String tabularToString(TabularData tabularData) {
    TabularType type = tabularData.getTabularType();
    StringBuilder b = new StringBuilder();
    b.append("(").append(type.getTypeName()).append(")\n");
    Collection<CompositeData> values = (Collection) tabularData.values();
    for (CompositeData cd: values) {
        b.append(compositeToString(cd));
    }
    return b.toString();
}
 
Example 13
Source File: JmxValueFunctions.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static Map tabularDataToMap(TabularData table) {
    Map<String, Object> result = Maps.newLinkedHashMap();
    for (Object entry : table.values()) {
        CompositeData data = (CompositeData) entry; //.getValue()
        for (String key : data.getCompositeType().keySet()) {
            Object old = result.put(key, data.get(key));
            if (old != null) {
                log.warn("tablularDataToMap has overwritten key {}", key);
            }
        }
    }
    return result;
}
 
Example 14
Source File: TestSCMMXBean.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Test
public void testSCMMXBean() throws Exception {
  ObjectName bean = new ObjectName(
      "Hadoop:service=StorageContainerManager,"
          + "name=StorageContainerManagerInfo,"
          + "component=ServerRuntime");

  String dnRpcPort = (String)mbs.getAttribute(bean,
      "DatanodeRpcPort");
  assertEquals(scm.getDatanodeRpcPort(), dnRpcPort);


  String clientRpcPort = (String)mbs.getAttribute(bean,
      "ClientRpcPort");
  assertEquals(scm.getClientRpcPort(), clientRpcPort);

  ConcurrentMap<String, ContainerStat> map = scm.getContainerReportCache();
  ContainerStat stat = new ContainerStat(1, 2, 3, 4, 5, 6, 7);
  map.put("nodeID", stat);
  TabularData data = (TabularData) mbs.getAttribute(
      bean, "ContainerReport");

  // verify report info
  assertEquals(1, data.values().size());
  for (Object obj : data.values()) {
    assertTrue(obj instanceof CompositeData);
    CompositeData d = (CompositeData) obj;
    Iterator<?> it = d.values().iterator();
    String key = it.next().toString();
    String value = it.next().toString();
    assertEquals("nodeID", key);
    assertEquals(stat.toJsonString(), value);
  }

  boolean inSafeMode = (boolean) mbs.getAttribute(bean,
      "InSafeMode");
  assertEquals(scm.isInSafeMode(), inSafeMode);

  double containerThreshold = (double) mbs.getAttribute(bean,
      "SafeModeCurrentContainerThreshold");
  assertEquals(scm.getCurrentContainerThreshold(), containerThreshold, 0);
}
 
Example 15
Source File: SdcInfoContentGenerator.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } 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());
    }
  }
}
 
Example 16
Source File: JSONBean.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void writeObject(JsonWriter writer, Object value) throws IOException {
  if (value == null) {
    writer.nullValue();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      writer.beginArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(writer, item);
      }
      writer.endArray();
    } else if (value instanceof Number) {
      Number n = (Number) value;
      if (Double.isFinite(n.doubleValue())) {
        writer.value(n);
      } else {
        writer.value(n.toString());
      }
    } else if (value instanceof Boolean) {
      Boolean b = (Boolean) value;
      writer.value(b);
    } else if (value instanceof CompositeData) {
      CompositeData cds = (CompositeData) value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      writer.beginObject();
      for (String key : keys) {
        writeAttribute(writer, key, null, cds.get(key));
      }
      writer.endObject();
    } else if (value instanceof TabularData) {
      TabularData tds = (TabularData) value;
      writer.beginArray();
      for (Object entry : tds.values()) {
        writeObject(writer, entry);
      }
      writer.endArray();
    } else {
      writer.value(value.toString());
    }
  }
}