asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mb...@apache.org
Subject asterixdb git commit: Use Inverted ClassLoader For External Functions
Date Tue, 05 Jul 2016 06:40:02 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 9e3f9befa -> 7f30303c3


Use Inverted ClassLoader For External Functions

Invert normal classloader order for external functions, first attempting to load
classes from external library before parent (system) classpath.  Classes from the
bootclassloader will load normally.

Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/973
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/7f30303c
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/7f30303c
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/7f30303c

Branch: refs/heads/master
Commit: 7f30303c3c38a08078b8f085f3c183c881aac64d
Parents: 9e3f9be
Author: Michael Blow <mblow@apache.org>
Authored: Mon Jul 4 03:26:11 2016 -0400
Committer: Michael Blow <michael.blow@couchbase.com>
Committed: Mon Jul 4 23:39:14 2016 -0700

----------------------------------------------------------------------
 .../external/ExternalLibraryClassLoader.java    | 56 ++++++++++++++++++++
 .../app/external/ExternalLibraryUtils.java      |  4 +-
 2 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7f30303c/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
new file mode 100644
index 0000000..711ac6d
--- /dev/null
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.app.external;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+public class ExternalLibraryClassLoader extends URLClassLoader {
+
+    private static final ClassLoader bootClassLoader = new ClassLoader(null){};
+
+    public ExternalLibraryClassLoader(URL[] urls, ClassLoader parentClassLoader) {
+        super(urls, parentClassLoader);
+    }
+
+    @Override
+    protected Class<?> loadClass(String name, boolean resolveClass) throws ClassNotFoundException
{
+        synchronized (getClassLoadingLock(name)) {
+            Class<?> clazz = findLoadedClass(name);
+            if (clazz == null) {
+                try {
+                    clazz = bootClassLoader.loadClass(name);
+                } catch (ClassNotFoundException ex) {
+                    // this is expected path for non-bootclassloader classes
+                    try {
+                        clazz = findClass(name);
+                    } catch (ClassNotFoundException ex2) {
+                        // this is expected path for classes not defined in the external
library classpath,
+                        // finally we try our parent classloader
+                        clazz = getParent().loadClass(name);
+                    }
+                }
+            }
+            if (resolveClass) {
+                resolveClass(clazz);
+            }
+            return clazz;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7f30303c/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
index a5654bd..04aebf5 100755
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
@@ -21,7 +21,6 @@ package org.apache.asterix.app.external;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -379,8 +378,7 @@ public class ExternalLibraryUtils {
         }
 
         // create and return the class loader
-        ClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
-        return classLoader;
+        return new ExternalLibraryClassLoader(urls, parentClassLoader);
     }
 
     /**


Mime
View raw message