Search in sources :

Example 16 with OpenType

use of javax.management.openmbean.OpenType in project ddf by codice.

the class UndeliveredMessages method getMessages.

@Override
public List<CompositeData> getMessages(String address, String module) {
    List<CompositeData> undeliveredMessages = new ArrayList<>();
    Object compositeDatas = invokeMbean(createArtemisObjectName(address, module), GET_MESSAGES_OPERATION, new Object[] { "" }, new String[] { String.class.getName() });
    if (!(compositeDatas instanceof CompositeData[])) {
        return undeliveredMessages;
    }
    CompositeData[] messages = (CompositeData[]) compositeDatas;
    for (CompositeData message : messages) {
        Set<String> setMessageKeys = message.getCompositeType().keySet();
        String[] messageKeysArray = setMessageKeys.toArray(new String[setMessageKeys.size()]);
        Object[] messageValues = message.getAll(messageKeysArray);
        CompositeType messageCompositeType = message.getCompositeType();
        String[] itemDescription = new String[messageKeysArray.length];
        OpenType<?>[] itemTypes = new OpenType[messageKeysArray.length];
        try {
            for (int i = 0; i < messageKeysArray.length; i++) {
                String messageKey = messageKeysArray[i];
                itemDescription[i] = messageCompositeType.getDescription(messageKey);
                if (messageKeysArray[i].equals("body")) {
                    byte[] messageBodyBytes = (byte[]) message.get("body");
                    // Remove unprintable characters from the beginning of the string
                    messageValues[i] = removeNullCharacters(new String(Arrays.copyOfRange(messageBodyBytes, 5, messageBodyBytes.length), StandardCharsets.UTF_8));
                    itemTypes[i] = SimpleType.STRING;
                } else {
                    itemTypes[i] = messageCompositeType.getType(messageKey);
                }
            }
            undeliveredMessages.add(new CompositeDataSupport(new CompositeType(messageCompositeType.getTypeName(), messageCompositeType.getDescription(), messageKeysArray, itemDescription, itemTypes), messageKeysArray, messageValues));
        } catch (OpenDataException e) {
            LOGGER.warn("Unable to retrieve messages from the broker. For more information, set " + "logging level to DEBUG.");
            LOGGER.debug("Unable to retrieve messages from the broker.", e);
        }
    }
    return undeliveredMessages;
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ArrayList(java.util.ArrayList) OpenDataException(javax.management.openmbean.OpenDataException) CompositeType(javax.management.openmbean.CompositeType)

Example 17 with OpenType

use of javax.management.openmbean.OpenType in project Payara by payara.

the class OpenMBeanUtil method getThrowableOpenType.

/**
 *    Get a CompositeType describing a CompositeData which has no elements.
 */
public static OpenType getThrowableOpenType(final Throwable t) throws OpenDataException {
    final String[] itemNames = new String[] { "Message", "Cause", "StackTrace" };
    final String[] descriptions = new String[] { "The message from the Throwable", "The cause (if any) from the Throwable", "The stack trace from the Throwable" };
    final OpenType[] openTypes = new OpenType[itemNames.length];
    openTypes[0] = SimpleType.STRING;
    openTypes[1] = t.getCause() == null ? SimpleType.VOID : getThrowableOpenType(t.getCause());
    openTypes[2] = newArrayType(t.getStackTrace().length, getStackTraceElementOpenType());
    return (new CompositeType(t.getClass().getName(), "Throwable composite type", itemNames, descriptions, openTypes));
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeType(javax.management.openmbean.CompositeType)

Example 18 with OpenType

use of javax.management.openmbean.OpenType in project Payara by payara.

the class OpenMBeanUtil method mapToCompositeType.

/**
 *    Create a CompositeType from a Map.  Each key in the map must be a String,
 *    and each value must be a type consistent with OpenTypes.
 *
 *    @param typeName	the arbitrary name of the OpenType to be used
 *    @param description	the arbitrary description of the OpenType to be used
 *    @param map	a Map keyed by String, whose values may not be null
 */
public static CompositeType mapToCompositeType(final String typeName, final String description, final Map<String, ?> map, CompositeTypeFromNameCallback callback) throws OpenDataException {
    final String[] itemNames = new String[map.keySet().size()];
    map.keySet().toArray(itemNames);
    final String[] itemDescriptions = new String[itemNames.length];
    final OpenType[] itemTypes = new OpenType[itemNames.length];
    for (int i = 0; i < itemNames.length; ++i) {
        final String name = itemNames[i];
        final Object value = map.get(name);
        itemDescriptions[i] = "value " + name;
        if (value == null) {
            // force nulls to type String
            itemTypes[i] = callback.getOpenTypeFromName(name);
        } else {
            itemTypes[i] = getOpenType(value);
        }
    }
    final CompositeType type = new CompositeType(typeName, description, itemNames, itemDescriptions, itemTypes);
    return (type);
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeType(javax.management.openmbean.CompositeType)

Example 19 with OpenType

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

the class DefaultMXBeanMappingFactory method makeCompositeMapping.

private MXBeanMapping makeCompositeMapping(Class<?> c, MXBeanMappingFactory factory) throws OpenDataException {
    // For historical reasons GcInfo implements CompositeData but we
    // shouldn't count its CompositeData.getCompositeType() field as
    // an item in the computed CompositeType.
    final boolean gcInfoHack = (c.getName().equals("com.sun.management.GcInfo") && c.getClassLoader() == null);
    ReflectUtil.checkPackageAccess(c);
    final List<Method> methods = MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
    final SortedMap<String, Method> getterMap = newSortedMap();
    /* Select public methods that look like "T getX()" or "boolean
           isX()", where T is not void and X is not the empty
           string.  Exclude "Class getClass()" inherited from Object.  */
    for (Method method : methods) {
        final String propertyName = propertyName(method);
        if (propertyName == null)
            continue;
        if (gcInfoHack && propertyName.equals("CompositeType"))
            continue;
        Method old = getterMap.put(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] = factory.mappingForType(retType, factory).getOpenType();
        i++;
    }
    CompositeType compositeType = new CompositeType(c.getName(), c.getName(), // field names
    itemNames, // field descriptions
    itemNames, openTypes);
    return new CompositeMapping(c, compositeType, itemNames, getters, factory);
}
Also used : OpenType(javax.management.openmbean.OpenType) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) SimpleType(javax.management.openmbean.SimpleType) ArrayType(javax.management.openmbean.ArrayType) CompositeType(javax.management.openmbean.CompositeType) ElementType(java.lang.annotation.ElementType) 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 20 with OpenType

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

the class LocalMBeanServer method tabularData.

public static TabularData tabularData(final String typeName, final String typeDescription, final String[] names, final Object[] values) {
    if (names.length == 0) {
        return null;
    }
    final OpenType<?>[] types = new OpenType<?>[names.length];
    for (int i = 0; i < types.length; i++) {
        types[i] = SimpleType.STRING;
    }
    try {
        final CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
        final TabularType type = new TabularType(typeName, typeDescription, ct, names);
        final TabularDataSupport data = new TabularDataSupport(type);
        final CompositeData line = new CompositeDataSupport(ct, names, values);
        data.put(line);
        return data;
    } catch (final OpenDataException e) {
        return null;
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) 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