sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1733302 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/ main/java/org/apache/sling/resourceresolver/impl/providers/ test/java/org/apache/sling/resourceresolver/impl/providers/
Date Wed, 02 Mar 2016 14:33:51 GMT
Author: cziegeler
Date: Wed Mar  2 14:33:51 2016
New Revision: 1733302

URL: http://svn.apache.org/viewvc?rev=1733302&view=rev
Log:
SLING-5561 : Resource Resolver Factory should be deactivated before provider is removed

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTracker.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1733302&r1=1733301&r2=1733302&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
Wed Mar  2 14:33:51 2016
@@ -26,7 +26,6 @@ import java.util.Map;
 
 import org.apache.commons.collections.BidiMap;
 import org.apache.commons.collections.bidimap.TreeBidiMap;
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -488,8 +487,16 @@ public class ResourceResolverFactoryActi
                     new ChangeListener() {
 
                         @Override
-                        public void providerChanged(final String pid) {
-                            if (ArrayUtils.contains(requiredResourceProviders, pid)) {
+                        public void providerAdded() {
+                            if ( factoryRegistration == null ) {
+                                checkFactoryPreconditions();
+                            }
+
+                        }
+
+                        @Override
+                        public void providerRemoved(final String pid) {
+                            if ( factoryRegistration != null ) {
                                 checkFactoryPreconditions();
                             }
                         }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTracker.java?rev=1733302&r1=1733301&r2=1733302&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTracker.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTracker.java
Wed Mar  2 14:33:51 2016
@@ -66,7 +66,9 @@ public class ResourceProviderTracker imp
 
     public interface ChangeListener {
 
-        void providerChanged(String pid);
+        void providerAdded();
+
+        void providerRemoved(String pid);
     }
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -104,7 +106,7 @@ public class ResourceProviderTracker imp
                 final ServiceReference ref = (ServiceReference)service;
                 final ResourceProviderInfo info = infos.remove(ref);
                 if ( info != null ) {
-                    unregister(info);
+                    unregister(info, (String)ref.getProperty(Constants.SERVICE_PID));
                 }
             }
 
@@ -194,7 +196,7 @@ public class ResourceProviderTracker imp
      * Unregister a resource provider.
      * @param info The resource provider info.
      */
-    private void unregister(final ResourceProviderInfo info) {
+    private void unregister(final ResourceProviderInfo info, final String pid) {
         final boolean isInvalid;
         synchronized ( this.invalidProviders ) {
             isInvalid = this.invalidProviders.remove(info) != null;
@@ -207,16 +209,25 @@ public class ResourceProviderTracker imp
                 final List<ResourceProviderHandler> matchingHandlers = this.handlers.get(info.getPath());
                 if ( matchingHandlers != null ) {
                     boolean doActivateNext = false;
-                    if ( matchingHandlers.get(0).getInfo() == info ) {
+                    final ResourceProviderHandler firstHandler = matchingHandlers.get(0);
+                    if ( firstHandler.getInfo() == info ) {
                         doActivateNext = true;
-                        this.deactivate(matchingHandlers.get(0));
-                        events.add(new ProviderEvent(false, matchingHandlers.get(0).getInfo()));
+                        final ChangeListener cl = this.listener;
+                        if ( cl != null ) {
+                            cl.providerRemoved(pid);
+                        }
+                        this.deactivate(firstHandler);
+                        events.add(new ProviderEvent(false, firstHandler.getInfo()));
                     }
                     if (removeHandlerByInfo(info, matchingHandlers)) {
                         while (doActivateNext && !matchingHandlers.isEmpty()) {
                             if (this.activate(matchingHandlers.get(0))) {
                                 doActivateNext = false;
                                 events.add(new ProviderEvent(true, matchingHandlers.get(0).getInfo()));
+                                final ChangeListener cl = this.listener;
+                                if ( cl != null ) {
+                                    cl.providerAdded();
+                                }
                             } else {
                                 matchingHandlers.remove(0);
                             }
@@ -406,9 +417,6 @@ public class ResourceProviderTracker imp
                 for(final ProviderEvent e : events) {
                     postOSGiEvent(e);
                     postResourceProviderChange(e);
-                    if ( e.pid != null && listener != null ) {
-                        listener.providerChanged(e.pid);
-                    }
                 }
             }
         });

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java?rev=1733302&r1=1733301&r2=1733302&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java
Wed Mar  2 14:33:51 2016
@@ -45,7 +45,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.service.event.EventAdmin;
 
 public class ResourceProviderTrackerTest {
-    
+
     private ResourceProviderInfo rp2Info;
     private ResourceProviderTracker tracker;
     private Fixture fixture;
@@ -53,59 +53,59 @@ public class ResourceProviderTrackerTest
     @Before
     public void prepare() throws Exception {
         BundleContext bundleContext = MockOsgi.newBundleContext();
-        
+
         fixture = new Fixture(bundleContext);
-        
+
         EventAdmin eventAdmin = mock(EventAdmin.class);
-        
+
         @SuppressWarnings("unchecked")
         ResourceProvider<Object> rp = mock(ResourceProvider.class);
         @SuppressWarnings("unchecked")
         ResourceProvider<Object> rp2 = mock(ResourceProvider.class);
         @SuppressWarnings("unchecked")
         ResourceProvider<Object> rp3 = mock(ResourceProvider.class);
-        
+
         fixture.registerResourceProvider(rp, "/", AuthType.no);
         rp2Info = fixture.registerResourceProvider(rp2, "/path", AuthType.lazy);
         fixture.registerResourceProvider(rp3, "invalid", AuthType.no);
-        
+
         tracker = new ResourceProviderTracker();
-        
+
         tracker.setObservationReporterGenerator(new SimpleObservationReporterGenerator(new
NoDothingObservationReporter()));
         tracker.activate(bundleContext, eventAdmin, new DoNothingChangeListener());
     }
 
     @Test
     public void activate() {
-        
+
         // since the OSGi mocks are asynchronous we don't have to wait for the changes to
propagate
-        
+
         assertThat(tracker.getResourceProviderStorage().getAllHandlers().size(), equalTo(2));
-        
+
         fixture.unregisterResourceProvider(rp2Info);
-        
+
         assertThat(tracker.getResourceProviderStorage().getAllHandlers().size(), equalTo(1));
     }
 
     @Test
     public void deactivate() {
-        
+
         tracker.deactivate();
-        
+
         assertThat(tracker.getResourceProviderStorage().getAllHandlers(), hasSize(0));
     }
-    
+
     @Test
     public void fillDto() throws Exception {
-        
+
         RuntimeDTO dto = new RuntimeDTO();
-        
+
         tracker.fill(dto);
-        
+
         assertThat( dto.providers, arrayWithSize(2));
         assertThat( dto.failedProviders, arrayWithSize(1));
     }
-    
+
     static final class NoDothingObservationReporter implements ObservationReporter {
         @Override
         public void reportChanges(Iterable<ResourceChange> changes, boolean distribute)
{
@@ -116,7 +116,7 @@ public class ResourceProviderTrackerTest
             return Collections.emptyList();
         }
     }
-    
+
     static final class SimpleObservationReporterGenerator implements ObservationReporterGenerator
{
         private final ObservationReporter reporter;
 
@@ -134,11 +134,19 @@ public class ResourceProviderTrackerTest
             return reporter;
         }
     }
-    
+
     static final class DoNothingChangeListener implements ChangeListener {
+
+        @Override
+        public void providerAdded() {
+            // TODO Auto-generated method stub
+
+        }
+
         @Override
-        public void providerChanged(String pid) {
-            
+        public void providerRemoved(String pid) {
+            // TODO Auto-generated method stub
+
         }
     }
 }
\ No newline at end of file



Mime
View raw message