trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbirds...@apache.org
Subject [1/2] incubator-trafodion git commit: TRAFODION-2782 reserve UDRs classloader sequence
Date Thu, 26 Oct 2017 19:12:07 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master af54ea41f -> 371cb7110


TRAFODION-2782 reserve UDRs classloader sequence


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/9d05287f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/9d05287f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/9d05287f

Branch: refs/heads/master
Commit: 9d05287fbe3025a90eb479bf0ceda2b6428c8471
Parents: ea24774
Author: mashengchen <mashengchen@gmail.com>
Authored: Tue Oct 24 05:54:24 2017 +0000
Committer: mashengchen <mashengchen@gmail.com>
Committed: Tue Oct 24 05:54:24 2017 +0000

----------------------------------------------------------------------
 .../org/trafodion/sql/udr/LmClassLoader.java    | 54 ++++++++++++++++++--
 1 file changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/9d05287f/core/sql/src/main/java/org/trafodion/sql/udr/LmClassLoader.java
----------------------------------------------------------------------
diff --git a/core/sql/src/main/java/org/trafodion/sql/udr/LmClassLoader.java b/core/sql/src/main/java/org/trafodion/sql/udr/LmClassLoader.java
index 04ba64a..76102e6 100644
--- a/core/sql/src/main/java/org/trafodion/sql/udr/LmClassLoader.java
+++ b/core/sql/src/main/java/org/trafodion/sql/udr/LmClassLoader.java
@@ -63,10 +63,45 @@ import java.security.PrivilegedExceptionAction;
  *   order
  *
  **/
-public class LmClassLoader extends URLClassLoader
+public class LmClassLoader extends ClassLoader
 {
   private final static boolean DEBUG = false; // static DEBUG
 
+    private ChildURLClassLoader childClassLoader;
+
+    private static class FindClassClassLoader extends ClassLoader {
+        public FindClassClassLoader(ClassLoader parent) {
+            super(parent);
+        }
+
+        @Override
+        public Class<?> findClass(String name) throws ClassNotFoundException {
+            return super.findClass(name);
+        }
+    }
+
+    private static class ChildURLClassLoader extends URLClassLoader {
+        private FindClassClassLoader realParent;
+
+        
+        public ChildURLClassLoader(URL[] urls, FindClassClassLoader realParent) {
+            super(urls, null);
+
+            this.realParent = realParent;
+        }
+
+        @Override
+        public Class<?> findClass(String name) throws ClassNotFoundException {
+            try {
+                Class<?> loaded = super.findLoadedClass(name);
+                if (loaded != null)
+                    return loaded;
+                return super.findClass(name);
+            } catch (ClassNotFoundException e) {
+                return realParent.loadClass(name);
+            }
+        }
+    }
 
   /**
    * Creates a new instance for a given set of URLs.
@@ -77,13 +112,15 @@ public class LmClassLoader extends URLClassLoader
    **/
   public LmClassLoader(URL[] urls)
   {
-      super(urls);
+      //super(urls);
+      super(Thread.currentThread().getContextClassLoader());
+      childClassLoader = new ChildURLClassLoader(urls, new FindClassClassLoader(this.getParent()));
   }
 
   String getContainerPath()
   {
       // The first URL points to the container. Get the path of that URL
-      return getURLs()[0].getPath();
+      return childClassLoader.getURLs()[0].getPath();
   }
 
   /**
@@ -164,4 +201,15 @@ public class LmClassLoader extends URLClassLoader
         System.out.println("LmClassLoader::findResourceInternal did not find resource " +
name + "in container " + path);
     return null;
   }
+    @Override
+    protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
+        try {
+            Class<?> result = childClassLoader.findClass(name);
+            if (resolve)
+                resolveClass(result);
+            return result;
+        } catch (ClassNotFoundException e) {
+            return super.loadClass(name, resolve);
+        }
+    }
 }


Mime
View raw message