* @param defaultDomain The default domain to be used
* @throws SecurityException if access is not granted to create an MBeanServer instance
*/
public MX4JMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate)
{
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Creating MBeanServer instance...");
SecurityManager sm = System.getSecurityManager();
if (sm != null)
{
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Checking permission to create MBeanServer...");
sm.checkPermission(new MBeanServerPermission("newMBeanServer"));
}
if (defaultDomain == null) defaultDomain = "";
this.defaultDomain = defaultDomain;
if (delegate==null) throw new JMRuntimeException("Delegate can't be null");
this.delegate = delegate;
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("MBeanServer default domain is: '" + this.defaultDomain + "'");
mbeanRepository = createMBeanRepository();
classLoaderRepository = createClassLoaderRepository();
// JMX 1.2 requires the CLR to have as first entry the classloader of this class
classLoaderRepository.addClassLoader(getClass().getClassLoader());
introspector = new MBeanIntrospector();
// This is the official name of the delegate, it is used as a source for MBeanServerNotifications
try
{
delegateName = new ObjectName("JMImplementation", "type", "MBeanServerDelegate");
}
catch (MalformedObjectNameException ignored)
{
}
try
{
ObjectName invokerName = new ObjectName(MBeanServerInterceptorConfigurator.OBJECT_NAME);
invoker = new MBeanServerInterceptorConfigurator(this);
// ContextClassLoaderMBeanServerInterceptor ccl = new ContextClassLoaderMBeanServerInterceptor();
// NotificationListenerMBeanServerInterceptor notif = new NotificationListenerMBeanServerInterceptor();
// SecurityMBeanServerInterceptor sec = new SecurityMBeanServerInterceptor();
InvokerMBeanServerInterceptor inv = new InvokerMBeanServerInterceptor(outer==null ? this : outer);
// invoker.addPreInterceptor(ccl);
// invoker.addPreInterceptor(notif);
// invoker.addPostInterceptor(sec);
invoker.addPostInterceptor(inv);
invoker.start();
// The interceptor stack is in place, register the configurator and all interceptors
privilegedRegisterMBean(invoker, invokerName);
// ObjectName cclName = new ObjectName("JMImplementation", "interceptor", "contextclassloader");
// ObjectName notifName = new ObjectName("JMImplementation", "interceptor", "notificationwrapper");
// ObjectName secName = new ObjectName("JMImplementation", "interceptor", "security");
ObjectName invName = new ObjectName("JMImplementation", "interceptor", "invoker");
// privilegedRegisterMBean(ccl, cclName);
// privilegedRegisterMBean(notif, notifName);
// privilegedRegisterMBean(sec, secName);
privilegedRegisterMBean(inv, invName);
}
catch (Exception x)
{
logger.error("MBeanServerInterceptorConfigurator cannot be registered", x);
throw new ImplementationException();
}
// Now register the delegate
try
{
privilegedRegisterMBean(delegate, delegateName);
}
catch (Exception x)
{
logger.error("MBeanServerDelegate cannot be registered", x);
throw new ImplementationException(x.toString());
}
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("MBeanServer instance created successfully");
}