tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: dont try to be clever just be brutal with ear classloaders
Date Tue, 03 Feb 2015 10:06:27 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x b3099bfbc -> 2f6692bc3


dont try to be clever just be brutal with ear classloaders


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

Branch: refs/heads/tomee-1.7.x
Commit: 2f6692bc3577e360843bf0dc7024e55fdb284292
Parents: b3099bf
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Tue Feb 3 11:06:06 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Tue Feb 3 11:06:06 2015 +0100

----------------------------------------------------------------------
 .../util/classloader/URLClassLoaderFirst.java   |  6 +-
 .../catalina/LazyStopWebappClassLoader.java     | 62 ++++++++------------
 2 files changed, 29 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/2f6692bc/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
b/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
index c360b3d..b91c221 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
@@ -172,7 +172,11 @@ public class URLClassLoaderFirst extends URLClassLoader {
         return null;
     }
 
-    private Class<?> loadInternal(final String name, final boolean resolve) {
+    public Class<?> findAlreadyLoadedClass(final String name) {
+        return super.findLoadedClass(name);
+    }
+
+    public Class<?> loadInternal(final String name, final boolean resolve) {
         try {
             final Class<?> clazz = findClass(name);
             if (clazz != null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/2f6692bc/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
index 645b9f8..e8ffefe 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
@@ -23,13 +23,12 @@ import org.apache.openejb.OpenEJB;
 import org.apache.openejb.classloader.ClassLoaderConfigurer;
 import org.apache.openejb.classloader.WebAppEnricher;
 import org.apache.openejb.config.NewLoaderLogic;
+import org.apache.openejb.core.ParentClassLoaderFinder;
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
-import org.apache.openejb.util.URLs;
 import org.apache.openejb.util.classloader.URLClassLoaderFirst;
-import org.apache.openejb.core.ParentClassLoaderFinder;
 
 import java.io.File;
 import java.io.IOException;
@@ -107,7 +106,7 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
     }
 
     @Override
-    public Class<?> loadClass(final String name) throws ClassNotFoundException {
+    public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException
{
         if ("org.apache.openejb.hibernate.OpenEJBJtaPlatform".equals(name)
             || "org.apache.openejb.jpa.integration.hibernate.PrefixNamingStrategy".equals(name)
             || "org.apache.openejb.jpa.integration.eclipselink.PrefixSessionCustomizer".equals(name)
@@ -119,7 +118,7 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
                 j2seClassLoader = NoClassClassLoader.INSTANCE;
                 delegate = false;
                 try {
-                    return super.loadClass(name);
+                    return super.loadClass(name, resolve);
                 } finally {
                     setJavaseClassLoader(old);
                     setDelegate(originalDelegate);
@@ -132,15 +131,19 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
             try {
                 return OpenEJB.class.getClassLoader().loadClass(name); // we could use containerClassLoader
but this is server loader so cut it even more
             } catch (final ClassNotFoundException e) {
-                return super.loadClass(name);
+                synchronized (this) {
+                    return super.loadClass(name, resolve);
+                }
             } catch (final NoClassDefFoundError ncdfe) {
-                return super.loadClass(name);
+                synchronized (this) {
+                    return super.loadClass(name, resolve);
+                }
             }
         } else if (name.startsWith("javax.faces.") || name.startsWith("org.apache.webbeans.jsf."))
{
             synchronized (this) {
                 delegate = false;
                 try {
-                    return super.loadClass(name);
+                    return super.loadClass(name, resolve);
                 } finally {
                     setDelegate(originalDelegate);
                 }
@@ -151,51 +154,34 @@ public class LazyStopWebappClassLoader extends WebappClassLoader {
                 final boolean filter = filter(name);
                 filterTempCache.put(name, filter); // will be called again by super.loadClass()
so cache it
                 if (!filter) {
-                    if (isTheSame(name, getParent(), containerClassLoader, false, false))
{
-                        return loadWithDelegate(false, name);
-                    } else if (isTheSame(name, getParent(), this, true, originalDelegate))
{
-                        return loadWithDelegate(true, name);
+                    if (URLClassLoaderFirst.class.isInstance(getParent())) { // true
+                        final URLClassLoaderFirst urlClassLoaderFirst = URLClassLoaderFirst.class.cast(getParent());
+                        Class<?> c = urlClassLoaderFirst.findAlreadyLoadedClass(name);
+                        if (c != null) {
+                            return c;
+                        }
+                        c = urlClassLoaderFirst.loadInternal(name, resolve);
+                        if (c != null) {
+                            return c;
+                        }
                     }
+                    return loadWithDelegate(getResource(name.replace('.', '/') + CLASS_EXTENSION)
== null, resolve, name);
                 }
             }
-        }
-        synchronized (this) { // TODO: rework it to avoid it but not a big issue, see first
if of this method
-            return super.loadClass(name);
+            return super.loadClass(name, resolve);
         }
     }
 
-    private Class<?> loadWithDelegate(final boolean delegate, final String name) throws
ClassNotFoundException {
+    private Class<?> loadWithDelegate(final boolean delegate, final boolean resolve,
final String name) throws ClassNotFoundException {
         setDelegate(delegate);
         try {
-            return super.loadClass(name);
+            return super.loadClass(name, resolve);
         } finally {
             filterTempCache.remove(name); // no more needed since class is loaded, avoid
to waste mem
             setDelegate(originalDelegate);
         }
     }
 
-    // NOTE: valueIfExistingInBoth should be removed but we need to work really more to make
it a reality
-    private boolean isTheSame(final String name, final ClassLoader c1, final ClassLoader
c2, final Boolean valueIfExistingInBoth, final boolean defaultValue) {
-        final String resource = name.replace('.', '/') + CLASS_EXTENSION;
-
-        final URL u1 = c1.getResource(resource);
-        if (u1 == null) {
-            return defaultValue;
-        }
-        final URL u2 = c2.getResource(resource);
-        if (u2 == null) {
-            return defaultValue;
-        }
-        if (valueIfExistingInBoth != null) {
-            return valueIfExistingInBoth;
-        }
-        try {
-            return URLs.toFile(u2).getCanonicalPath().equalsIgnoreCase(URLs.toFile(u1).getCanonicalPath());
-        } catch (final IOException e) {
-            return defaultValue;
-        }
-    }
-
     @Override
     protected boolean filter(final String name) {
         if ("org.apache.tomee.mojarra.TomEEInjectionProvider".equals(name)) {


Mime
View raw message