incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r921031 - in /sling/trunk/bundles: commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java jcr/resource/pom.xml jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
Date Tue, 09 Mar 2010 18:17:28 GMT
Author: cziegeler
Date: Tue Mar  9 18:17:27 2010
New Revision: 921031

URL: http://svn.apache.org/viewvc?rev=921031&view=rev
Log:
Use new osgi util to order services based on their ranking

Modified:
    sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
    sling/trunk/bundles/jcr/resource/pom.xml
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java

Modified: sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java?rev=921031&r1=921030&r2=921031&view=diff
==============================================================================
--- sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
(original)
+++ sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
Tue Mar  9 18:17:27 2010
@@ -151,5 +151,6 @@ public class OsgiUtilTest extends TestCa
         map1.put(Constants.SERVICE_RANKING, "hello");
         assertEquals(-1, OsgiUtil.getComparableForServiceRanking(map1).compareTo(map2));
         assertEquals(1, OsgiUtil.getComparableForServiceRanking(map2).compareTo(map1));
+        assertEquals(1, OsgiUtil.getComparableForServiceRanking(map2).compareTo(OsgiUtil.getComparableForServiceRanking(map1)));
     }
 }

Modified: sling/trunk/bundles/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=921031&r1=921030&r2=921031&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/pom.xml (original)
+++ sling/trunk/bundles/jcr/resource/pom.xml Tue Mar  9 18:17:27 2010
@@ -163,6 +163,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.0.5-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.classloader</artifactId>
             <version>1.0.0</version>
             <scope>provided</scope>

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java?rev=921031&r1=921030&r2=921031&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
Tue Mar  9 18:17:27 2010
@@ -20,7 +20,6 @@ package org.apache.sling.jcr.resource.in
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -29,8 +28,7 @@ import javax.servlet.http.HttpServletReq
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceDecorator;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.apache.sling.commons.osgi.OsgiUtil;
 
 /**
  * Helper class to track the resource decorators and keep
@@ -79,29 +77,20 @@ public class ResourceDecoratorTracker {
         return this.resourceDecoratorsArray;
     }
 
-    protected void addResourceDecorator(final ServiceReference reference) {
-    }
-
     protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String,
Object> props) {
         synchronized (this.resourceDecorators) {
-            final Long id = (Long) props.get(Constants.SERVICE_ID);
-            long ranking = -1;
-            if (props.get(Constants.SERVICE_RANKING) != null) {
-                ranking = (Long) props.get(Constants.SERVICE_RANKING);
-            }
-            this.resourceDecorators.add(new ResourceDecoratorEntry(id, ranking, decorator));
-            Collections.sort(this.resourceDecorators, ResourceDecoratorEntry.COMPARATOR);
+            this.resourceDecorators.add(new ResourceDecoratorEntry(decorator, OsgiUtil.getComparableForServiceRanking(props)));
+            Collections.sort(this.resourceDecorators);
             updateResourceDecoratorsArray();
         }
     }
 
     protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String,
Object> props) {
         synchronized (this.resourceDecorators) {
-            final long id = (Long) props.get(Constants.SERVICE_ID);
             final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators.iterator();
             while (i.hasNext()) {
                 final ResourceDecoratorEntry current = i.next();
-                if (current.serviceId == id) {
+                if (current.decorator == decorator) {
                     i.remove();
                     break;
                 }
@@ -131,41 +120,20 @@ public class ResourceDecoratorTracker {
     /**
      * Internal class to keep track of the resource decorators.
      */
-    private static final class ResourceDecoratorEntry {
-
-        final long serviceId;
+    private static final class ResourceDecoratorEntry implements Comparable<ResourceDecoratorEntry>
{
 
-        final long ranking;
+        final Comparable<Object> comparable;
 
         final ResourceDecorator decorator;
 
-        public ResourceDecoratorEntry(final long id,
-               final long ranking,
-               final ResourceDecorator d) {
-            this.serviceId = id;
-            this.ranking = ranking;
+        public ResourceDecoratorEntry(final ResourceDecorator d,
+                final Comparable<Object> comparable) {
+            this.comparable = comparable;
             this.decorator = d;
         }
 
-        public static Comparator<ResourceDecoratorEntry> COMPARATOR =
-
-            new Comparator<ResourceDecoratorEntry>() {
-
-                public int compare(ResourceDecoratorEntry o1,
-                        ResourceDecoratorEntry o2) {
-                    if (o1.ranking < o2.ranking) {
-                        return 1;
-                    } else if (o1.ranking > o2.ranking) {
-                        return -1;
-                    } else {
-                        if (o1.serviceId < o2.serviceId) {
-                            return -1;
-                        } else if (o1.serviceId > o2.serviceId) {
-                            return 1;
-                        }
-                    }
-                    return 0;
-                }
-            };
+        public int compareTo(ResourceDecoratorEntry o) {
+            return comparable.compareTo(o.comparable);
+        }
     }
 }



Mime
View raw message