Search in sources :

Example 31 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project quasar by puniverse.

the class JMXForkJoinPoolMonitor method registerMBean.

protected void registerMBean() {
    try {
        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        final ObjectName mxbeanName = new ObjectName(mbeanName);
        mbs.registerMBean(this, mxbeanName);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        ex.printStackTrace();
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 32 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method registerDynamicMBean.

private ObjectInstance registerDynamicMBean(String classname, DynamicMBean mbean, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    name = nonDefaultDomain(name);
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "registerMBean", "ObjectName = " + name);
    }
    ObjectName logicalName = preRegister(mbean, server, name);
    // preRegister returned successfully, so from this point on we
    // must call postRegister(false) if there is any problem.
    boolean registered = false;
    boolean registerFailed = false;
    ResourceContext context = null;
    try {
        if (mbean instanceof DynamicMBean2) {
            try {
                ((DynamicMBean2) mbean).preRegister2(server, logicalName);
                // until we succeed
                registerFailed = true;
            } catch (Exception e) {
                if (e instanceof RuntimeException)
                    throw (RuntimeException) e;
                if (e instanceof InstanceAlreadyExistsException)
                    throw (InstanceAlreadyExistsException) e;
                throw new RuntimeException(e);
            }
        }
        if (logicalName != name && logicalName != null) {
            logicalName = ObjectName.getInstance(nonDefaultDomain(logicalName));
        }
        checkMBeanPermission(classname, null, logicalName, "registerMBean");
        if (logicalName == null) {
            final RuntimeException wrapped = new IllegalArgumentException("No object name specified");
            throw new RuntimeOperationsException(wrapped, "Exception occurred trying to register the MBean");
        }
        final Object resource = getResource(mbean);
        // Register the MBean with the repository.
        // Returns the resource context that was used.
        // The returned context does nothing for regular MBeans.
        // For ClassLoader MBeans the context makes it possible to register these
        // objects with the appropriate framework artifacts, such as
        // the CLR, from within the repository lock.
        // In case of success, we also need to call context.done() at the
        // end of this method.
        //
        context = registerWithRepository(resource, mbean, logicalName);
        registerFailed = false;
        registered = true;
    } finally {
        try {
            postRegister(logicalName, mbean, registered, registerFailed);
        } finally {
            if (registered && context != null)
                context.done();
        }
    }
    return new ObjectInstance(logicalName, classname);
}
Also used : JMRuntimeException(javax.management.JMRuntimeException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) NamedObject(com.sun.jmx.mbeanserver.NamedObject) IntrospectionException(javax.management.IntrospectionException) OperationsException(javax.management.OperationsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeMBeanException(javax.management.RuntimeMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) DynamicMBean2(com.sun.jmx.mbeanserver.DynamicMBean2) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 33 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class MBeanIntrospector method getPerInterface.

final PerInterface<M> getPerInterface(Class<?> mbeanInterface) throws NotCompliantMBeanException {
    PerInterfaceMap<M> map = getPerInterfaceMap();
    synchronized (map) {
        WeakReference<PerInterface<M>> wr = map.get(mbeanInterface);
        PerInterface<M> pi = (wr == null) ? null : wr.get();
        if (pi == null) {
            try {
                MBeanAnalyzer<M> analyzer = getAnalyzer(mbeanInterface);
                MBeanInfo mbeanInfo = makeInterfaceMBeanInfo(mbeanInterface, analyzer);
                pi = new PerInterface<M>(mbeanInterface, this, analyzer, mbeanInfo);
                wr = new WeakReference<PerInterface<M>>(pi);
                map.put(mbeanInterface, wr);
            } catch (Exception x) {
                throw Introspector.throwException(mbeanInterface, x);
            }
        }
        return pi;
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ReflectionException(javax.management.ReflectionException)

Example 34 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class MBeanAnalyzer method initMaps.

// Introspect the mbeanInterface and initialize this object's maps.
//
private void initMaps(Class<?> mbeanType, MBeanIntrospector<M> introspector) throws Exception {
    final List<Method> methods1 = introspector.getMethods(mbeanType);
    final List<Method> methods = eliminateCovariantMethods(methods1);
    /* Run through the methods to detect inconsistencies and to enable
           us to give getter and setter together to visitAttribute. */
    for (Method m : methods) {
        final String name = m.getName();
        final int nParams = m.getParameterTypes().length;
        final M cm = introspector.mFrom(m);
        String attrName = "";
        if (name.startsWith("get"))
            attrName = name.substring(3);
        else if (name.startsWith("is") && m.getReturnType() == boolean.class)
            attrName = name.substring(2);
        if (attrName.length() != 0 && nParams == 0 && m.getReturnType() != void.class) {
            // It's a getter
            // Check we don't have both isX and getX
            AttrMethods<M> am = attrMap.get(attrName);
            if (am == null)
                am = new AttrMethods<M>();
            else {
                if (am.getter != null) {
                    final String msg = "Attribute " + attrName + " has more than one getter";
                    throw new NotCompliantMBeanException(msg);
                }
            }
            am.getter = cm;
            attrMap.put(attrName, am);
        } else if (name.startsWith("set") && name.length() > 3 && nParams == 1 && m.getReturnType() == void.class) {
            // It's a setter
            attrName = name.substring(3);
            AttrMethods<M> am = attrMap.get(attrName);
            if (am == null)
                am = new AttrMethods<M>();
            else if (am.setter != null) {
                final String msg = "Attribute " + attrName + " has more than one setter";
                throw new NotCompliantMBeanException(msg);
            }
            am.setter = cm;
            attrMap.put(attrName, am);
        } else {
            // It's an operation
            List<M> cms = opMap.get(name);
            if (cms == null)
                cms = newList();
            cms.add(cm);
            opMap.put(name, cms);
        }
    }
    /* Check that getters and setters are consistent. */
    for (Map.Entry<String, AttrMethods<M>> entry : attrMap.entrySet()) {
        AttrMethods<M> am = entry.getValue();
        if (!introspector.consistent(am.getter, am.setter)) {
            final String msg = "Getter and setter for " + entry.getKey() + " have inconsistent types";
            throw new NotCompliantMBeanException(msg);
        }
    }
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) List(java.util.List) Method(java.lang.reflect.Method) Map(java.util.Map)

Example 35 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.

the class Introspector method checkCompliance.

public static void checkCompliance(Class<?> mbeanClass) throws NotCompliantMBeanException {
    //
    if (DynamicMBean.class.isAssignableFrom(mbeanClass))
        return;
    // Is Standard MBean?
    //
    final Exception mbeanException;
    try {
        getStandardMBeanInterface(mbeanClass);
        return;
    } catch (NotCompliantMBeanException e) {
        mbeanException = e;
    }
    // Is MXBean?
    //
    final Exception mxbeanException;
    try {
        getMXBeanInterface(mbeanClass);
        return;
    } catch (NotCompliantMBeanException e) {
        mxbeanException = e;
    }
    final String msg = "MBean class " + mbeanClass.getName() + " does not implement " + "DynamicMBean, and neither follows the Standard MBean conventions (" + mbeanException.toString() + ") nor the MXBean conventions (" + mxbeanException.toString() + ")";
    throw new NotCompliantMBeanException(msg);
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) AttributeNotFoundException(javax.management.AttributeNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

NotCompliantMBeanException (javax.management.NotCompliantMBeanException)58 ObjectName (javax.management.ObjectName)37 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)29 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 MBeanServer (javax.management.MBeanServer)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)24 StandardMBean (javax.management.StandardMBean)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 MBeanException (javax.management.MBeanException)5 ReflectionException (javax.management.ReflectionException)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Logger (org.apache.aries.jmx.Logger)4 RegistrableStandardEmitterMBean (org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean)4 IntrospectionException (javax.management.IntrospectionException)3 JMRuntimeException (javax.management.JMRuntimeException)3 ObjectInstance (javax.management.ObjectInstance)3 RuntimeOperationsException (javax.management.RuntimeOperationsException)3 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)3 IOException (java.io.IOException)2