aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [1/3] aries-jax-rs-whiteboard git commit: Register services in order
Date Mon, 05 Jun 2017 15:35:27 GMT
Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master c34b36fce -> a012f18ef


Register services in order


Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/32396a87
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/32396a87
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/32396a87

Branch: refs/heads/master
Commit: 32396a87fd90de88f5472e0c21354ce5da5a246b
Parents: c34b36f
Author: Carlos Sierra <csierra@apache.org>
Authored: Wed Apr 5 18:44:39 2017 +0200
Committer: Carlos Sierra <csierra@apache.org>
Committed: Mon Jun 5 16:25:07 2017 +0200

----------------------------------------------------------------------
 .../internal/CXFJaxRsServiceRegistrator.java    | 35 ++++++++++++++------
 .../aries/jax/rs/whiteboard/internal/Utils.java | 10 +++---
 2 files changed, 31 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/32396a87/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
index dd91521..57e095a 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
@@ -19,9 +19,11 @@ package org.apache.aries.jax.rs.whiteboard.internal;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeSet;
 
 import javax.ws.rs.core.Application;
 import javax.ws.rs.ext.RuntimeDelegate;
@@ -47,7 +49,8 @@ public class CXFJaxRsServiceRegistrator {
     private final Map<String, Object> _properties;
     private final Collection<Object> _providers = new ArrayList<>();
     private Server _server;
-    private final Collection<ResourceInformation> _services = new ArrayList<>();
+    private final Collection<ResourceInformation<ServiceReference<?>>>
+        _services = new TreeSet<>(Comparator.reverseOrder());
 
     private static final String CXF_ENDPOINT_ADDRESS = "CXF_ENDPOINT_ADDRESS";
 
@@ -193,34 +196,46 @@ public class CXFJaxRsServiceRegistrator {
 
         String address = safeToString(_properties.get(CXF_ENDPOINT_ADDRESS));
 
-        if (address != null) {
-            jaxRsServerFactoryBean.setAddress(address);
-        }
+        jaxRsServerFactoryBean.setAddress(address);
 
         _server = jaxRsServerFactoryBean.create();
 
         _server.start();
     }
 
-    public static class ResourceInformation {
-        private final String prefixPath;
+    public static class ResourceInformation<T extends Comparable<? super T>>
+        implements Comparable<ResourceInformation<T>> {
+
+        private final String _prefixPath;
+        private final T _comparable;
         private final ResourceProvider _resourceProvider;
 
         public ResourceInformation(
-            String prefixPath, ResourceProvider resourceProvider) {
+            T comparable, String prefixPath,
+            ResourceProvider resourceProvider) {
 
-            this.prefixPath = prefixPath;
-            this._resourceProvider = resourceProvider;
+            _comparable = comparable;
+
+            _resourceProvider = resourceProvider;
         }
 
         public String getPrefixPath() {
-            return prefixPath;
+            return _prefixPath;
         }
 
         public ResourceProvider getResourceProvider() {
             return _resourceProvider;
         }
 
+        @Override
+        public int compareTo(ResourceInformation<T> resourceInformation) {
+            if (resourceInformation == null) {
+                return 1;
+            }
+
+            return _comparable.compareTo(resourceInformation._comparable);
+        }
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/32396a87/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
index 0951f6e..0836ac0 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
@@ -23,6 +23,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.message.Message;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceObjects;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.wiring.BundleWiring;
@@ -129,8 +130,9 @@ public class Utils {
 
         try {
             thread.setContextClassLoader(classLoader);
-            ResourceInformation resourceInformation = new ResourceInformation(
-                resourceBase, resourceProvider);
+            ResourceInformation<ServiceReference<?>> resourceInformation =
+                new ResourceInformation<>(
+                    serviceReference, resourceBase, resourceProvider);
             registrator.add(resourceInformation);
             return just(resourceInformation);
         }
@@ -139,8 +141,8 @@ public class Utils {
         }
     }
 
-    public static String safeToString(Object resourceBaseObject) {
-        return resourceBaseObject == null ? "" : resourceBaseObject.toString();
+    public static String safeToString(Object object) {
+        return object == null ? "" : object.toString();
     }
 
     public static <T> ResourceProvider getResourceProvider(


Mime
View raw message