private void initialize(MBeanInstantiator instantiator, MetaData meta, String domain) { this.instantiator = instantiator; if (instantiator == null) throw new IllegalArgumentException("instantiator must not be null."); this.meta = (meta == null ? new MetaDataImpl(instantiator) : meta); this.secureClr = new SecureClassLoaderRepository(instantiator.getClassLoaderRepository()); if (domain != null) { interceptor = new DefaultMBeanInterceptor(this, domain); } else { interceptor = new DefaultMBeanInterceptor(this); } // Create the MBeanServer identification MBean try { MBeanServerDelegateObject = new MBeanServerDelegateImpl(new MBeanServerDelegate()); MBeanServerDelegateObjectName = new ObjectName(ServiceName.DELEGATE); interceptor.registerMBean(MBeanServerDelegateObject, MBeanServerDelegateObjectName); } catch (JMException e) { // This should never happen! final RuntimeException r = new RuntimeException("Unexpected JMException: " + e); Utils.initCause(r, e); throw r; } ClassLoader myLoader = this.getClass().getClassLoader(); final ModifiableClassLoaderRepository loaders = instantiator.getClassLoaderRepository(); if (loaders != null && myLoader != null) { loaders.addClassLoader(myLoader); } }
/** * Registers a pre-existing object as an MBean with the MBean server. If the object name given is * null, the MBean may automatically provide its own name by implementing the {@link * javax.management.MBeanRegistration MBeanRegistration} interface. The call returns an <CODE> * ObjectInstance</CODE> object representing the registered MBean. * * @param object The MBean to be registered as an MBean. * @param name The object name of the MBean. May be null. * @return The <CODE>ObjectInstance</CODE> for the MBean that has been registered. * @exception InstanceAlreadyExistsException The MBean is already under the control of the MBean * server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> (<CODE>MBeanRegistration * </CODE> interface) method of the MBean has thrown an exception. The MBean will not be * registered. * @exception NotCompliantMBeanException This object is not a JMX compliant MBean * @exception RuntimeOperationsException Wraps an <CODE>{@link java.lang.IllegalArgumentException} * </CODE>: The object passed in parameter is null or no object name is specified. */ public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { return interceptor.registerMBean(object, name); }