incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r920882 - in /sling/trunk/bundles/commons/osgi/src: main/java/org/apache/sling/commons/osgi/OsgiUtil.java test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
Date Tue, 09 Mar 2010 14:08:28 GMT
Author: cziegeler
Date: Tue Mar  9 14:08:28 2010
New Revision: 920882

URL: http://svn.apache.org/viewvc?rev=920882&view=rev
Log:
SLING-1431 : Utility method to get the service ranking

Modified:
    sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
    sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java

Modified: sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java?rev=920882&r1=920881&r2=920882&view=diff
==============================================================================
--- sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
(original)
+++ sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
Tue Mar  9 14:08:28 2010
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventConstants;
@@ -290,4 +291,31 @@ public class OsgiUtil {
         return new Event(topic, table);
     }
 
+    /**
+     * Return the service ranking
+     * @param props A property map
+     * @return The service ranking.
+     * @since 2.0.6
+     */
+    public static int getServiceRanking(final Map<String, Object> props) {
+        int ranking = 0;
+        if ( props != null && props.get(Constants.SERVICE_RANKING) instanceof Integer)
{
+            ranking = (Integer)props.get(Constants.SERVICE_RANKING);
+        }
+        return ranking;
+    }
+
+    /**
+     * Return the service ranking
+     * @param ref The service reference.
+     * @return The service ranking.
+     * @since 2.0.6
+     */
+    public static int getServiceRanking(final ServiceReference ref) {
+        int ranking = 0;
+        if ( ref.getProperty(Constants.SERVICE_RANKING) instanceof Integer) {
+            ranking = (Integer)ref.getProperty(Constants.SERVICE_RANKING);
+        }
+        return ranking;
+    }
 }

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=920882&r1=920881&r2=920882&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 14:08:28 2010
@@ -19,12 +19,15 @@
 package org.apache.sling.commons.osgi;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import junit.framework.TestCase;
 
+import org.osgi.framework.Constants;
+
 public class OsgiUtilTest extends TestCase {
 
     @SuppressWarnings("deprecation")
@@ -129,4 +132,12 @@ public class OsgiUtilTest extends TestCa
             }
         }
     }
+
+    public void testRanking() {
+        assertEquals(0, OsgiUtil.getServiceRanking((Map<String, Object>)null));
+        final Map<String, Object> stringMap = Collections.singletonMap(Constants.SERVICE_RANKING,
(Object)"1");
+        assertEquals(0, OsgiUtil.getServiceRanking(stringMap));
+        final Map<String, Object> intMap = Collections.singletonMap(Constants.SERVICE_RANKING,
(Object)1);
+        assertEquals(1, OsgiUtil.getServiceRanking(intMap));
+    }
 }



Mime
View raw message