use of com.sun.jmx.mbeanserver.DynamicMBean2 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);
}
use of com.sun.jmx.mbeanserver.DynamicMBean2 in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getNotificationBroadcaster.
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) {
if (reqClass.isInstance(instance))
return reqClass.cast(instance);
if (instance instanceof DynamicMBean2)
instance = ((DynamicMBean2) instance).getResource();
if (reqClass.isInstance(instance))
return reqClass.cast(instance);
final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName());
final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName();
throw new RuntimeOperationsException(exc, msg);
}
Aggregations