incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r921724 - in /sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl: Activator.java DynamicClassLoaderManagerFactory.java DynamicClassLoaderManagerImpl.java PackageAdminClassLoader.java
Date Thu, 11 Mar 2010 08:39:58 GMT
Author: cziegeler
Date: Thu Mar 11 08:39:58 2010
New Revision: 921724

URL: http://svn.apache.org/viewvc?rev=921724&view=rev
Log:
SLING-1435 :  After a NoClassDefError classes are still not found even if they have been installed
in the meantime with Java 6

Modified:
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/Activator.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerFactory.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/PackageAdminClassLoader.java

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/Activator.java?rev=921724&r1=921723&r2=921724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/Activator.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/Activator.java
Thu Mar 11 08:39:58 2010
@@ -108,17 +108,15 @@ public class Activator implements Synchr
      * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
      */
     public void bundleChanged(BundleEvent event) {
-        final long bundleId = event.getBundle().getBundleId();
-        boolean needsUpdate = this.service.isBundleUsed(bundleId);
-        if ( needsUpdate ) {
+        boolean reload = false;
+        if ( event.getType() == BundleEvent.RESOLVED ) {
+            reload = this.service.hasUnresolvedPackages(event.getBundle());
+        } else if ( this.service.isBundleUsed(event.getBundle().getBundleId()) ) {
+            reload = true;
+        }
+        if ( reload ) {
             this.unregisterManagerFactory();
             this.registerManagerFactory();
-        } else {
-            // if a new bundle has been added (=resolved), we should
-            // clear the negative cache (see SLING-1302)
-            if ( event.getType() == BundleEvent.RESOLVED ) {
-                this.service.clearNegativeCaches();
-            }
         }
     }
 }

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerFactory.java?rev=921724&r1=921723&r2=921724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerFactory.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerFactory.java
Thu Mar 11 08:39:58 2010
@@ -16,16 +16,15 @@
  */
 package org.apache.sling.commons.classloader.impl;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 
 /**
@@ -42,8 +41,7 @@ public class DynamicClassLoaderManagerFa
 
     private final Set<Long> usedBundles = Collections.synchronizedSet(new HashSet<Long>());
 
-    /** All created managers. */
-    private final List<DynamicClassLoaderManagerImpl> managers = new ArrayList<DynamicClassLoaderManagerImpl>();
+    private final Set<String> unresolvedPackages = Collections.synchronizedSet(new
HashSet<String>());
 
     /**
      * Create a new service instance
@@ -63,9 +61,6 @@ public class DynamicClassLoaderManagerFa
                              final ServiceRegistration registration) {
         final DynamicClassLoaderManagerImpl manager =  new DynamicClassLoaderManagerImpl(this.context,
                 this.pckAdmin, new BundleProxyClassLoader(bundle), this);
-        synchronized ( managers ) {
-            managers.add(manager);
-        }
         return manager;
     }
 
@@ -76,9 +71,6 @@ public class DynamicClassLoaderManagerFa
                              final ServiceRegistration registration,
                              final Object service) {
         if ( service != null ) {
-            synchronized ( managers ) {
-                managers.remove(service);
-            }
             ((DynamicClassLoaderManagerImpl)service).deactivate();
         }
     }
@@ -102,13 +94,30 @@ public class DynamicClassLoaderManagerFa
     }
 
     /**
-     * Clear the negative caches of all registered managers.
+     * Notify that a package is not found during class loading.
+     * @param pckName The package name.
      */
-    public void clearNegativeCaches() {
-        synchronized ( this.managers ) {
-            for(final DynamicClassLoaderManagerImpl manager : this.managers) {
-                manager.clearNegativeCache();
+    public void addUnresolvedPackage(final String pckName) {
+        this.unresolvedPackages.add(pckName);
+    }
+
+    /**
+     * Check if an exported package from the bundle has not been
+     * found during previous class loading attempts.
+     * @param bundle The bundle to check
+     * @return <code>true</code> if a package has not be found before
+     */
+    public boolean hasUnresolvedPackages(final Bundle bundle) {
+        if ( !this.unresolvedPackages.isEmpty() ) {
+            final ExportedPackage[] pcks = this.pckAdmin.getExportedPackages(bundle);
+            if ( pcks != null ) {
+                for(final ExportedPackage pck : pcks ) {
+                    if ( this.unresolvedPackages.contains(pck.getName()) ) {
+                        return true;
+                    }
+                }
             }
         }
+        return false;
     }
 }

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java?rev=921724&r1=921723&r2=921724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
Thu Mar 11 08:39:58 2010
@@ -70,13 +70,6 @@ public class DynamicClassLoaderManagerIm
         this.facade = new ClassLoaderFacade(this);
     }
 
-    /**
-     * Clear the negative cache
-     */
-    public void clearNegativeCache() {
-        this.pckAdminCL.clearNegativeCache();
-    }
-
     private synchronized void updateCache() {
         if ( this.trackingCount < this.getTrackingCount() ) {
             final ServiceReference[] refs = this.getServiceReferences();

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/PackageAdminClassLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/PackageAdminClassLoader.java?rev=921724&r1=921723&r2=921724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/PackageAdminClassLoader.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/PackageAdminClassLoader.java
Thu Mar 11 08:39:58 2010
@@ -61,13 +61,6 @@ class PackageAdminClassLoader extends Cl
     }
 
     /**
-     * Clear the negative cache.
-     */
-    public void clearNegativeCache() {
-        negativeClassCache.clear();
-    }
-
-    /**
      * Find the bundle for a given package.
      * @param pckName The package name.
      * @return The bundle or <code>null</code>
@@ -180,12 +173,14 @@ class PackageAdminClassLoader extends Cl
         try {
             clazz = super.loadClass(name, resolve);
         } catch (ClassNotFoundException cnfe) {
-            final Bundle bundle = this.findBundleForPackage(getPackageFromClassName(name));
+            final String pckName = getPackageFromClassName(name);
+            final Bundle bundle = this.findBundleForPackage(pckName);
             if ( bundle != null ) {
                 try {
                     clazz = bundle.loadClass(name);
                 } catch (ClassNotFoundException inner) {
                     negativeClassCache.add(name);
+                    this.factory.addUnresolvedPackage(pckName);
                     throw inner;
                 }
                 this.factory.addUsedBundle(bundle);
@@ -193,6 +188,8 @@ class PackageAdminClassLoader extends Cl
         }
         if ( clazz == null ) {
             negativeClassCache.add(name);
+            final String pckName = getPackageFromClassName(name);
+            this.factory.addUnresolvedPackage(pckName);
             throw new ClassNotFoundException("Class not found " + name);
         }
         this.classCache.put(name, clazz);



Mime
View raw message