sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1628219 - in /sling/trunk/contrib/extensions/superimposing/src: main/java/org/apache/sling/superimposing/ main/java/org/apache/sling/superimposing/impl/ test/java/org/apache/sling/superimposing/impl/
Date Mon, 29 Sep 2014 16:50:41 GMT
Author: sseifert
Date: Mon Sep 29 16:50:41 2014
New Revision: 1628219

URL: http://svn.apache.org/r1628219
Log:
SLING-1778 initial sling superimposing resource provider implementation

Modified:
    sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/SuperimposingManager.java
    sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
    sling/trunk/contrib/extensions/superimposing/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java

Modified: sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/SuperimposingManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/SuperimposingManager.java?rev=1628219&r1=1628218&r2=1628219&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/SuperimposingManager.java
(original)
+++ sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/SuperimposingManager.java
Mon Sep 29 16:50:41 2014
@@ -18,7 +18,7 @@
  */
 package org.apache.sling.superimposing;
 
-import java.util.Map;
+import java.util.Iterator;
 
 import org.apache.sling.superimposing.impl.SuperimposingResourceProviderImpl;
 
@@ -29,13 +29,15 @@ import org.apache.sling.superimposing.im
 public interface SuperimposingManager {
 
     /**
-     * @return true if superimposing mode is enabled
+     * @return true if superimposing mode is enabled.
      */
     boolean isEnabled();
 
     /**
-     * @return Immutable map with all superimposing resource providers currently registered
+     * @return Iterator with all superimposing resource providers currently registered.
+     *   Iterator is backed by a {@link java.util.concurrent.ConcurrentHashMap} and is safe
to access
+     *   even if superimposing resource providers are registered or unregistered at the same
time.
      */
-    Map<String, SuperimposingResourceProvider> getRegisteredProviders();
+    Iterator<SuperimposingResourceProvider> getRegisteredProviders();
 
 }

Modified: sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java?rev=1628219&r1=1628218&r2=1628219&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
(original)
+++ sling/trunk/contrib/extensions/superimposing/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
Mon Sep 29 16:50:41 2014
@@ -22,9 +22,9 @@ import static org.apache.sling.superimpo
 import static org.apache.sling.superimposing.SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -413,11 +413,13 @@ public class SuperimposingManagerImpl im
     }
 
     /**
-     * @return Immutable map with all superimposing resource providers currently registered
+     * @return Iterator with all superimposing resource providers currently registered.
+     *   Iterator is backed by a {@link java.util.concurrent.ConcurrentHashMap} and is safe
to access
+     *   even if superimposing resource providers are registered or unregistered at the same
time.
      */
-    public Map<String, SuperimposingResourceProvider> getRegisteredProviders() {
-        Map<String, SuperimposingResourceProvider> mapcopy = new HashMap<String,
SuperimposingResourceProvider>(superimposingProviders);
-        return Collections.unmodifiableMap(mapcopy);
+    @SuppressWarnings("unchecked")
+    public Iterator<SuperimposingResourceProvider> getRegisteredProviders() {
+        return IteratorUtils.unmodifiableIterator(superimposingProviders.values().iterator());
     }
 
     SuperimposingManagerImpl withResourceResolverFactory(ResourceResolverFactory resolverFactory)
{

Modified: sling/trunk/contrib/extensions/superimposing/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/superimposing/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java?rev=1628219&r1=1628218&r2=1628219&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/superimposing/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
(original)
+++ sling/trunk/contrib/extensions/superimposing/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
Mon Sep 29 16:50:41 2014
@@ -40,6 +40,7 @@ import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -217,6 +218,7 @@ public class SuperimposingManagerImplTes
         verifyZeroInteractions(bundleContext);
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void testFindAllSuperimposings() throws InterruptedException, LoginException,
RepositoryException {
         // prepare a query that returns one existing superimposed resource
@@ -231,9 +233,9 @@ public class SuperimposingManagerImplTes
         initialize(true);
 
         // ensure the superimposed resource is detected and registered
-        Map<String, SuperimposingResourceProvider> providers = underTest.getRegisteredProviders();
+        List<SuperimposingResourceProvider> providers = IteratorUtils.toList(underTest.getRegisteredProviders());
         assertEquals(1, providers.size());
-        SuperimposingResourceProvider provider = providers.values().iterator().next();
+        SuperimposingResourceProvider provider = providers.iterator().next();
         assertEquals(SUPERIMPOSED_PATH, provider.getRootPath());
         assertEquals(ORIGINAL_PATH, provider.getSourcePath());
         assertFalse(provider.isOverlayable());
@@ -300,6 +302,7 @@ public class SuperimposingManagerImplTes
         return eventIterator;
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void testSuperimposedResourceCreateUpdateRemove() throws InterruptedException,
LoginException, RepositoryException {
         initialize(true);
@@ -309,9 +312,9 @@ public class SuperimposingManagerImplTes
         underTest.onEvent(prepareNodeCreateEvent(superimposedResource));
 
         // ensure the superimposed resource is detected and registered
-        Map<String, SuperimposingResourceProvider> providers = underTest.getRegisteredProviders();
+        List<SuperimposingResourceProvider> providers = IteratorUtils.toList(underTest.getRegisteredProviders());
         assertEquals(1, providers.size());
-        SuperimposingResourceProvider provider = providers.values().iterator().next();
+        SuperimposingResourceProvider provider = providers.iterator().next();
         assertEquals(SUPERIMPOSED_PATH, provider.getRootPath());
         assertEquals(ORIGINAL_PATH, provider.getSourcePath());
         assertFalse(provider.isOverlayable());
@@ -322,9 +325,9 @@ public class SuperimposingManagerImplTes
         underTest.onEvent(prepareNodeChangeEvent(superimposedResource));
 
         // ensure the superimposed resource update is detected and a new provider instance
is registered
-        providers = underTest.getRegisteredProviders();
+        providers = IteratorUtils.toList(underTest.getRegisteredProviders());
         assertEquals(1, providers.size());
-        SuperimposingResourceProvider provider2 = providers.values().iterator().next();
+        SuperimposingResourceProvider provider2 = providers.iterator().next();
         assertEquals(SUPERIMPOSED_PATH, provider2.getRootPath());
         assertEquals("/other/path", provider2.getSourcePath());
         assertFalse(provider2.isOverlayable());
@@ -334,10 +337,11 @@ public class SuperimposingManagerImplTes
         underTest.onEvent(prepareNodeRemoveEvent(superimposedResource));
 
         // ensure provider is removed
-        providers = underTest.getRegisteredProviders();
+        providers = IteratorUtils.toList(underTest.getRegisteredProviders());
         assertEquals(0, providers.size());
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void testSuperimposedResourceCreateMove() throws InterruptedException, LoginException,
RepositoryException {
         when(componentContextProperties.get(SuperimposingManagerImpl.FINDALLQUERIES_PROPERTY)).thenReturn("syntax|query");
@@ -363,9 +367,9 @@ public class SuperimposingManagerImplTes
         underTest.onEvent(prepareNodeMoveEvent(superimposedResource, oldPath));
 
         // ensure the superimposed resource update is detected and a new provider instance
is registered
-        Map<String, SuperimposingResourceProvider> providers = underTest.getRegisteredProviders();
+        List<SuperimposingResourceProvider> providers = IteratorUtils.toList(underTest.getRegisteredProviders());
         assertEquals(1, providers.size());
-        SuperimposingResourceProvider provider = providers.values().iterator().next();
+        SuperimposingResourceProvider provider = providers.iterator().next();
         assertEquals("/new/path", provider.getRootPath());
         assertEquals(ORIGINAL_PATH, provider.getSourcePath());
         assertFalse(provider.isOverlayable());



Mime
View raw message