accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject svn commit: r1477380 - in /accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs: AccumuloReloadingVFSClassLoader.java AccumuloVFSClassLoader.java
Date Mon, 29 Apr 2013 22:18:02 GMT
Author: vines
Date: Mon Apr 29 22:18:02 2013
New Revision: 1477380

URL: http://svn.apache.org/r1477380
Log:
ACCUMULO-1321 - temporary fix. This will create a new vfs classloader in place, but it leaves
cruft


Modified:
    accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoader.java
    accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java

Modified: accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoader.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoader.java?rev=1477380&r1=1477379&r2=1477380&view=diff
==============================================================================
--- accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoader.java
(original)
+++ accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoader.java
Mon Apr 29 22:18:02 2013
@@ -38,7 +38,7 @@ public class AccumuloReloadingVFSClassLo
   private static final Logger log = Logger.getLogger(AccumuloReloadingVFSClassLoader.class);
 
   /* 5 minute timeout */
-  private static final int DEFAULT_TIMEOUT = 300000;
+  private static final int DEFAULT_TIMEOUT = 1000;
   
   private String uris;
   private FileObject[] files;
@@ -47,13 +47,28 @@ public class AccumuloReloadingVFSClassLo
   private DefaultFileMonitor monitor = null;
   private VFSClassLoader cl = null;
   private boolean preDelegate;
+  public String stringify(FileObject[] files) {
+    StringBuilder sb = new StringBuilder();
+    sb.append('[');
+    String delim = "";
+    for (FileObject file : files) {
+      sb.append(delim);
+      delim = ", ";
+      sb.append(file.getName());
+    }
+    sb.append(']');
+    return sb.toString();
+  }
 
   @Override
   public synchronized ClassLoader getClassLoader() {
     if (cl == null || cl.getParent() != parent.getClassLoader()) {
       try {
+        vfs = AccumuloVFSClassLoader.generateVfs(true);
         files = AccumuloVFSClassLoader.resolve(vfs, uris);
-        
+
+        log.debug("Rebuilding dynamic classloader using files- " + stringify(files));
+
         if (preDelegate)
           cl = new VFSClassLoader(files, vfs, parent.getClassLoader());
         else

Modified: accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java?rev=1477380&r1=1477379&r2=1477380&view=diff
==============================================================================
--- accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
(original)
+++ accumulo/branches/1.5/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
Mon Apr 29 22:18:02 2013
@@ -59,12 +59,12 @@ import org.apache.log4j.Logger;
 public class AccumuloVFSClassLoader {
   
   public static class AccumuloVFSClassLoaderShutdownThread implements Runnable {
-
+    
     public void run() {
       try {
-	AccumuloVFSClassLoader.close();
+        AccumuloVFSClassLoader.close();
       } catch (Exception e) {
-	  //do nothing, we are shutting down anyway
+        // do nothing, we are shutting down anyway
       }
     }
     
@@ -73,7 +73,7 @@ public class AccumuloVFSClassLoader {
   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.";
@@ -84,14 +84,14 @@ public class AccumuloVFSClassLoader {
   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()));
     
+    Runtime.getRuntime().addShutdownHook(new Thread(new AccumuloVFSClassLoaderShutdownThread()));
   }
   
   public synchronized static <U> Class<? extends U> loadClass(String classname,
Class<U> extension) throws ClassNotFoundException {
@@ -105,28 +105,28 @@ public class AccumuloVFSClassLoader {
   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()) {
@@ -161,10 +161,10 @@ public class AccumuloVFSClassLoader {
       }
       
     }
-
+    
     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);
     
@@ -181,14 +181,14 @@ public class AccumuloVFSClassLoader {
         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, vfs, wrapper, 1000, true);
   }
-
+  
   public static ClassLoader getClassLoader() throws IOException {
     ReloadingClassLoader localLoader = loader;
     while (null == localLoader) {
@@ -196,47 +196,7 @@ public class AccumuloVFSClassLoader {
         if (null == loader) {
           
           if (null == vfs) {
-            vfs = new DefaultFileSystemManager();
-            vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
-            vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
-            vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
-            vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
-            vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
-            vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
-            vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
-            vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
-            vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
-            vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
-            vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
-            vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
-            vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
-            vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
-            vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
-            vfs.addProvider("hdfs", new HdfsFileProvider());
-            vfs.addExtensionMap("jar", "jar");
-            vfs.addExtensionMap("zip", "zip");
-            vfs.addExtensionMap("gz", "gz");
-            vfs.addExtensionMap("tar", "tar");
-            vfs.addExtensionMap("tbz2", "tar");
-            vfs.addExtensionMap("tgz", "tar");
-            vfs.addExtensionMap("bz2", "bz2");
-            vfs.addMimeTypeMap("application/x-tar", "tar");
-            vfs.addMimeTypeMap("application/x-gzip", "gz");
-            vfs.addMimeTypeMap("application/zip", "zip");
-            vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
-            vfs.setFilesCache(new SoftRefFilesCache());
-            String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, "");
-            File cacheDir = new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-"
+ System.getProperty("user.name", "nouser"));
-            if (!("".equals(cacheDirPath)))
-              cacheDir = new File(cacheDirPath);
-            vfs.setReplicator(new DefaultFileReplicator(cacheDir));
-            vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
-            vfs.init();
+            vfs = generateVfs(false);
           }
           
           // Set up the 2nd tier class loader
@@ -252,15 +212,61 @@ public class AccumuloVFSClassLoader {
             return localLoader.getClassLoader();
           }
           
-          //Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT
-          localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, vfs, parent));
+          // Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT
+          localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, generateVfs(true),
parent));
           loader = localLoader;
         }
       }
     }
-
+    
     return localLoader.getClassLoader();
   }
+  
+  public static DefaultFileSystemManager generateVfs(boolean reloading) throws FileSystemException
{
+    DefaultFileSystemManager vfs = new DefaultFileSystemManager();
+    vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
+    vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
+    vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
+    vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
+    vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
+    vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
+    vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
+    vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
+    vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
+    vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
+    vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
+    vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
+    vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
+    vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
+    vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
+    vfs.addProvider("hdfs", new HdfsFileProvider());
+    vfs.addExtensionMap("jar", "jar");
+    vfs.addExtensionMap("zip", "zip");
+    vfs.addExtensionMap("gz", "gz");
+    vfs.addExtensionMap("tar", "tar");
+    vfs.addExtensionMap("tbz2", "tar");
+    vfs.addExtensionMap("tgz", "tar");
+    vfs.addExtensionMap("bz2", "bz2");
+    vfs.addMimeTypeMap("application/x-tar", "tar");
+    vfs.addMimeTypeMap("application/x-gzip", "gz");
+    vfs.addMimeTypeMap("application/zip", "zip");
+    vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
+    vfs.setFilesCache(new SoftRefFilesCache());
+    String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, "");
+    File cacheDir = new File(System.getProperty("java.io.tmpdir"), (reloading? "accumulo-vfs-reloading-cache":"accumulo-vfs-cache-")
+ System.getProperty("user.name", "nouser"));
+    if (!("".equals(cacheDirPath)))
+      cacheDir = new File(cacheDirPath);
+    vfs.setReplicator(new DefaultFileReplicator(cacheDir));
+    vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
+    vfs.init();
+    return vfs;
+  }
+  
   public interface Printer {
     void print(String s);
   }
@@ -268,11 +274,12 @@ public class AccumuloVFSClassLoader {
   public static void printClassPath() {
     printClassPath(new Printer() {
       @Override
-      public void print(String s) { 
+      public void print(String s) {
         System.out.println(s);
       }
     });
   }
+  
   public static void printClassPath(Printer out) {
     try {
       ClassLoader cl = getClassLoader();
@@ -296,11 +303,11 @@ public class AccumuloVFSClassLoader {
           // If VFS class loader enabled, but no contexts defined.
           URLClassLoader ucl = (URLClassLoader) classLoader;
           out.print("Level " + level + " URL classpath items are:");
-
-            for (URL u : ucl.getURLs()) {
-              out.print("\t" + u.toExternalForm());
-            }
-
+          
+          for (URL u : ucl.getURLs()) {
+            out.print("\t" + u.toExternalForm());
+          }
+          
         } else if (classLoader instanceof VFSClassLoader) {
           out.print("Level " + level + " VFS classpaths items are:");
           VFSClassLoader vcl = (VFSClassLoader) classLoader;
@@ -316,7 +323,6 @@ public class AccumuloVFSClassLoader {
       throw new RuntimeException(t);
     }
   }
-
   
   public static synchronized ContextManager getContextManager() throws IOException {
     if (contextManager == null) {
@@ -332,10 +338,10 @@ public class AccumuloVFSClassLoader {
         }
       });
     }
-
+    
     return contextManager;
   }
-
+  
   public static void close() {
     if (null != vfs)
       vfs.close();



Mime
View raw message