Search in sources :

Example 76 with OpenDataException

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

the class ThreadInfoCompositeData method getCompositeData.

protected CompositeData getCompositeData() {
    // Convert StackTraceElement[] to CompositeData[]
    StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    CompositeData[] stackTraceData = new CompositeData[stackTrace.length];
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
    }
    // Convert MonitorInfo[] and LockInfo[] to CompositeData[]
    CompositeData lockInfoData = LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
    // Convert LockInfo[] and MonitorInfo[] to CompositeData[]
    LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
    CompositeData[] lockedSyncsData = new CompositeData[lockedSyncs.length];
    for (int i = 0; i < lockedSyncs.length; i++) {
        LockInfo li = lockedSyncs[i];
        lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
    }
    MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
    CompositeData[] lockedMonitorsData = new CompositeData[lockedMonitors.length];
    for (int i = 0; i < lockedMonitors.length; i++) {
        MonitorInfo mi = lockedMonitors[i];
        lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
    }
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // threadInfoItemNames!
    final Object[] threadInfoItemValues = { new Long(threadInfo.getThreadId()), threadInfo.getThreadName(), threadInfo.getThreadState().name(), new Long(threadInfo.getBlockedTime()), new Long(threadInfo.getBlockedCount()), new Long(threadInfo.getWaitedTime()), new Long(threadInfo.getWaitedCount()), lockInfoData, threadInfo.getLockName(), new Long(threadInfo.getLockOwnerId()), threadInfo.getLockOwnerName(), stackTraceData, new Boolean(threadInfo.isSuspended()), new Boolean(threadInfo.isInNative()), lockedMonitorsData, lockedSyncsData };
    try {
        return new CompositeDataSupport(threadInfoCompositeType, threadInfoItemNames, threadInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) OpenDataException(javax.management.openmbean.OpenDataException) LockInfo(java.lang.management.LockInfo)

Example 77 with OpenDataException

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

the class MXBeanLookup method mxbeanToObjectName.

synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException {
    String wrong;
    if (mxbean instanceof Proxy) {
        InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
        if (ih instanceof MBeanServerInvocationHandler) {
            MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih;
            if (mbsih.getMBeanServerConnection().equals(mbsc))
                return mbsih.getObjectName();
            else
                wrong = "proxy for a different MBeanServer";
        } else
            wrong = "not a JMX proxy";
    } else {
        ObjectName name = mxbeanToObjectName.get(mxbean);
        if (name != null)
            return name;
        wrong = "not an MXBean registered in this MBeanServer";
    }
    String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName();
    throw new OpenDataException("Could not convert " + s + " to an ObjectName: " + wrong);
// Message will be strange if mxbean is null but it is not
// supposed to be.
}
Also used : Proxy(java.lang.reflect.Proxy) OpenDataException(javax.management.openmbean.OpenDataException) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ObjectName(javax.management.ObjectName)

Example 78 with OpenDataException

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

the class ConvertingMethod method invokeWithOpenReturn.

private Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
    final Object[] javaParams;
    try {
        javaParams = fromOpenParameters(params);
    } catch (InvalidObjectException e) {
        // probably can't happen
        final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
        throw new MBeanException(e, msg);
    }
    final Object javaReturn = MethodUtil.invoke(method, obj, javaParams);
    try {
        return returnMapping.toOpenValue(javaReturn);
    } catch (OpenDataException e) {
        // probably can't happen
        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 79 with OpenDataException

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

use of javax.management.openmbean.OpenDataException in project controller by opendaylight.

the class CompositeAttributeResolvingStrategy method parseAttribute.

@Override
public Optional<CompositeDataSupport> parseAttribute(final String attrName, final Object value) throws DocumentedException {
    if (value == null) {
        return Optional.absent();
    }
    Util.checkType(value, Map.class);
    Map<?, ?> valueMap = (Map<?, ?>) value;
    valueMap = preprocessValueMap(valueMap);
    Map<String, Object> items = Maps.newHashMap();
    Map<String, OpenType<?>> openTypes = Maps.newHashMap();
    final String[] names = new String[getOpenType().keySet().size()];
    final String[] descriptions = new String[getOpenType().keySet().size()];
    OpenType<?>[] itemTypes = new OpenType[names.length];
    int index = 0;
    for (Object innerAttrName : innerTypes.keySet()) {
        Preconditions.checkState(innerAttrName instanceof String, "Attribute name must be string");
        String innerAttrNameStr = (String) innerAttrName;
        AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy = innerTypes.get(innerAttrName);
        Object valueToParse = valueMap.get(innerAttrName);
        Optional<?> parsedInnerValue = attributeResolvingStrategy.parseAttribute(innerAttrNameStr, valueToParse);
        if (attributeResolvingStrategy instanceof EnumAttributeResolvingStrategy) {
            // Open type for enum contain the class name necessary for its resolution,
            // however in a DTO
            // the open type need to be just SimpleType.STRING so that JMX is happy
            // After the enum attribute is resolved, change its open type back to STRING
            openTypes.put(innerAttrNameStr, SimpleType.STRING);
        } else {
            openTypes.put(innerAttrNameStr, attributeResolvingStrategy.getOpenType());
        }
        items.put(yangToJavaAttrMapping.get(innerAttrNameStr), parsedInnerValue.isPresent() ? parsedInnerValue.get() : null);
        // fill names + item types in order to reconstruct the open type for current
        // attribute
        names[index] = yangToJavaAttrMapping.get(innerAttrNameStr);
        descriptions[index] = getOpenType().getDescription(names[index]);
        itemTypes[index] = openTypes.get(innerAttrNameStr);
        index++;
    }
    CompositeDataSupport parsedValue;
    try {
        LOG.trace("Attribute {} with open type {}. Reconstructing open type.", attrName, getOpenType());
        setOpenType(new CompositeType(getOpenType().getTypeName(), getOpenType().getDescription(), names, descriptions, itemTypes));
        LOG.debug("Attribute {}. Open type reconstructed to {}", attrName, getOpenType(), getOpenType());
        parsedValue = new CompositeDataSupport(getOpenType(), items);
    } catch (final OpenDataException e) {
        throw new IllegalStateException("An error occurred during restoration of composite type " + this + " for attribute " + attrName + " from value " + value, e);
    }
    LOG.debug("Attribute {} : {} parsed to type {} as {}", attrName, value, getOpenType(), parsedValue);
    return Optional.of(parsedValue);
}
Also used : OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) OpenDataException(javax.management.openmbean.OpenDataException) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)139 CompositeType (javax.management.openmbean.CompositeType)94 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)67 CompositeData (javax.management.openmbean.CompositeData)54 OpenType (javax.management.openmbean.OpenType)52 TabularType (javax.management.openmbean.TabularType)33 TabularDataSupport (javax.management.openmbean.TabularDataSupport)32 HashMap (java.util.HashMap)14 Map (java.util.Map)12 TabularData (javax.management.openmbean.TabularData)11 ObjectName (javax.management.ObjectName)8 ArrayType (javax.management.openmbean.ArrayType)8 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4 MBeanServer (javax.management.MBeanServer)4 SimpleType (javax.management.openmbean.SimpleType)4 IOException (java.io.IOException)3 InvalidObjectException (java.io.InvalidObjectException)3