public static TabularData tableFrom(Collection<JmxProviderState> jmxProviderStates) {
   TabularDataSupport table = new TabularDataSupport(PROVIDER_STATE_TABLE);
   for (JmxProviderState entry : jmxProviderStates) {
     table.put(entry.asCompositeData());
   }
   return table;
 }
 /** Wraps the service statistics into JMX types */
 private void populateServiceStatistics(boolean clearCollectedStats) {
   // clear existing stats in the TabularDataSupport and re-populate it with current data extracted
   // from service framework classes
   serviceInvocationStatistics.clear();
   ServiceStatistics[] stats = getStats(clearCollectedStats);
   for (ServiceStatistics stat : stats) {
     Object[] statValues = new Object[attributeNames.length];
     statValues[0] = stat.getServiceName();
     statValues[1] = stat.getServiceVersion();
     statValues[2] = stat.getStartupTimeStamp().getTime();
     statValues[3] =
         stat.getLastCalledTimestamp() == null ? null : stat.getLastCalledTimestamp().getTime();
     statValues[4] = stat.getActiveRequestsCount();
     statValues[5] = stat.getTotalRequestsCount();
     statValues[6] = stat.getAverageResponseTime();
     statValues[7] = stat.getMinimumResponseTime();
     statValues[8] = stat.getMaximumResponseTime();
     statValues[9] = stat.getLastServiceRequestResponseTime();
     statValues[10] = stat.getErrorRequestsCount();
     statValues[11] = stat.getSuccessRequestsCount();
     CompositeData compositeData;
     try {
       compositeData = new CompositeDataSupport(compositeType, attributeNames, statValues);
       serviceInvocationStatistics.put(compositeData);
     } catch (OpenDataException e) {
       // ideally we should not get this exception
       LOGGER.error(
           "Error constructing JMX data type from service statistics. Error is : "
               + e.getMessage(),
           e);
     }
   }
 }
Пример #3
0
  @Test
  public void testJmxAttributeOfTypeTabularDataProviderConvertedToMap() throws Exception {
    // Create the CompositeType and TabularData
    CompositeType compositeType =
        new CompositeType(
            "typeName",
            "description",
            new String[] {"myint", "mystring", "mybool"}, // item names
            new String[] {
              "myint", "mystring", "mybool"
            }, // item descriptions, can't be null or empty string
            new OpenType<?>[] {SimpleType.INTEGER, SimpleType.STRING, SimpleType.BOOLEAN});
    TabularType tt =
        new TabularType("typeName", "description", compositeType, new String[] {"myint"});
    TabularDataSupport tds = new TabularDataSupport(tt);
    tds.put(
        new CompositeDataSupport(
            compositeType,
            new String[] {"mybool", "myint", "mystring"},
            new Object[] {true, 1234, "on"}));

    // Create MBean
    GeneralisedDynamicMBean mbean =
        jmxService.registerMBean(ImmutableMap.of(attributeName, tds), objectName);

    feed =
        JmxFeed.builder()
            .entity(entity)
            .pollAttribute(
                new JmxAttributePollConfig<Map>(mapAttribute)
                    .objectName(objectName)
                    .attributeName(attributeName)
                    .onSuccess((Function) JmxValueFunctions.tabularDataToMap()))
            .build();

    // Starts with value defined when registering...
    assertSensorEventually(
        mapAttribute,
        ImmutableMap.of("myint", 1234, "mystring", "on", "mybool", Boolean.TRUE),
        TIMEOUT_MS);
  }
  private static TabularData tabularData(
      String typeName, String typeDescription, String[] names, Object[] values) {
    if (names.length == 0) {
      return null;
    }

    OpenType<?>[] types = new OpenType<?>[names.length];
    for (int i = 0; i < types.length; i++) {
      types[i] = SimpleType.STRING;
    }

    try {
      CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
      TabularType type = new TabularType(typeName, typeDescription, ct, names);
      TabularDataSupport data = new TabularDataSupport(type);

      CompositeData line = new CompositeDataSupport(ct, names, values);
      data.put(line);

      return data;
    } catch (OpenDataException e) {
      return null;
    }
  }
 /**
  * Adds the specified {@link CompositeData} value to the table, ignoring the supplied key, by
  * simply calling <code>put((CompositeData) val)</code>.
  *
  * @param key ignored.
  * @param val the {@link CompositeData} value to add.
  * @return the {@link CompositeData} value.
  * @throws NullPointerException if <code>val</code> is <code>null</code>.
  * @throws InvalidOpenTypeException if the type of the given value does not match the row type.
  * @throws KeyAlreadyExistsException if the value has the same calculated index as an existing
  *     value.
  */
 public Object put(Object key, Object val) {
   put((CompositeData) val);
   return val;
 }