This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.commons.classloader-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-classloader.git
commit e4bc6a3a7adf438188648edfdc3bfb8e4f5787d6 Author: Carsten Ziegeler <[email protected]> AuthorDate: Mon Oct 12 13:17:54 2009 +0000 SLING-1144 : Make sync variable volatile and use tracker count instead of keeping track of changes by using custom methods. git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/classloader@824327 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/DynamicClassLoaderManagerImpl.java | 59 ++++++++-------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java b/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java index 2388b5b..6dabeb1 100644 --- a/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java +++ b/src/main/java/org/apache/sling/commons/classloader/impl/DynamicClassLoaderManagerImpl.java @@ -25,7 +25,6 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; /** * This is the default implementation of the dynamic class loader @@ -33,7 +32,7 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; */ public class DynamicClassLoaderManagerImpl extends ServiceTracker - implements DynamicClassLoaderManager, ServiceTrackerCustomizer { + implements DynamicClassLoaderManager { /** The package admin class loader. */ private final PackageAdminClassLoader pckAdminCL; @@ -41,17 +40,14 @@ public class DynamicClassLoaderManagerImpl /** The dynamic class loader. */ private final ClassLoaderFacade facade; - /** The bundle context. */ - private final BundleContext context; - /** The cached chain of class loaders. */ private ClassLoader[] cache; - /** Needs the cache an update? */ - private boolean updateCache = false; + /** Is this still active? */ + private volatile boolean active = true; - /** Is this service still active? */ - private boolean active = true; + /** Tracking count */ + private volatile int trackingCount = -1; /** * Create a new service instance @@ -64,45 +60,34 @@ public class DynamicClassLoaderManagerImpl final ClassLoader parent, final DynamicClassLoaderManagerFactory factory) { super(ctx, DynamicClassLoaderProvider.class.getName(), null); - this.context = ctx; this.pckAdminCL = new PackageAdminClassLoader(pckAdmin, parent, factory); this.cache = new ClassLoader[] {this.pckAdminCL}; this.open(); this.facade = new ClassLoaderFacade(this); } - public Object addingService(ServiceReference reference) { - this.updateCache = true; - return this.context.getService(reference); - } - - public void modifiedService(ServiceReference reference, Object service) { - // as the ranking property has changed we have to update the cache - this.updateCache = true; - } - - public void removedService(ServiceReference reference, Object service) { - this.context.ungetService(reference); - this.updateCache = true; - } - private synchronized void updateCache() { - if ( this.updateCache ) { + if ( this.trackingCount < this.getTrackingCount() ) { final ServiceReference[] refs = this.getServiceReferences(); - final ClassLoader[] loaders = new ClassLoader[1 + refs.length]; - Arrays.sort(refs, ServiceReferenceComparator.INSTANCE); - int index = 0; - for(final ServiceReference ref : refs) { - final DynamicClassLoaderProvider provider = (DynamicClassLoaderProvider)this.getService(ref); - if ( provider != null ) { - loaders[index] = provider.getClassLoader(this.pckAdminCL); + final ClassLoader[] loaders; + if ( refs == null || refs.length == 0 ) { + loaders = new ClassLoader[] {this.pckAdminCL}; + } else { + loaders = new ClassLoader[1 + refs.length]; + Arrays.sort(refs, ServiceReferenceComparator.INSTANCE); + int index = 0; + for(final ServiceReference ref : refs) { + final DynamicClassLoaderProvider provider = (DynamicClassLoaderProvider)this.getService(ref); + if ( provider != null ) { + loaders[index] = provider.getClassLoader(this.pckAdminCL); + } + index++; } - index++; + loaders[index] = this.pckAdminCL; } - loaders[index] = this.pckAdminCL; // and now use new array this.cache = loaders; - this.updateCache = false; + this.trackingCount = this.getTrackingCount(); } } @@ -135,7 +120,7 @@ public class DynamicClassLoaderManagerImpl * @return The list of class loaders. */ public ClassLoader[] getDynamicClassLoaders() { - if ( this.updateCache ) { + if ( this.trackingCount < this.getTrackingCount() ) { updateCache(); } return this.cache; -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
