You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by "Michael Blow (Code Review)" <do...@asterixdb.incubator.apache.org> on 2016/07/04 07:28:06 UTC

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Michael Blow has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/973

Change subject: Use Inverted ClassLoader For External Functions
......................................................................

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
---
A asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
2 files changed, 57 insertions(+), 3 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/73/973/1

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;
+        }
+    }
+}
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 @@
 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 @@
         }
 
         // create and return the class loader
-        ClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
-        return classLoader;
+        return new ExternalLibraryClassLoader(urls, parentClassLoader);
     }
 
     /**

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Jenkins (Code Review)" <do...@asterixdb.incubator.apache.org>.
Jenkins has posted comments on this change.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


Patch Set 1:

Integration Tests Started https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-integration-tests/18/

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: abdullah alamoudi <ba...@gmail.com>
Gerrit-HasComments: No

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Jenkins (Code Review)" <do...@asterixdb.incubator.apache.org>.
Jenkins has posted comments on this change.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


Patch Set 1:

Build Started https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-notopic/1801/

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-HasComments: No

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Michael Blow (Code Review)" <do...@asterixdb.incubator.apache.org>.
Michael Blow has posted comments on this change.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


Patch Set 1:

(2 comments)

https://asterix-gerrit.ics.uci.edu/#/c/973/1/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
File asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java:

Line 39:                 } catch (ClassNotFoundException ex) {
> CRITICAL SonarQube violation:
false-positive


Line 43:                     } catch (ClassNotFoundException ex2) {
> CRITICAL SonarQube violation:
false-positive


-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: abdullah alamoudi <ba...@gmail.com>
Gerrit-HasComments: Yes

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Till Westmann (Code Review)" <do...@asterixdb.incubator.apache.org>.
Till Westmann has posted comments on this change.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


Patch Set 1: Code-Review+2

Looks good to (but I haven't tested it).

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: abdullah alamoudi <ba...@gmail.com>
Gerrit-HasComments: No

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Michael Blow (Code Review)" <do...@asterixdb.incubator.apache.org>.
Michael Blow has submitted this change and it was merged.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


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 <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>
---
A asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryClassLoader.java
M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalLibraryUtils.java
2 files changed, 57 insertions(+), 3 deletions(-)

Approvals:
  Till Westmann: Looks good to me, approved
  Jenkins: Verified; Verified

Objections:
  Jenkins: Violations found



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;
+        }
+    }
+}
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 @@
 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 @@
         }
 
         // create and return the class loader
-        ClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
-        return classLoader;
+        return new ExternalLibraryClassLoader(urls, parentClassLoader);
     }
 
     /**

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 2
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: abdullah alamoudi <ba...@gmail.com>

Change in asterixdb[master]: Use Inverted ClassLoader For External Functions

Posted by "Jenkins (Code Review)" <do...@asterixdb.incubator.apache.org>.
Jenkins has posted comments on this change.

Change subject: Use Inverted ClassLoader For External Functions
......................................................................


Patch Set 1: Integration-Tests+1

Integration Tests Successful

https://asterix-jenkins.ics.uci.edu/job/asterix-gerrit-integration-tests/18/ : SUCCESS

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/973
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7c152efd62af41bdedcbffdd29cd1041a8237ca4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Jenkins <je...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mi...@couchbase.com>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: abdullah alamoudi <ba...@gmail.com>
Gerrit-HasComments: No