Search in sources :

Example 6 with OpenType

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

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

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

the class OpenTypeConverter method makeArrayOrCollectionConverter.

private static OpenTypeConverter makeArrayOrCollectionConverter(Type collectionType, Type elementType) throws OpenDataException {
    final OpenTypeConverter elementConverter = toConverter(elementType);
    final OpenType elementOpenType = elementConverter.getOpenType();
    final ArrayType openType = new ArrayType(1, elementOpenType);
    final Class elementOpenClass = elementConverter.getOpenClass();
    final Class openArrayClass;
    final String openArrayClassName;
    if (elementOpenClass.isArray())
        openArrayClassName = "[" + elementOpenClass.getName();
    else
        openArrayClassName = "[L" + elementOpenClass.getName() + ";";
    try {
        openArrayClass = Class.forName(openArrayClassName);
    } catch (ClassNotFoundException e) {
        throw openDataException("Cannot obtain array class", e);
    }
    if (collectionType instanceof ParameterizedType) {
        return new CollectionConverter(collectionType, openType, openArrayClass, elementConverter);
    } else {
        if (elementConverter.isIdentity()) {
            return new IdentityConverter(collectionType, openType, openArrayClass);
        } else {
            return new ArrayConverter(collectionType, openType, openArrayClass, elementConverter);
        }
    }
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) ArrayType(javax.management.openmbean.ArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) OpenType(javax.management.openmbean.OpenType)

Example 9 with OpenType

use of javax.management.openmbean.OpenType in project karaf by apache.

the class InstanceToTableMapper method createRowType.

private static CompositeType createRowType() throws OpenDataException {
    String desc = "This type describes Karaf instance";
    OpenType<?>[] itemTypes = new OpenType[] { SimpleType.INTEGER, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
    String[] descriptions = new String[] { "The Process ID of the instance or 0 if not running", "The name of the instance", "Whether the instance is root", "The SSH port that can be used to connect to the instance", "The host address where the SSH server is listening", "The RMI registry port that can be used to manage the instance", "The host address where the RMI registry is listening", "The RMI server port that can be used to manage the instance", "The host address where the RMI server is listening", "The state of the instance", "The location of the instance", "The Java options of the instance" };
    CompositeType comp = new CompositeType("Instances", desc, InstancesMBean.INSTANCE, descriptions, itemTypes);
    return comp;
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeType(javax.management.openmbean.CompositeType)

Example 10 with OpenType

use of javax.management.openmbean.OpenType in project karaf by apache.

the class JmxReference method createReferenceType.

private static CompositeType createReferenceType() {
    try {
        String description = "This type encapsulates Scr references";
        String[] itemNames = ScrServiceMBean.REFERENCE;
        OpenType[] itemTypes = new OpenType[itemNames.length];
        String[] itemDescriptions = new String[itemNames.length];
        itemTypes[0] = SimpleType.STRING;
        itemTypes[1] = SimpleType.BOOLEAN;
        itemTypes[2] = SimpleType.STRING;
        itemTypes[3] = SimpleType.STRING;
        itemTypes[4] = SimpleType.STRING;
        itemTypes[5] = new ArrayType(1, SimpleType.STRING);
        itemDescriptions[0] = "The name of the reference";
        itemDescriptions[1] = "The state of the reference";
        itemDescriptions[2] = "The cardinality of the reference";
        itemDescriptions[3] = "The availability of the reference";
        itemDescriptions[4] = "The policy of the reference";
        itemDescriptions[5] = "The bound services";
        return new CompositeType("Reference", description, itemNames, itemDescriptions, itemTypes);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Unable to build reference type", e);
    }
}
Also used : ArrayType(javax.management.openmbean.ArrayType) OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenType (javax.management.openmbean.OpenType)28 CompositeType (javax.management.openmbean.CompositeType)23 OpenDataException (javax.management.openmbean.OpenDataException)15 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)10 TabularType (javax.management.openmbean.TabularType)10 TabularDataSupport (javax.management.openmbean.TabularDataSupport)7 ObjectName (javax.management.ObjectName)6 ArrayType (javax.management.openmbean.ArrayType)6 CompositeData (javax.management.openmbean.CompositeData)6 GenericArrayType (java.lang.reflect.GenericArrayType)5 ParameterizedType (java.lang.reflect.ParameterizedType)5 MBeanServer (javax.management.MBeanServer)5 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)4 MBeanInfo (javax.management.MBeanInfo)4 Descriptor (javax.management.Descriptor)3 ImmutableDescriptor (javax.management.ImmutableDescriptor)3 JMException (javax.management.JMException)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)3