Search in sources :

Example 1 with MXBeanMappingFactory

use of com.sun.jmx.mbeanserver.MXBeanMappingFactory 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 MXBeanMappingFactory

use of com.sun.jmx.mbeanserver.MXBeanMappingFactory 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)2 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