Search in sources :

Example 11 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 12 with OpenType

use of javax.management.openmbean.OpenType in project jdk8u_jdk by JetBrains.

the class MXBeanIntrospector method getMBeanAttributeInfo.

@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName, ConvertingMethod getter, ConvertingMethod setter) {
    final boolean isReadable = (getter != null);
    final boolean isWritable = (setter != null);
    final boolean isIs = isReadable && getName(getter).startsWith("is");
    final String description = attributeName;
    final OpenType<?> openType;
    final Type originalType;
    if (isReadable) {
        openType = getter.getOpenReturnType();
        originalType = getter.getGenericReturnType();
    } else {
        openType = setter.getOpenParameterTypes()[0];
        originalType = setter.getGenericParameterTypes()[0];
    }
    Descriptor descriptor = typeDescriptor(openType, originalType);
    if (isReadable) {
        descriptor = ImmutableDescriptor.union(descriptor, getter.getDescriptor());
    }
    if (isWritable) {
        descriptor = ImmutableDescriptor.union(descriptor, setter.getDescriptor());
    }
    final MBeanAttributeInfo ai;
    if (canUseOpenInfo(originalType)) {
        ai = new OpenMBeanAttributeInfoSupport(attributeName, description, openType, isReadable, isWritable, isIs, descriptor);
    } else {
        ai = new MBeanAttributeInfo(attributeName, originalTypeString(originalType), description, isReadable, isWritable, isIs, descriptor);
    }
    return ai;
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) OpenMBeanAttributeInfoSupport(javax.management.openmbean.OpenMBeanAttributeInfoSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 13 with OpenType

use of javax.management.openmbean.OpenType in project jdk8u_jdk by JetBrains.

the class GarbageCollectionNotifInfoCompositeData method getBaseGcNotifInfoCompositeType.

private static synchronized CompositeType getBaseGcNotifInfoCompositeType() {
    if (baseGcNotifInfoCompositeType == null) {
        try {
            OpenType<?>[] baseGcNotifInfoItemTypes = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, GcInfoCompositeData.getBaseGcInfoCompositeType() };
            baseGcNotifInfoCompositeType = new CompositeType("sun.management.BaseGarbageCollectionNotifInfoCompositeType", "CompositeType for Base GarbageCollectionNotificationInfo", gcNotifInfoItemNames, gcNotifInfoItemNames, baseGcNotifInfoItemTypes);
        } catch (OpenDataException e) {
            // shouldn't reach here
            throw Util.newException(e);
        }
    }
    return baseGcNotifInfoCompositeType;
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Example 14 with OpenType

use of javax.management.openmbean.OpenType in project jdk8u_jdk by JetBrains.

the class GcInfoBuilder method getGcInfoCompositeType.

// Returns the CompositeType for the GcInfo including
// the extension attributes
synchronized CompositeType getGcInfoCompositeType() {
    if (gcInfoCompositeType != null)
        return gcInfoCompositeType;
    // First, fill with the attributes in the GcInfo
    String[] gcInfoItemNames = GcInfoCompositeData.getBaseGcInfoItemNames();
    OpenType[] gcInfoItemTypes = GcInfoCompositeData.getBaseGcInfoItemTypes();
    int numGcInfoItems = gcInfoItemNames.length;
    int itemCount = numGcInfoItems + gcExtItemCount;
    allItemNames = new String[itemCount];
    String[] allItemDescs = new String[itemCount];
    OpenType<?>[] allItemTypes = new OpenType<?>[itemCount];
    System.arraycopy(gcInfoItemNames, 0, allItemNames, 0, numGcInfoItems);
    System.arraycopy(gcInfoItemNames, 0, allItemDescs, 0, numGcInfoItems);
    System.arraycopy(gcInfoItemTypes, 0, allItemTypes, 0, numGcInfoItems);
    // Then fill with the extension GC-specific attributes, if any.
    if (gcExtItemCount > 0) {
        fillGcAttributeInfo(gc, gcExtItemCount, gcExtItemNames, gcExtItemTypes, gcExtItemDescs);
        System.arraycopy(gcExtItemNames, 0, allItemNames, numGcInfoItems, gcExtItemCount);
        System.arraycopy(gcExtItemDescs, 0, allItemDescs, numGcInfoItems, gcExtItemCount);
        for (int i = numGcInfoItems, j = 0; j < gcExtItemCount; i++, j++) {
            switch(gcExtItemTypes[j]) {
                case 'Z':
                    allItemTypes[i] = SimpleType.BOOLEAN;
                    break;
                case 'B':
                    allItemTypes[i] = SimpleType.BYTE;
                    break;
                case 'C':
                    allItemTypes[i] = SimpleType.CHARACTER;
                    break;
                case 'S':
                    allItemTypes[i] = SimpleType.SHORT;
                    break;
                case 'I':
                    allItemTypes[i] = SimpleType.INTEGER;
                    break;
                case 'J':
                    allItemTypes[i] = SimpleType.LONG;
                    break;
                case 'F':
                    allItemTypes[i] = SimpleType.FLOAT;
                    break;
                case 'D':
                    allItemTypes[i] = SimpleType.DOUBLE;
                    break;
                default:
                    throw new AssertionError("Unsupported type [" + gcExtItemTypes[i] + "]");
            }
        }
    }
    CompositeType gict = null;
    try {
        final String typeName = "sun.management." + gc.getName() + ".GcInfoCompositeType";
        gict = new CompositeType(typeName, "CompositeType for GC info for " + gc.getName(), allItemNames, allItemDescs, allItemTypes);
    } catch (OpenDataException e) {
        // shouldn't reach here
        throw Util.newException(e);
    }
    gcInfoCompositeType = gict;
    return gcInfoCompositeType;
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Example 15 with OpenType

use of javax.management.openmbean.OpenType in project jdk8u_jdk by JetBrains.

the class GarbageCollectionNotifInfoCompositeData method getCompositeTypeByBuilder.

private CompositeType getCompositeTypeByBuilder() {
    final GcInfoBuilder builder = AccessController.doPrivileged(new PrivilegedAction<GcInfoBuilder>() {

        public GcInfoBuilder run() {
            try {
                Class cl = Class.forName("com.sun.management.GcInfo");
                Field f = cl.getDeclaredField("builder");
                f.setAccessible(true);
                return (GcInfoBuilder) f.get(gcNotifInfo.getGcInfo());
            } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
                return null;
            }
        }
    });
    CompositeType gict = null;
    synchronized (compositeTypeByBuilder) {
        gict = compositeTypeByBuilder.get(builder);
        if (gict == null) {
            OpenType<?>[] gcNotifInfoItemTypes = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, builder.getGcInfoCompositeType() };
            try {
                final String typeName = "sun.management.GarbageCollectionNotifInfoCompositeType";
                gict = new CompositeType(typeName, "CompositeType for GC notification info", gcNotifInfoItemNames, gcNotifInfoItemNames, gcNotifInfoItemTypes);
                compositeTypeByBuilder.put(builder, gict);
            } catch (OpenDataException e) {
                // shouldn't reach here
                throw Util.newException(e);
            }
        }
    }
    return gict;
}
Also used : Field(java.lang.reflect.Field) OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenType (javax.management.openmbean.OpenType)32 CompositeType (javax.management.openmbean.CompositeType)26 OpenDataException (javax.management.openmbean.OpenDataException)15 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)10 TabularType (javax.management.openmbean.TabularType)10 CompositeData (javax.management.openmbean.CompositeData)7 TabularDataSupport (javax.management.openmbean.TabularDataSupport)7 ObjectName (javax.management.ObjectName)6 ArrayType (javax.management.openmbean.ArrayType)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