use of org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.MBeanServerInterceptor 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));
}
}
use of org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor.MBeanServerInterceptor 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);
}
}
Aggregations