public ThroughputQueueBroadcast deserialize()

in streams-monitoring/src/main/java/org/apache/streams/jackson/ThroughputQueueDeserializer.java [47:91]


  public ThroughputQueueBroadcast deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    try {
      MBeanServer server = ManagementFactory.getPlatformMBeanServer();

      ThroughputQueueBroadcast throughputQueueBroadcast = new ThroughputQueueBroadcast();
      JsonNode attributes = jsonParser.getCodec().readTree(jsonParser);

      ObjectName name = new ObjectName(attributes.get("canonicalName").asText());
      MBeanInfo info = server.getMBeanInfo(name);
      throughputQueueBroadcast.setName(name.toString());

      for (MBeanAttributeInfo attribute : Arrays.asList(info.getAttributes())) {
        try {
          switch (attribute.getName()) {
            case "CurrentSize":
              throughputQueueBroadcast.setCurrentSize((long) server.getAttribute(name, attribute.getName()));
              break;
            case "AvgWait":
              throughputQueueBroadcast.setAvgWait((double) server.getAttribute(name, attribute.getName()));
              break;
            case "MaxWait":
              throughputQueueBroadcast.setMaxWait((long) server.getAttribute(name, attribute.getName()));
              break;
            case "Removed":
              throughputQueueBroadcast.setRemoved((long) server.getAttribute(name, attribute.getName()));
              break;
            case "Added":
              throughputQueueBroadcast.setAdded((long) server.getAttribute(name, attribute.getName()));
              break;
            case "Throughput":
              throughputQueueBroadcast.setThroughput((double) server.getAttribute(name, attribute.getName()));
              break;
            default:
              break;
          }
        } catch (Exception ex) {
          LOGGER.error("Exception while trying to deserialize ThroughputQueueBroadcast object: {}", ex);
        }
      }

      return throughputQueueBroadcast;
    } catch (Exception ex) {
      return null;
    }
  }