Search in sources :

Example 6 with OpenDataException

use of javax.management.openmbean.OpenDataException 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 7 with OpenDataException

use of javax.management.openmbean.OpenDataException 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 8 with OpenDataException

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

the class OpenMethod method invokeWithOpenReturn.

Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
    final Object[] javaParams;
    try {
        javaParams = fromOpenParameters(params);
    } catch (InvalidObjectException e) {
        final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
        throw new MBeanException(e, msg);
    }
    final Object javaReturn = method.invoke(obj, javaParams);
    try {
        return returnTypeConverter.toOpenValue(javaReturn);
    } catch (OpenDataException e) {
        final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
        throw new MBeanException(e, msg);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) MBeanException(javax.management.MBeanException) InvalidObjectException(java.io.InvalidObjectException)

Example 9 with OpenDataException

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

the class OpenTypeConverter method makeCompositeConverter.

/**
   * @return the open type converrter for a given type
   */
private static OpenTypeConverter makeCompositeConverter(Class c) throws OpenDataException {
    final List<Method> methods = Arrays.asList(c.getMethods());
    final SortedMap<String, Method> getterMap = OpenTypeUtil.newSortedMap();
    for (Method method : methods) {
        final String propertyName = propertyName(method);
        if (propertyName == null)
            continue;
        Method old = getterMap.put(OpenTypeUtil.decapitalize(propertyName), method);
        if (old != null) {
            final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
            throw new OpenDataException(msg);
        }
    }
    final int nitems = getterMap.size();
    if (nitems == 0) {
        throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
    }
    final Method[] getters = new Method[nitems];
    final String[] itemNames = new String[nitems];
    final OpenType[] openTypes = new OpenType[nitems];
    int i = 0;
    for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
        itemNames[i] = entry.getKey();
        final Method getter = entry.getValue();
        getters[i] = getter;
        final Type retType = getter.getGenericReturnType();
        openTypes[i] = toConverter(retType).getOpenType();
        i++;
    }
    CompositeType compositeType = new // field
    CompositeType(// field
    c.getName(), // field
    c.getName(), // field
    itemNames, // field descriptions
    itemNames, openTypes);
    return new CompositeConverter(c, compositeType, itemNames, getters);
}
Also used : OpenType(javax.management.openmbean.OpenType) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) ArrayType(javax.management.openmbean.ArrayType) CompositeType(javax.management.openmbean.CompositeType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) TabularType(javax.management.openmbean.TabularType) OpenDataException(javax.management.openmbean.OpenDataException) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) SortedMap(java.util.SortedMap) CompositeType(javax.management.openmbean.CompositeType)

Example 10 with OpenDataException

use of javax.management.openmbean.OpenDataException 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)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)51 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)24 TabularDataSupport (javax.management.openmbean.TabularDataSupport)22 TabularType (javax.management.openmbean.TabularType)22 CompositeType (javax.management.openmbean.CompositeType)21 CompositeData (javax.management.openmbean.CompositeData)17 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 MBeanServer (javax.management.MBeanServer)5 TabularData (javax.management.openmbean.TabularData)5 ArrayType (javax.management.openmbean.ArrayType)4 InvalidObjectException (java.io.InvalidObjectException)3 SortedMap (java.util.SortedMap)3 JMException (javax.management.JMException)3 StandardMBean (javax.management.StandardMBean)3 IOException (java.io.IOException)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2