synchronized ClassLoader getDelegateClassLoader()

in modules/vfs-class-loader/src/main/java/org/apache/accumulo/classloader/vfs/AccumuloVFSClassLoader.java [540:604]


  synchronized ClassLoader getDelegateClassLoader() {
    // We cannot create the VFS file system during VM initialization,
    // we have to perform some lazy initialization here due to the fact
    // that the logging libraries (and others) make use of the ServiceLoader
    // and call ClassLoader.getSystemClassLoader() which you can't do until
    // the VM is fully initialized.
    if (!isVMInitialized() || vfsInitializing) {
      return this.parent;
    } else if (!this.vfsInitialized) {
      this.vfsInitializing = true;
      printDebug("getDelegateClassLoader() initializing VFS.");
      initializeFileSystem();
      this.vfsInitialized = true;
      printDebug("getDelegateClassLoader() VFS initialized.");
    }
    if (null == this.cl) {
      try {
        if (!isSystemClassLoader()) {
          printDebug("Reloading enabled, creating monitor");
          fileMonitor = Optional.of(new Monitor(this));
        } else {
          printDebug("Reloading disabled as this is the java.system.class.loader");
        }
        printDebug("Creating initial delegate class loader");
        updateDelegateClassloader();
        if (isSystemClassLoader()) {
          // An HDFS FileSystem and Configuration object were created for each unique HDFS namespace
          // in the call to resolve above. The HDFS Client did us a favor and cached these objects
          // so that the next time someone calls FileSystem.get(uri), they get the cached object.
          // However, these objects were created not with the VFS classloader, but the
          // classloader above it. We need to override the classloader on the Configuration objects.
          // Ran into an issue were log recovery was being attempted and SequenceFile$Reader was
          // trying to instantiate the key class via WritableName.getClass(String, Configuration)
          printDebug("Setting ClassLoader on HDFS FileSystem objects");
          for (FileObject fo : this.files) {
            if (fo instanceof HdfsFileObject) {
              String uri = fo.getName().getRootURI();
              Configuration c = new Configuration(true);
              c.set(FileSystem.FS_DEFAULT_NAME_KEY, uri);
              try {
                FileSystem fs = FileSystem.get(c);
                fs.getConf().setClassLoader(cl);
              } catch (IOException e) {
                throw new RuntimeException("Error setting classloader on HDFS FileSystem object",
                    e);
              }
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Error creating initial delegate classloader", e);
      }
    }
    if (this.vfsInitializing) {
      this.vfsInitializing = false;
      printDebug(ClassPathPrinter.getClassPath(this, true));
    }
    try {
      updateLock.readLock().lock();
      return this.cl;
    } finally {
      updateLock.readLock().unlock();
    }
  }