accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject git commit: ACCUMULO-1514 Dynamic classloader now has same behavior as general classloader
Date Tue, 29 Oct 2013 17:20:31 GMT
Updated Branches:
  refs/heads/master 2e2ac78eb -> 2f5974ca6


ACCUMULO-1514 Dynamic classloader now has same behavior as general classloader

don't matter


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/2f5974ca
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/2f5974ca
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/2f5974ca

Branch: refs/heads/master
Commit: 2f5974ca62ac58b07a53e021652f4b80756dc07d
Parents: 2e2ac78
Author: John Vines <jvines@gmail.com>
Authored: Tue Oct 29 13:11:56 2013 -0400
Committer: John Vines <jvines@gmail.com>
Committed: Tue Oct 29 13:13:02 2013 -0400

----------------------------------------------------------------------
 .../classloader/vfs/AccumuloVFSClassLoader.java | 119 +++++++++----------
 1 file changed, 57 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f5974ca/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
index eb653bc..b1e829a 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
@@ -58,9 +58,9 @@ import org.apache.log4j.Logger;
  * 
  */
 public class AccumuloVFSClassLoader {
-  
+
   public static class AccumuloVFSClassLoaderShutdownThread implements Runnable {
-    
+
     public void run() {
       try {
         AccumuloVFSClassLoader.close();
@@ -68,35 +68,35 @@ public class AccumuloVFSClassLoader {
         // do nothing, we are shutting down anyway
       }
     }
-    
+
   }
-  
+
   private static List<WeakReference<DefaultFileSystemManager>> vfsInstances =
Collections
       .synchronizedList(new ArrayList<WeakReference<DefaultFileSystemManager>>());
-  
+
   public static final String DYNAMIC_CLASSPATH_PROPERTY_NAME = "general.dynamic.classpaths";
-  
+
   public static final String DEFAULT_DYNAMIC_CLASSPATH_VALUE = "$ACCUMULO_HOME/lib/ext/[^.].*.jar\n";
-  
+
   public static final String VFS_CLASSLOADER_SYSTEM_CLASSPATH_PROPERTY = "general.vfs.classpaths";
-  
+
   public static final String VFS_CONTEXT_CLASSPATH_PROPERTY = "general.vfs.context.classpath.";
-  
+
   public static final String VFS_CACHE_DIR = "general.vfs.cache.dir";
-  
+
   private static ClassLoader parent = null;
   private static volatile ReloadingClassLoader loader = null;
   private static final Object lock = new Object();
-  
+
   private static ContextManager contextManager;
-  
+
   private static Logger log = Logger.getLogger(AccumuloVFSClassLoader.class);
-  
+
   static {
     // Register the shutdown hook
     Runtime.getRuntime().addShutdownHook(new Thread(new AccumuloVFSClassLoaderShutdownThread()));
   }
-  
+
   public synchronized static <U> Class<? extends U> loadClass(String classname,
Class<U> extension) throws ClassNotFoundException {
     try {
       return (Class<? extends U>) getClassLoader().loadClass(classname).asSubclass(extension);
@@ -104,44 +104,39 @@ public class AccumuloVFSClassLoader {
       throw new ClassNotFoundException("IO Error loading class " + classname, e);
     }
   }
-  
+
   public static Class<?> loadClass(String classname) throws ClassNotFoundException
{
     return loadClass(classname, Object.class).asSubclass(Object.class);
   }
-  
+
   static FileObject[] resolve(FileSystemManager vfs, String uris) throws FileSystemException
{
     return resolve(vfs, uris, new ArrayList<FileObject>());
   }
-  
+
   static FileObject[] resolve(FileSystemManager vfs, String uris, ArrayList<FileObject>
pathsToMonitor) throws FileSystemException {
     if (uris == null)
       return new FileObject[0];
-    
+
     ArrayList<FileObject> classpath = new ArrayList<FileObject>();
-    
+
     pathsToMonitor.clear();
-    
+
     for (String path : uris.split(",")) {
-      
+
       path = path.trim();
-      
+
       if (path.equals(""))
         continue;
-      
+
       path = AccumuloClassLoader.replaceEnvVars(path, System.getenv());
-      
+
       FileObject fo = vfs.resolveFile(path);
-      
+
       switch (fo.getType()) {
         case FILE:
-          classpath.add(fo);
-          pathsToMonitor.add(fo);
-          break;
         case FOLDER:
+          classpath.add(fo);
           pathsToMonitor.add(fo);
-          for (FileObject child : fo.getChildren()) {
-            classpath.add(child);
-          }
           break;
         case IMAGINARY:
           // assume its a pattern
@@ -162,67 +157,67 @@ public class AccumuloVFSClassLoader {
           log.warn("ignoring classpath entry " + fo);
           break;
       }
-      
+
     }
-    
+
     return classpath.toArray(new FileObject[classpath.size()]);
   }
-  
+
   private static ReloadingClassLoader createDynamicClassloader(final ClassLoader parent)
throws FileSystemException, IOException {
     String dynamicCPath = AccumuloClassLoader.getAccumuloString(DYNAMIC_CLASSPATH_PROPERTY_NAME,
DEFAULT_DYNAMIC_CLASSPATH_VALUE);
-    
+
     String envJars = System.getenv("ACCUMULO_XTRAJARS");
     if (null != envJars && !envJars.equals(""))
       if (dynamicCPath != null && !dynamicCPath.equals(""))
         dynamicCPath = dynamicCPath + "," + envJars;
       else
         dynamicCPath = envJars;
-    
+
     ReloadingClassLoader wrapper = new ReloadingClassLoader() {
       @Override
       public ClassLoader getClassLoader() {
         return parent;
       }
     };
-    
+
     if (dynamicCPath == null || dynamicCPath.equals(""))
       return wrapper;
-    
+
     // TODO monitor time for lib/ext was 1 sec... should this be configurable? - ACCUMULO-1301
     return new AccumuloReloadingVFSClassLoader(dynamicCPath, generateVfs(), wrapper, 1000,
true);
   }
-  
+
   public static ClassLoader getClassLoader() throws IOException {
     ReloadingClassLoader localLoader = loader;
     while (null == localLoader) {
       synchronized (lock) {
         if (null == loader) {
-          
+
           FileSystemManager vfs = generateVfs();
-          
+
           // Set up the 2nd tier class loader
           if (null == parent) {
             parent = AccumuloClassLoader.getClassLoader();
           }
-          
+
           FileObject[] vfsCP = resolve(vfs, AccumuloClassLoader.getAccumuloString(VFS_CLASSLOADER_SYSTEM_CLASSPATH_PROPERTY,
""));
-          
+
           if (vfsCP.length == 0) {
             localLoader = createDynamicClassloader(parent);
             loader = localLoader;
             return localLoader.getClassLoader();
           }
-          
+
           // Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT
           localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, vfs, parent));
           loader = localLoader;
         }
       }
     }
-    
+
     return localLoader.getClassLoader();
   }
-  
+
   public static FileSystemManager generateVfs() throws FileSystemException {
     DefaultFileSystemManager vfs = new FinalCloseDefaultFileSystemManager();
     vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
@@ -268,11 +263,11 @@ public class AccumuloVFSClassLoader {
     vfsInstances.add(new WeakReference<DefaultFileSystemManager>(vfs));
     return vfs;
   }
-  
+
   public interface Printer {
     void print(String s);
   }
-  
+
   public static void printClassPath() {
     printClassPath(new Printer() {
       @Override
@@ -281,28 +276,28 @@ public class AccumuloVFSClassLoader {
       }
     });
   }
-  
+
   public static void printClassPath(Printer out) {
     try {
       ClassLoader cl = getClassLoader();
       ArrayList<ClassLoader> classloaders = new ArrayList<ClassLoader>();
-      
+
       while (cl != null) {
         classloaders.add(cl);
         cl = cl.getParent();
       }
-      
+
       Collections.reverse(classloaders);
-      
+
       int level = 0;
-      
+
       for (ClassLoader classLoader : classloaders) {
         if (level > 0)
           out.print("");
         level++;
-        
+
         String classLoaderDescription;
-        
+
         switch (level) {
           case 1:
             classLoaderDescription = level + ": Java System Classloader (loads Java system
resources)";
@@ -321,16 +316,16 @@ public class AccumuloVFSClassLoader {
                 + AccumuloVFSClassLoader.class.getName() + ")";
             break;
         }
-        
+
         if (classLoader instanceof URLClassLoader) {
           // If VFS class loader enabled, but no contexts defined.
           URLClassLoader ucl = (URLClassLoader) classLoader;
           out.print("Level " + classLoaderDescription + " URL classpath items are:");
-          
+
           for (URL u : ucl.getURLs()) {
             out.print("\t" + u.toExternalForm());
           }
-          
+
         } else if (classLoader instanceof VFSClassLoader) {
           out.print("Level " + classLoaderDescription + " VFS classpaths items are:");
           VFSClassLoader vcl = (VFSClassLoader) classLoader;
@@ -341,12 +336,12 @@ public class AccumuloVFSClassLoader {
           out.print("Unknown classloader configuration " + classLoader.getClass());
         }
       }
-      
+
     } catch (Throwable t) {
       throw new RuntimeException(t);
     }
   }
-  
+
   public static synchronized ContextManager getContextManager() throws IOException {
     if (contextManager == null) {
       getClassLoader();
@@ -361,10 +356,10 @@ public class AccumuloVFSClassLoader {
         }
       });
     }
-    
+
     return contextManager;
   }
-  
+
   public static void close() {
     for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) {
       DefaultFileSystemManager ref = vfsInstance.get();


Mime
View raw message