incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r881245 - in /sling/trunk: bundles/commons/classloader/ bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/ bundles/jcr/classlo...
Date Tue, 17 Nov 2009 11:12:48 GMT
Author: cziegeler
Date: Tue Nov 17 11:12:48 2009
New Revision: 881245

URL: http://svn.apache.org/viewvc?rev=881245&view=rev
Log:
SLING-1191 : Dynamic class loader providers are not reloaded when bundles are updated/installed
etc.
Add new release method to the dynamic class loader provider. This allows a provider to react
on bundle/class loader changes.

Modified:
    sling/trunk/bundles/commons/classloader/pom.xml
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
    sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java
    sling/trunk/bundles/jcr/classloader/pom.xml
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
    sling/trunk/contrib/commons/fsclassloader/pom.xml
    sling/trunk/contrib/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java

Modified: sling/trunk/bundles/commons/classloader/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/pom.xml?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/pom.xml (original)
+++ sling/trunk/bundles/commons/classloader/pom.xml Tue Nov 17 11:12:48 2009
@@ -24,12 +24,11 @@
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
         <version>7</version>
-        <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
     <artifactId>org.apache.sling.commons.classloader</artifactId>
     <packaging>bundle</packaging>
-    <version>1.0.1-SNAPSHOT</version>
+    <version>1.1.0-SNAPSHOT</version>
 
     <name>Apache Sling Dynamic Class Loader Support</name>
     <description>
@@ -58,7 +57,7 @@
                             org.apache.sling.commons.classloader.impl.Activator
                         </Bundle-Activator>
                         <Export-Package>
-                            org.apache.sling.commons.classloader;version=${pom.version}
+                            org.apache.sling.commons.classloader;version=1.1.0
                         </Export-Package>
                         <Private-Package>
                             org.apache.sling.commons.classloader.impl

Modified: sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
(original)
+++ sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/DynamicClassLoaderProvider.java
Tue Nov 17 11:12:48 2009
@@ -33,8 +33,22 @@
      * as one of its parent class loaders. This ensures that the returned
      * class loader has access to all dynamically loaded classes that
      * are not part of this class loader.
+     * When the class loader is not needed anymore, it is released by
+     * calling the {@link #release(ClassLoader)} method.
      * @param parent The parent class loader for this dynamic class loader.
      * @return The class loader.
+     * @see #release(ClassLoader)
      */
     ClassLoader getClassLoader(ClassLoader parent);
+
+    /**
+     * Release the provided class loader.
+     * When the class loader is not needed anymore, e.g. when the dynamic class
+     * loader is shutdown, it is released with this method.
+     * The implementation can use this hook to free any allocated resources etc.
+     * @param classLoader The class loader.
+     * @see #getClassLoader(ClassLoader)
+     * @since 2.0
+     */
+    void release(ClassLoader classLoader);
 }

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=881245&r1=881244&r2=881245&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
Tue Nov 17 11:12:48 2009
@@ -43,6 +43,9 @@
     /** The cached chain of class loaders. */
     private ClassLoader[] cache;
 
+    /** The cached chain of dynamic class loader providers. */
+    private DynamicClassLoaderProvider[] providerCache;
+
     /** Is this still active? */
     private volatile boolean active = true;
 
@@ -62,6 +65,7 @@
         super(ctx, DynamicClassLoaderProvider.class.getName(), null);
         this.pckAdminCL = new PackageAdminClassLoader(pckAdmin, parent, factory);
         this.cache = new ClassLoader[] {this.pckAdminCL};
+        this.providerCache = new DynamicClassLoaderProvider[0];
         this.open();
         this.facade = new ClassLoaderFacade(this);
     }
@@ -70,10 +74,13 @@
         if ( this.trackingCount < this.getTrackingCount() ) {
             final ServiceReference[] refs = this.getServiceReferences();
             final ClassLoader[] loaders;
+            final DynamicClassLoaderProvider[] providers;
             if ( refs == null || refs.length == 0 ) {
                 loaders = new ClassLoader[] {this.pckAdminCL};
+                providers = new DynamicClassLoaderProvider[0];
             } else {
                 loaders = new ClassLoader[1 + refs.length];
+                providers = new DynamicClassLoaderProvider[refs.length];
                 Arrays.sort(refs, ServiceReferenceComparator.INSTANCE);
                 int index = 0;
                 for(final ServiceReference ref : refs) {
@@ -85,18 +92,38 @@
                 }
                 loaders[index] = this.pckAdminCL;
             }
+            // release old class loaders
+            this.releaseProviders();
+
             // and now use new array
             this.cache = loaders;
+            this.providerCache = providers;
             this.trackingCount = this.getTrackingCount();
         }
     }
 
     /**
+     * Free used class loader providers
+     */
+    private void releaseProviders() {
+        if ( this.providerCache != null ) {
+            for(int i=0; i<this.providerCache.length; i++) {
+                if ( this.cache[i] != null ) {
+                    this.providerCache[i].release(this.cache[i]);
+                }
+            }
+        }
+    }
+
+    /**
      * Deactivate this service.
      */
     public void deactivate() {
+        this.releaseProviders();
         this.active = false;
         this.close();
+        this.providerCache = null;
+        this.cache = null;
     }
 
     /**

Modified: sling/trunk/bundles/jcr/classloader/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/pom.xml?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/pom.xml (original)
+++ sling/trunk/bundles/jcr/classloader/pom.xml Tue Nov 17 11:12:48 2009
@@ -23,7 +23,6 @@
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
         <version>7</version>
-        <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
     <artifactId>org.apache.sling.jcr.classloader</artifactId>
@@ -98,7 +97,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.classloader</artifactId>
-            <version>1.0.0</version>
+            <version>1.1.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
(original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
Tue Nov 17 11:12:48 2009
@@ -87,8 +87,6 @@
 
     private String[] classPath;
 
-    private RepositoryClassLoaderFacade facade;
-
     /** @scr.reference policy="dynamic" */
     private MimeTypeService mimeTypeService;
 
@@ -116,15 +114,20 @@
      * @see org.apache.sling.commons.classloader.DynamicClassLoaderProvider#getClassLoader(ClassLoader)
      */
     public ClassLoader getClassLoader(final ClassLoader parent) {
-        if ( this.facade == null ) {
-            this.facade = new RepositoryClassLoaderFacade(this, parent, this.getClassPaths());
-        }
-
-        return this.facade;
+        return new RepositoryClassLoaderFacade(this, parent, this.getClassPaths());
     }
 
+    /**
+     * @see org.apache.sling.commons.classloader.DynamicClassLoaderProvider#release(java.lang.ClassLoader)
+     */
+    public void release(ClassLoader classLoader) {
+        if ( classLoader instanceof RepositoryClassLoaderFacade ) {
+            ((RepositoryClassLoaderFacade)classLoader).destroy();
+        }
+    }
     //---------- SCR Integration ----------------------------------------------
 
+
     /**
      * @see org.apache.sling.commons.classloader.ClassLoaderWriter#delete(java.lang.String)
      */
@@ -415,10 +418,6 @@
      * @param componentContext
      */
     protected void deactivate(final ComponentContext componentContext) {
-        if ( this.facade != null) {
-            this.facade.destroy();
-            this.facade = null;
-        }
         if ( this.readSession != null ) {
             this.readSession.logout();
             this.readSession = null;

Modified: sling/trunk/contrib/commons/fsclassloader/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/fsclassloader/pom.xml?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/contrib/commons/fsclassloader/pom.xml (original)
+++ sling/trunk/contrib/commons/fsclassloader/pom.xml Tue Nov 17 11:12:48 2009
@@ -23,8 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>6</version>
-        <relativePath>../../../parent/pom.xml</relativePath>
+        <version>7</version>
     </parent>
 
     <artifactId>org.apache.sling.commons.fsclassloader</artifactId>
@@ -79,13 +78,17 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.classloader</artifactId>
-            <version>1.0.0</version>
+            <version>1.1.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>

Modified: sling/trunk/contrib/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java?rev=881245&r1=881244&r2=881245&view=diff
==============================================================================
--- sling/trunk/contrib/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
(original)
+++ sling/trunk/contrib/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
Tue Nov 17 11:12:48 2009
@@ -59,6 +59,13 @@
         }
     }
 
+    /**
+     * @see org.apache.sling.commons.classloader.DynamicClassLoaderProvider#release(java.lang.ClassLoader)
+     */
+    public void release(ClassLoader classLoader) {
+        // nothing to do here
+    }
+
     //---------- SCR Integration ----------------------------------------------
 
     /**



Mime
View raw message