Search in sources :

Example 1 with PrivateClassLoader

use of javax.management.loading.PrivateClassLoader in project felix by apache.

the class MX4JMBeanServer method unregisterMBean.

public void unregisterMBean(ObjectName objectName) throws InstanceNotFoundException, MBeanRegistrationException {
    objectName = secureObjectName(objectName);
    if (objectName == null || objectName.isPattern()) {
        throw new RuntimeOperationsException(new IllegalArgumentException("ObjectName cannot be null or a pattern ObjectName"));
    }
    if (objectName.getDomain().equals("JMImplementation")) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Domain 'JMImplementation' is reserved for the JMX Agent"));
    }
    MBeanMetaData metadata = findMBeanMetaData(objectName);
    try {
        MBeanServerInterceptor head = getHeadInterceptor();
        head.registration(metadata, MBeanServerInterceptor.PRE_DEREGISTER);
        unregister(metadata);
        getHeadInterceptor().registration(metadata, MBeanServerInterceptor.POST_DEREGISTER);
        if (metadata.mbean instanceof ClassLoader && !(metadata.mbean instanceof PrivateClassLoader)) {
            getModifiableClassLoaderRepository().removeClassLoader((ClassLoader) metadata.mbean);
        }
    } catch (MBeanRegistrationException x) {
        throw x;
    } catch (SecurityException x) {
        throw x;
    } catch (Exception x) {
        throw new MBeanRegistrationException(x);
    } catch (Error x) {
        throw new MBeanRegistrationException(new RuntimeErrorException(x));
    }
}
Also used : MBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.MBeanServerInterceptor) InvokerMBeanServerInterceptor(org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.InvokerMBeanServerInterceptor) RuntimeErrorException(javax.management.RuntimeErrorException) PrivateClassLoader(javax.management.loading.PrivateClassLoader) PrivateClassLoader(javax.management.loading.PrivateClassLoader) MBeanRegistrationException(javax.management.MBeanRegistrationException) 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) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with PrivateClassLoader

use of javax.management.loading.PrivateClassLoader 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)

Aggregations

IOException (java.io.IOException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 AttributeNotFoundException (javax.management.AttributeNotFoundException)2 BadAttributeValueExpException (javax.management.BadAttributeValueExpException)2 BadBinaryOpValueExpException (javax.management.BadBinaryOpValueExpException)2 BadStringOperationException (javax.management.BadStringOperationException)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 IntrospectionException (javax.management.IntrospectionException)2 InvalidApplicationException (javax.management.InvalidApplicationException)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 JMRuntimeException (javax.management.JMRuntimeException)2 ListenerNotFoundException (javax.management.ListenerNotFoundException)2 MBeanException (javax.management.MBeanException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 OperationsException (javax.management.OperationsException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeErrorException (javax.management.RuntimeErrorException)2