Search in sources :

Example 26 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project aries by apache.

the class PropertyDataTest method testFromCompositeDataForWrapperTypes.

@Test
public void testFromCompositeDataForWrapperTypes() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(KEY, "key");
    items.put(VALUE, "1");
    items.put(TYPE, INTEGER);
    CompositeData compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Integer> intData = PropertyData.from(compositeData);
    assertEquals("key", intData.getKey());
    assertEquals(new Integer(1), intData.getValue());
    assertEquals(INTEGER, intData.getEncodedType());
    assertFalse(intData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "1.0");
    items.put(TYPE, DOUBLE);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Double> doubleData = PropertyData.from(compositeData);
    assertEquals("key", doubleData.getKey());
    assertEquals(Double.valueOf(1.0), doubleData.getValue());
    assertEquals(DOUBLE, doubleData.getEncodedType());
    assertFalse(doubleData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "a");
    items.put(TYPE, CHARACTER);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Character> charData = PropertyData.from(compositeData);
    assertEquals("key", charData.getKey());
    assertEquals(Character.valueOf('a'), charData.getValue());
    assertEquals(CHARACTER, charData.getEncodedType());
    assertFalse(charData.isEncodingPrimitive());
    items.clear();
    items.put(KEY, "key");
    items.put(VALUE, "true");
    items.put(TYPE, BOOLEAN);
    compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
    PropertyData<Boolean> booleanData = PropertyData.from(compositeData);
    assertEquals("key", booleanData.getKey());
    assertTrue(booleanData.getValue());
    assertEquals(BOOLEAN, booleanData.getEncodedType());
    assertFalse(booleanData.isEncodingPrimitive());
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 27 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project deltaspike by apache.

the class DeltaSpikeConfigInfo method getConfigSources.

@Override
public TabularData getConfigSources() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);
        String typeName = "ConfigSources";
        OpenType<?>[] types = new OpenType<?>[] { SimpleType.INTEGER, SimpleType.STRING };
        String[] keys = new String[] { "Ordinal", "ConfigSource" };
        CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
        TabularType type = new TabularType(typeName, typeName, ct, keys);
        TabularDataSupport configSourceInfo = new TabularDataSupport(type);
        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigSource configSource : configSources) {
            configSourceInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configSource.getOrdinal(), configSource.getConfigName() }));
        }
        return configSourceInfo;
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    } finally {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 28 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project deltaspike by apache.

the class DeltaSpikeConfigInfo method getConfigEntries.

@Override
public TabularData getConfigEntries() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(appConfigClassLoader);
        List<ConfigEntry> configEntries = calculateConfigEntries();
        String[] configArray = new String[configEntries.size()];
        for (int i = 0; i < configEntries.size(); i++) {
            ConfigEntry configEntry = configEntries.get(i);
            configArray[i] = configEntry.getKey() + " = " + configEntry.getValue() + " - picked up from: " + configEntry.getFromConfigSource();
        }
        String typeName = "ConfigEntries";
        OpenType<?>[] types = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
        String[] keys = new String[] { "Key", "Value", "fromConfigSource" };
        CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
        TabularType type = new TabularType(typeName, typeName, ct, keys);
        TabularDataSupport configEntryInfo = new TabularDataSupport(type);
        ConfigSource[] configSources = ConfigResolver.getConfigSources();
        for (ConfigEntry configEntry : configEntries) {
            configEntryInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configEntry.getKey(), configEntry.getValue(), configEntry.getFromConfigSource() }));
        }
        return configEntryInfo;
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    } finally {
        // set back the original TCCL
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 29 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project geode by apache.

the class TableConverter method toNonNullOpenValue.

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;
}
Also used : TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Comparator(java.util.Comparator) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) SortedMap(java.util.SortedMap) Map(java.util.Map) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 30 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project geode by apache.

the class CompositeConverter method toNonNullOpenValue.

/**
   * Converts to open value
   */
Object toNonNullOpenValue(Object value) throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;
    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = getters[i].invoke(value, (Object[]) null);
            values[i] = getterConverters[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
Also used : CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeDataView(javax.management.openmbean.CompositeDataView) OpenDataException(javax.management.openmbean.OpenDataException) InvalidObjectException(java.io.InvalidObjectException) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)92 CompositeData (javax.management.openmbean.CompositeData)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)60 CompositeType (javax.management.openmbean.CompositeType)55 TabularData (javax.management.openmbean.TabularData)43 OpenDataException (javax.management.openmbean.OpenDataException)25 HashMap (java.util.HashMap)21 Map (java.util.Map)19 TabularType (javax.management.openmbean.TabularType)19 OpenType (javax.management.openmbean.OpenType)10 Test (org.junit.Test)8 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 IOException (java.io.IOException)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)3 MBeanInfo (javax.management.MBeanInfo)3 Bundle (org.osgi.framework.Bundle)3