Search in sources :

Example 71 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project felix by apache.

the class MX4JMBeanServer method registerImpl.

private void registerImpl(MBeanMetaData metadata, boolean privileged) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    introspector.introspect(metadata);
    if (!introspector.isMBeanCompliant(metadata))
        throw new NotCompliantMBeanException("MBean is not compliant");
    MBeanServerInterceptor head = getHeadInterceptor();
    try {
        // With this call, the MBean implementor can replace the ObjectName with a subclass that is not secure, secure it again
        head.registration(metadata, MBeanServerInterceptor.PRE_REGISTER);
        metadata.name = secureObjectName(metadata.name);
        metadata.instance = new ObjectInstance(metadata.name, metadata.info.getClassName());
        register(metadata, privileged);
        head.registration(metadata, MBeanServerInterceptor.POST_REGISTER_TRUE);
    } catch (Throwable x) {
        try {
            head.registration(metadata, MBeanServerInterceptor.POST_REGISTER_FALSE);
        } catch (MBeanRegistrationException ignored) {
        /* Ignore this one to rethrow the other one */
        }
        if (x instanceof SecurityException) {
            throw (SecurityException) x;
        } else if (x instanceof InstanceAlreadyExistsException) {
            throw (InstanceAlreadyExistsException) x;
        } else if (x instanceof MBeanRegistrationException) {
            throw (MBeanRegistrationException) x;
        } else if (x instanceof RuntimeOperationsException) {
            throw (RuntimeOperationsException) x;
        } else if (x instanceof JMRuntimeException) {
            throw (JMRuntimeException) x;
        } else if (x instanceof Exception) {
            throw new MBeanRegistrationException((Exception) x);
        } else if (x instanceof Error) {
            throw new MBeanRegistrationException(new RuntimeErrorException((Error) x));
        } else {
            throw new ImplementationException();
        }
    }
    if (metadata.mbean instanceof ClassLoader && !(metadata.mbean instanceof PrivateClassLoader)) {
        ClassLoader cl = (ClassLoader) metadata.mbean;
        getModifiableClassLoaderRepository().addClassLoader(cl);
    }
}
Also used : RuntimeErrorException(javax.management.RuntimeErrorException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) ObjectInstance(javax.management.ObjectInstance) PrivateClassLoader(javax.management.loading.PrivateClassLoader) IntrospectionException(javax.management.IntrospectionException) OperationsException(javax.management.OperationsException) BadBinaryOpValueExpException(javax.management.BadBinaryOpValueExpException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) BadStringOperationException(javax.management.BadStringOperationException) ReflectionException(javax.management.ReflectionException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RuntimeErrorException(javax.management.RuntimeErrorException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) JMRuntimeException(javax.management.JMRuntimeException) PrivilegedActionException(java.security.PrivilegedActionException) BadAttributeValueExpException(javax.management.BadAttributeValueExpException) IOException(java.io.IOException) ImplementationException(org.apache.felix.mosgi.jmx.agent.mx4j.ImplementationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) InvalidApplicationException(javax.management.InvalidApplicationException) MBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.MBeanServerInterceptor) InvokerMBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.InvokerMBeanServerInterceptor) PrivateClassLoader(javax.management.loading.PrivateClassLoader) JMRuntimeException(javax.management.JMRuntimeException) MBeanRegistrationException(javax.management.MBeanRegistrationException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 72 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project scylla-jmx by scylladb.

the class APIMBean method checkRegistration.

/**
 * Helper method to add/remove dynamically created MBeans from a server
 * instance.
 *
 * @param server
 *            The {@link MBeanServer} to check
 * @param all
 *            All {@link ObjectName}s that should be bound
 * @param predicate
 *            {@link QueryExp} predicate to filter relevant object names.
 * @param generator
 *            {@link Function} to create a new MBean instance for a given
 *            {@link ObjectName}
 *
 * @return
 * @throws MalformedObjectNameException
 */
public static boolean checkRegistration(MBeanServer server, Set<ObjectName> all, final Predicate<ObjectName> predicate, Function<ObjectName, Object> generator) throws MalformedObjectNameException {
    Set<ObjectName> registered = queryNames(server, predicate);
    for (ObjectName name : registered) {
        if (!all.contains(name)) {
            try {
                server.unregisterMBean(name);
            } catch (MBeanRegistrationException | InstanceNotFoundException e) {
            }
        }
    }
    int added = 0;
    for (ObjectName name : all) {
        if (!registered.contains(name)) {
            try {
                server.registerMBean(generator.apply(name), name);
                added++;
            } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
            }
        }
    }
    return added > 0;
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 73 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project hadoop by apache.

the class SimulatedFSDataset method registerMBean.

/**
   * Register the FSDataset MBean using the name
   *        "hadoop:service=DataNode,name=FSDatasetState-<storageid>"
   *  We use storage id for MBean name since a minicluster within a single
   * Java VM may have multiple Simulated Datanodes.
   */
void registerMBean(final String storageId) {
    // We wrap to bypass standard mbean naming convetion.
    // This wraping can be removed in java 6 as it is more flexible in 
    // package naming for mbeans and their impl.
    StandardMBean bean;
    try {
        bean = new StandardMBean(this, FSDatasetMBean.class);
        mbeanName = MBeans.register("DataNode", "FSDatasetState-" + storageId, bean);
    } catch (NotCompliantMBeanException e) {
        DataNode.LOG.warn("Error registering FSDatasetState MBean", e);
    }
    DataNode.LOG.info("Registered FSDatasetState MBean");
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FSDatasetMBean(org.apache.hadoop.hdfs.server.datanode.metrics.FSDatasetMBean)

Example 74 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 75 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)

Aggregations

NotCompliantMBeanException (javax.management.NotCompliantMBeanException)106 ObjectName (javax.management.ObjectName)73 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)71 MBeanRegistrationException (javax.management.MBeanRegistrationException)71 MalformedObjectNameException (javax.management.MalformedObjectNameException)59 MBeanServer (javax.management.MBeanServer)39 InstanceNotFoundException (javax.management.InstanceNotFoundException)23 StandardMBean (javax.management.StandardMBean)20 MBeanException (javax.management.MBeanException)8 ReflectionException (javax.management.ReflectionException)8 IOException (java.io.IOException)7 ObjectInstance (javax.management.ObjectInstance)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 Logger (org.apache.aries.jmx.Logger)4 MalformedURLException (java.net.MalformedURLException)3 DynamicMBean (javax.management.DynamicMBean)3 IntrospectionException (javax.management.IntrospectionException)3 JMRuntimeException (javax.management.JMRuntimeException)3