Search in sources :

Example 1 with MXBeanMapping

use of com.sun.jmx.mbeanserver.MXBeanMapping in project spf4j by zolyfarkas.

the class Spf4jJMXBeanMapping method defaultHandler.

@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
public static JMXBeanMapping defaultHandler(final Type javaType, final JMXBeanMappingSupplier mappings) throws NotSerializableException {
    // falling back to MXBeanMappingFactory.DEFAULT
    try {
        MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(javaType, new MXBeanMappingFactory() {

            @Override
            public MXBeanMapping mappingForType(final Type t, final MXBeanMappingFactory f) throws OpenDataException {
                JMXBeanMapping m;
                try {
                    m = mappings.get(t);
                } catch (NotSerializableException ex) {
                    OpenDataException tex = new OpenDataException(t + " is not seriablizable ");
                    tex.initCause(ex);
                    throw tex;
                }
                if (m != null) {
                    return MXBeanMappings.convert(m);
                }
                return MXBeanMappingFactory.DEFAULT.mappingForType(t, f);
            }
        });
        return MXBeanMappings.convert(mapping);
    } catch (OpenDataException ex) {
        NotSerializableException nsex = Throwables.first(ex, NotSerializableException.class);
        if (nsex != null) {
            throw nsex;
        } else {
            throw new IllegalArgumentException("No type mapping for " + javaType, ex);
        }
    }
}
Also used : JMXBeanMapping(org.spf4j.jmx.JMXBeanMapping) 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) NotSerializableException(java.io.NotSerializableException) MXBeanMappingFactory(com.sun.jmx.mbeanserver.MXBeanMappingFactory) OpenDataException(javax.management.openmbean.OpenDataException) MXBeanMapping(com.sun.jmx.mbeanserver.MXBeanMapping) JMXBeanMapping(org.spf4j.jmx.JMXBeanMapping) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with MXBeanMapping

use of com.sun.jmx.mbeanserver.MXBeanMapping in project jdk8u_jdk by JetBrains.

the class CompositeDataInvocationHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    final String methodName = method.getName();
    // Handle the methods from java.lang.Object
    if (method.getDeclaringClass() == Object.class) {
        if (methodName.equals("toString") && args == null)
            return "Proxy[" + compositeData + "]";
        else if (methodName.equals("hashCode") && args == null)
            return compositeData.hashCode() + 0x43444948;
        else if (methodName.equals("equals") && args.length == 1 && method.getParameterTypes()[0] == Object.class)
            return equals(proxy, args[0]);
        else {
            // is Object and so it's safe.
            return method.invoke(this, args);
        }
    }
    String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
    if (propertyName == null) {
        throw new IllegalArgumentException("Method is not getter: " + method.getName());
    }
    Object openValue;
    if (compositeData.containsKey(propertyName))
        openValue = compositeData.get(propertyName);
    else {
        String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
        if (compositeData.containsKey(decap))
            openValue = compositeData.get(decap);
        else {
            final String msg = "No CompositeData item " + propertyName + (decap.equals(propertyName) ? "" : " or " + decap) + " to match " + methodName;
            throw new IllegalArgumentException(msg);
        }
    }
    MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(), MXBeanMappingFactory.DEFAULT);
    return mapping.fromOpenValue(openValue);
}
Also used : MXBeanMapping(com.sun.jmx.mbeanserver.MXBeanMapping)

Example 3 with MXBeanMapping

use of com.sun.jmx.mbeanserver.MXBeanMapping in project spf4j by zolyfarkas.

the class DefaultMXBeanMappingFactoryOpenTypeMapper method getMXBeanMappingInternal.

/**
 * returns MXBeanMapping or null if type is not mappable to a OpenType.
 */
@Nullable
private synchronized JMXBeanMapping getMXBeanMappingInternal(final Type type) throws NotSerializableException {
    try {
        MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(type, new MXBeanMappingFactory() {

            @Override
            public MXBeanMapping mappingForType(final Type t, final MXBeanMappingFactory f) throws OpenDataException {
                try {
                    return MXBeanMappings.convert(appenderMap.get(t).get(t));
                } catch (NotSerializableException ex) {
                    OpenDataException tex = new OpenDataException(t + " is not serializable");
                    tex.initCause(ex);
                    throw tex;
                }
            }
        });
        return MXBeanMappings.convert(mapping);
    } catch (OpenDataException ex) {
        return null;
    }
}
Also used : Type(java.lang.reflect.Type) NotSerializableException(java.io.NotSerializableException) MXBeanMappingFactory(com.sun.jmx.mbeanserver.MXBeanMappingFactory) OpenDataException(javax.management.openmbean.OpenDataException) MXBeanMapping(com.sun.jmx.mbeanserver.MXBeanMapping) JMXBeanMapping(org.spf4j.jmx.JMXBeanMapping) Nullable(javax.annotation.Nullable)

Aggregations

MXBeanMapping (com.sun.jmx.mbeanserver.MXBeanMapping)3 MXBeanMappingFactory (com.sun.jmx.mbeanserver.MXBeanMappingFactory)2 NotSerializableException (java.io.NotSerializableException)2 Type (java.lang.reflect.Type)2 OpenDataException (javax.management.openmbean.OpenDataException)2 JMXBeanMapping (org.spf4j.jmx.JMXBeanMapping)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Nullable (javax.annotation.Nullable)1 ArrayType (javax.management.openmbean.ArrayType)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenType (javax.management.openmbean.OpenType)1 TabularType (javax.management.openmbean.TabularType)1