You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2017/06/19 15:34:11 UTC
[07/11] aries-jax-rs-whiteboard git commit: Register services in order
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/fcc6e291
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/fcc6e291
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/fcc6e291
Branch: refs/heads/master
Commit: fcc6e291574927f6839bdc7b4d417379dc0eb53c
Parents: e788939
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Apr 5 18:44:39 2017 +0200
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Jun 19 17:31:55 2017 +0200
----------------------------------------------------------------------
.../internal/CXFJaxRsServiceRegistrator.java | 41 ++++++++++++++------
.../aries/jax/rs/whiteboard/internal/Utils.java | 10 +++--
2 files changed, 35 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/fcc6e291/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..e1e6a25 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";
@@ -79,7 +82,8 @@ public class CXFJaxRsServiceRegistrator {
return properties;
}
- public void add(ResourceInformation resourceInformation) {
+ public void add(
+ ResourceInformation<ServiceReference<?>> resourceInformation) {
if (_closed) {
return;
}
@@ -111,7 +115,8 @@ public class CXFJaxRsServiceRegistrator {
_closed = true;
}
- public void remove(ResourceInformation resourceInformation) {
+ public void remove(
+ ResourceInformation<ServiceReference<?>> resourceInformation) {
if (_closed) {
return;
}
@@ -193,34 +198,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/fcc6e291/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(