sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1763899 - in /sling/trunk/bundles/resourceresolver: ./ src/main/java/org/apache/sling/resourceresolver/impl/observation/
Date Sat, 08 Oct 2016 14:21:01 GMT
Author: cziegeler
Date: Sat Oct  8 14:21:01 2016
New Revision: 1763899

URL: http://svn.apache.org/viewvc?rev=1763899&view=rev
Log:
SLING-6123 : Pass additional information like the search path to the listeners

Modified:
    sling/trunk/bundles/resourceresolver/pom.xml
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/BasicObservationReporter.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerWhiteboard.java

Modified: sling/trunk/bundles/resourceresolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/pom.xml?rev=1763899&r1=1763898&r2=1763899&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/pom.xml (original)
+++ sling/trunk/bundles/resourceresolver/pom.xml Sat Oct  8 14:21:01 2016
@@ -100,10 +100,6 @@
     
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-        </dependency>
-        <dependency>
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
         </dependency>
@@ -118,7 +114,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.11.0</version>
+            <version>2.14.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/BasicObservationReporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/BasicObservationReporter.java?rev=1763899&r1=1763898&r2=1763899&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/BasicObservationReporter.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/BasicObservationReporter.java
Sat Oct  8 14:21:01 2016
@@ -45,11 +45,16 @@ public class BasicObservationReporter im
 
     private final Map<ListenerConfig, List<ResourceChangeListenerInfo>> listeners
= new HashMap<BasicObservationReporter.ListenerConfig, List<ResourceChangeListenerInfo>>();;
 
+    private final String[] searchPath;
+
     /**
      * Create a reporter listening for resource provider changes
      * @param infos The listeners map
      */
-    public BasicObservationReporter(final Collection<ResourceChangeListenerInfo> infos)
{
+    public BasicObservationReporter(
+            final String[] searchPath,
+            final Collection<ResourceChangeListenerInfo> infos) {
+        this.searchPath = searchPath;
         final Set<String> paths = new HashSet<String>();
         for(final ResourceChangeListenerInfo info : infos) {
             if ( !info.getProviderChangeTypes().isEmpty() ) {
@@ -69,8 +74,12 @@ public class BasicObservationReporter im
      * @param providerPath The mount point of the provider
      * @param excludePaths Excluded paths for that provider
      */
-    public BasicObservationReporter(final Collection<ResourceChangeListenerInfo> infos,
+    public BasicObservationReporter(
+            final String[] searchPath,
+            final Collection<ResourceChangeListenerInfo> infos,
             final Path providerPath, final PathSet excludePaths) {
+        this.searchPath = searchPath;
+
         final Map<String, ObserverConfig> configMap = new HashMap<String, ObserverConfig>();
         for(final ResourceChangeListenerInfo info : infos) {
             if ( !info.getResourceChangeTypes().isEmpty() ) {
@@ -138,12 +147,13 @@ public class BasicObservationReporter im
      * @return The filtered list.
      */
     private List<ResourceChange> filterChanges(final Iterable<ResourceChange>
changes, final ListenerConfig config) {
-        final List<ResourceChange> filtered = new ArrayList<ResourceChange>();
+        final ResourceChangeListImpl filtered = new ResourceChangeListImpl(this.searchPath);
         for (final ResourceChange c : changes) {
             if (matches(c, config)) {
                 filtered.add(c);
             }
         }
+        filtered.lock();
         return filtered;
     }
 

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerWhiteboard.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerWhiteboard.java?rev=1763899&r1=1763898&r2=1763899&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerWhiteboard.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerWhiteboard.java
Sat Oct  8 14:21:01 2016
@@ -45,41 +45,43 @@ public class ResourceChangeListenerWhite
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    private final Map<ServiceReference, ResourceChangeListenerInfo> listeners = new
ConcurrentHashMap<ServiceReference, ResourceChangeListenerInfo>();
+    private final Map<ServiceReference<ResourceChangeListener>, ResourceChangeListenerInfo>
listeners = new ConcurrentHashMap<>();
 
     private volatile ResourceProviderTracker resourceProviderTracker;
 
-    private volatile ServiceTracker tracker;
+    private volatile ServiceTracker<ResourceChangeListener, ServiceReference<ResourceChangeListener>>
tracker;
+
+    private volatile String[] searchPath;
 
     public void activate(final BundleContext bundleContext,
             final ResourceProviderTracker resourceProviderTracker,
-            final String[] searchPaths) {
+            final String[] searchPath) {
+        this.searchPath = searchPath;
         this.resourceProviderTracker = resourceProviderTracker;
         this.resourceProviderTracker.setObservationReporterGenerator(this);
-        this.tracker = new ServiceTracker(bundleContext,
-                ResourceChangeListener.class.getName(),
-                new ServiceTrackerCustomizer() {
+        this.tracker = new ServiceTracker<>(bundleContext,
+                ResourceChangeListener.class,
+                new ServiceTrackerCustomizer<ResourceChangeListener, ServiceReference<ResourceChangeListener>>()
{
 
             @Override
-            public void removedService(final ServiceReference reference, final Object service)
{
-                final ServiceReference ref = (ServiceReference)service;
-                final ResourceChangeListenerInfo info = listeners.remove(ref);
+            public void removedService(final ServiceReference<ResourceChangeListener>
reference, final ServiceReference<ResourceChangeListener> service) {
+                final ResourceChangeListenerInfo info = listeners.remove(reference);
                 if ( info != null ) {
                     updateProviderTracker();
                 }
             }
 
             @Override
-            public void modifiedService(final ServiceReference reference, final Object service)
{
+            public void modifiedService(final ServiceReference<ResourceChangeListener>
reference, final ServiceReference<ResourceChangeListener> service) {
                 removedService(reference, service);
                 addingService(reference);
             }
 
             @Override
-            public Object addingService(final ServiceReference reference) {
-                final ResourceChangeListenerInfo info = new ResourceChangeListenerInfo(reference,
searchPaths);
+            public ServiceReference<ResourceChangeListener> addingService(final ServiceReference<ResourceChangeListener>
reference) {
+                final ResourceChangeListenerInfo info = new ResourceChangeListenerInfo(reference,
searchPath);
                 if ( info.isValid() ) {
-                    final ResourceChangeListener listener = (ResourceChangeListener) bundleContext.getService(reference);
+                    final ResourceChangeListener listener = bundleContext.getService(reference);
                     if ( listener != null ) {
                         info.setListener(listener);
                         listeners.put(reference, info);
@@ -109,12 +111,12 @@ public class ResourceChangeListenerWhite
 
     @Override
     public ObservationReporter create(final Path path, final PathSet excludes) {
-        return new BasicObservationReporter(this.listeners.values(), path, excludes);
+        return new BasicObservationReporter(this.searchPath, this.listeners.values(), path,
excludes);
     }
 
     @Override
     public ObservationReporter createProviderReporter() {
-        return new BasicObservationReporter(this.listeners.values());
+        return new BasicObservationReporter(this.searchPath, this.listeners.values());
     }
 
     private static final ObservationReporter EMPTY_REPORTER = new ObservationReporter() {



Mime
View raw message