You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:24:26 UTC
[sling-org-apache-sling-commons-osgi] 22/29: SLING-1431 : Utility
method to get the service ranking
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.commons.osgi-2.0.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-osgi.git
commit 8a4075ec8e5d98f5f65f7af0eb87371f55f11b4b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Mar 9 14:08:28 2010 +0000
SLING-1431 : Utility method to get the service ranking
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi@920882 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/commons/osgi/OsgiUtil.java | 28 ++++++++++++++++++++++
.../apache/sling/commons/osgi/OsgiUtilTest.java | 11 +++++++++
2 files changed, 39 insertions(+)
diff --git a/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java b/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
index b7a5e06..d95c82f 100644
--- a/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
+++ b/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
@@ -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;
+ }
}
diff --git a/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java b/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
index f43fbfd..d1aa341 100644
--- a/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
+++ b/src/test/java/org/apache/sling/commons/osgi/OsgiUtilTest.java
@@ -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 TestCase {
}
}
}
+
+ 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));
+ }
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.