예제 #1
0
  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);
    }
  }
예제 #2
0
  /**
   * Implements {@link MBeanServer#getClassLoader(ObjectName)}. Contrarily to JMX 1.2
   * specifications, this methods only works for ClassLoaders that are registered in the
   * ClassLoaderRepository. If you need a fully JMX 1.2 compatible MBeanServer use {@link
   * JdmkMBeanServerBuilder} to create one.
   *
   * @since Java DMK 5.1 (JMX 1.2)
   */
  public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {

    if (interceptor instanceof MBeanServerInterceptor) {
      return ((MBeanServerInterceptor) interceptor).getClassLoader(loaderName);
    }
    final ModifiableClassLoaderRepository loaders = instantiator.getClassLoaderRepository();
    final ClassLoader loader;
    synchronized (instantiator) {
      loader = loaders.getClassLoader(loaderName);
    }
    if (loader == null) {
      throw new InstanceNotFoundException(
          "The loader named " + loaderName + " is not registered in the MBeanServer");
    }
    return loader;
  }