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/11/03 15:25:10 UTC
[11/11] aries-jax-rs-whiteboard git commit: Move to
CachingServiceReference
Move to CachingServiceReference
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/d825a6c4
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/d825a6c4
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/d825a6c4
Branch: refs/heads/master
Commit: d825a6c4311a6e1d8b908ef7f4d3dadbbbb321b3
Parents: bd57dd7
Author: Carlos Sierra <cs...@apache.org>
Authored: Wed Nov 1 12:22:18 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Fri Nov 3 16:18:24 2017 +0100
----------------------------------------------------------------------
.../internal/AriesJaxRSServiceRuntime.java | 102 ++++++++++---------
.../internal/CXFJaxRsServiceRegistrator.java | 8 +-
.../rs/whiteboard/internal/TargetFilter.java | 5 +-
.../aries/jax/rs/whiteboard/internal/Utils.java | 59 ++++++-----
.../jax/rs/whiteboard/internal/Whiteboard.java | 78 +++++++-------
5 files changed, 133 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d825a6c4/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java
index 12d8fb2..7d53b21 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java
@@ -18,7 +18,7 @@
package org.apache.aries.jax.rs.whiteboard.internal;
import org.apache.aries.jax.rs.whiteboard.internal.Utils.PropertyHolder;
-import org.osgi.framework.ServiceReference;
+import org.apache.aries.osgi.functional.CachingServiceReference;
import org.osgi.service.jaxrs.runtime.JaxRSServiceRuntime;
import org.osgi.service.jaxrs.runtime.dto.ApplicationDTO;
import org.osgi.service.jaxrs.runtime.dto.DTOConstants;
@@ -57,79 +57,81 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
Whiteboard.class);
private ConcurrentHashMap<String, Map<String, Object>>
_applications = new ConcurrentHashMap<>();
- private ConcurrentHashMap<String, Collection<ServiceReference<?>>>
+ private ConcurrentHashMap<String, Collection<CachingServiceReference<?>>>
_applicationEndpoints = new ConcurrentHashMap<>();
- private ConcurrentHashMap<String, Collection<ServiceReference<?>>>
+ private ConcurrentHashMap<String, Collection<CachingServiceReference<?>>>
_applicationExtensions = new ConcurrentHashMap<>();
- private Collection<ServiceReference<Application>>
+ private Collection<CachingServiceReference<Application>>
_ungettableApplications = new CopyOnWriteArrayList<>();
- private Collection<ServiceReference<Application>> _shadowedApplications =
+ private Collection<CachingServiceReference<Application>> _shadowedApplications =
new CopyOnWriteArrayList<>();
- private Set<ServiceReference<Application>> _dependentApplications =
+ private Set<CachingServiceReference<Application>> _dependentApplications =
ConcurrentHashMap.newKeySet();
- private Collection<ServiceReference<Application>> _clashingApplications =
+ private Collection<CachingServiceReference<Application>> _clashingApplications =
new CopyOnWriteArrayList<>();
- private Collection<ServiceReference<Application>> _erroredApplications =
+ private Collection<CachingServiceReference<Application>> _erroredApplications =
new CopyOnWriteArrayList<>();
- private Collection<ServiceReference<?>> _erroredEndpoints =
+ private Collection<CachingServiceReference<?>> _erroredEndpoints =
new CopyOnWriteArrayList<>();
- private Collection<ServiceReference<?>> _ungettableEndpoints =
+ private Collection<CachingServiceReference<?>> _ungettableEndpoints =
new CopyOnWriteArrayList<>();
- private Collection<ServiceReference<?>> _ungettableExtensions =
+ private Collection<CachingServiceReference<?>> _ungettableExtensions =
new CopyOnWriteArrayList<>();
- private Set<ServiceReference<?>> _dependentServices =
+ private Set<CachingServiceReference<?>> _dependentServices =
ConcurrentHashMap.newKeySet();
- private Collection<ServiceReference<?>> _invalidExtensions =
+ private Collection<CachingServiceReference<?>> _invalidExtensions =
new CopyOnWriteArrayList<>();
private volatile Map<String, Object> _defaultApplicationProperties;
public void addApplicationEndpoint(
- String applicationName, ServiceReference<?> endpointServiceReference) {
+ String applicationName, CachingServiceReference<?> endpointImmutableServiceReference) {
_applicationEndpoints.compute(
- applicationName, merger(endpointServiceReference));
+ applicationName, merger(endpointImmutableServiceReference));
}
public void addApplicationExtension(
String applicationName,
- ServiceReference<?> extensionServiceReference) {
+ CachingServiceReference<?> extensionImmutableServiceReference) {
_applicationExtensions.compute(
- applicationName, merger(extensionServiceReference));
+ applicationName, merger(extensionImmutableServiceReference));
}
public void addClashingApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
_clashingApplications.add(serviceReference);
}
public void addDependentApplication(
- ServiceReference<Application> applicationReference) {
+ CachingServiceReference<Application> applicationReference) {
_dependentApplications.add(applicationReference);
}
- public void addDependentService(ServiceReference<?> serviceReference) {
+ public void addDependentService(CachingServiceReference<?> serviceReference) {
_dependentServices.add(serviceReference);
}
public void addErroredApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
_erroredApplications.add(serviceReference);
}
- public <T> void addErroredEndpoint(ServiceReference<T> serviceReference) {
+ public <T> void addErroredEndpoint(CachingServiceReference<T> serviceReference) {
_erroredEndpoints.add(serviceReference);
}
- public void addInvalidExtension(ServiceReference<?> serviceReference) {
+ public void addInvalidExtension(
+ CachingServiceReference<?> serviceReference) {
+
_invalidExtensions.add(serviceReference);
}
public boolean addNotGettableApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
if (_LOGGER.isWarnEnabled()) {
_LOGGER.warn(
@@ -141,7 +143,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
public <T> boolean addNotGettableEndpoint(
- ServiceReference<T> serviceReference) {
+ CachingServiceReference<T> serviceReference) {
if (_LOGGER.isWarnEnabled()) {
_LOGGER.warn(
@@ -153,7 +155,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
public <T> void addNotGettableExtension(
- ServiceReference<T> serviceReference) {
+ CachingServiceReference<T> serviceReference) {
if (_LOGGER.isWarnEnabled()) {
_LOGGER.warn(
@@ -165,7 +167,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
public boolean addShadowedApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
return _shadowedApplications.add(serviceReference);
}
@@ -235,69 +237,69 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
public void removeApplicationEndpoint(
- String applicationName, ServiceReference<?> endpointServiceReference) {
+ String applicationName, CachingServiceReference<?> endpointImmutableServiceReference) {
_applicationEndpoints.compute(
- applicationName, remover(endpointServiceReference));
+ applicationName, remover(endpointImmutableServiceReference));
}
public void removeApplicationExtension(
- String applicationName, ServiceReference<?> extensionServiceReference) {
+ String applicationName, CachingServiceReference<?> extensionImmutableServiceReference) {
_applicationExtensions.computeIfPresent(
- applicationName, remover(extensionServiceReference));
+ applicationName, remover(extensionImmutableServiceReference));
}
public void removeClashingApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
_clashingApplications.remove(serviceReference);
}
public void removeDependentApplication(
- ServiceReference<Application> applicationReference) {
+ CachingServiceReference<Application> applicationReference) {
_dependentApplications.remove(applicationReference);
}
- public void removeDependentService(ServiceReference<?> serviceReference) {
+ public void removeDependentService(CachingServiceReference<?> serviceReference) {
_dependentServices.remove(serviceReference);
}
public void removeErroredApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
_erroredApplications.remove(serviceReference);
}
- public <T> void removeErroredEndpoint(ServiceReference<T> serviceReference) {
+ public <T> void removeErroredEndpoint(CachingServiceReference<T> serviceReference) {
_erroredEndpoints.remove(serviceReference);
}
- public void removeInvalidExtension(ServiceReference<?> serviceReference) {
+ public void removeInvalidExtension(CachingServiceReference<?> serviceReference) {
_invalidExtensions.remove(serviceReference);
}
public boolean removeNotGettableApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
return _ungettableApplications.remove(serviceReference);
}
public <T> boolean removeNotGettableEndpoint(
- ServiceReference<T> serviceReference) {
+ CachingServiceReference<T> serviceReference) {
return _ungettableEndpoints.remove(serviceReference);
}
public <T> void removeNotGettableExtension(
- ServiceReference<T> serviceReference) {
+ CachingServiceReference<T> serviceReference) {
_ungettableExtensions.remove(serviceReference);
}
public boolean removeShadowedApplication(
- ServiceReference<Application> serviceReference) {
+ CachingServiceReference<Application> serviceReference) {
return _shadowedApplications.remove(serviceReference);
}
@@ -351,7 +353,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private FailedExtensionDTO buildFailedExtensionDTO(
- int reason, ServiceReference<?> serviceReference) {
+ int reason, CachingServiceReference<?> serviceReference) {
FailedExtensionDTO failedExtensionDTO = new FailedExtensionDTO();
@@ -363,7 +365,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private FailedResourceDTO buildFailedResourceDTO(
- int reason, ServiceReference<?> serviceReference) {
+ int reason, CachingServiceReference<?> serviceReference) {
FailedResourceDTO failedResourceDTO = new FailedResourceDTO();
@@ -403,10 +405,10 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private Stream<ResourceDTO> getApplicationEndpointsStream(String name) {
- Collection<ServiceReference<?>> applicationEndpoints =
+ Collection<CachingServiceReference<?>> applicationEndpoints =
_applicationEndpoints.get(name);
- Stream<ServiceReference<?>> applicationEndpointStream =
+ Stream<CachingServiceReference<?>> applicationEndpointStream =
applicationEndpoints != null ?
applicationEndpoints.stream() :
Stream.empty();
@@ -418,10 +420,10 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private Stream<ExtensionDTO> getApplicationExtensionsStream(String name) {
- Collection<ServiceReference<?>> applicationExtensions =
+ Collection<CachingServiceReference<?>> applicationExtensions =
_applicationExtensions.get(name);
- Stream<ServiceReference<?>> applicationExtensionStream =
+ Stream<CachingServiceReference<?>> applicationExtensionStream =
applicationExtensions != null ?
applicationExtensions.stream() :
Stream.empty();
@@ -468,7 +470,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private static FailedApplicationDTO buildFailedApplicationDTO(
- int reason, ServiceReference<Application> serviceReference) {
+ int reason, CachingServiceReference<Application> serviceReference) {
FailedApplicationDTO failedApplicationDTO = new FailedApplicationDTO();
@@ -501,7 +503,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private static ExtensionDTO populateExtensionDTO(
- ExtensionDTO extensionDTO, ServiceReference<?> serviceReference) {
+ ExtensionDTO extensionDTO, CachingServiceReference<?> serviceReference) {
extensionDTO.name = serviceReference.getProperty(JAX_RS_NAME).
toString();
@@ -519,7 +521,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
}
private static ResourceDTO populateResourceDTO(
- ResourceDTO resourceDTO, ServiceReference<?> serviceReference) {
+ ResourceDTO resourceDTO, CachingServiceReference<?> serviceReference) {
resourceDTO.name = getApplicationName(serviceReference::getProperty);
resourceDTO.serviceId = (Long)serviceReference.getProperty(
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d825a6c4/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 41e482a..bac6758 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
@@ -37,7 +37,6 @@ import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.apache.cxf.message.Message;
import org.osgi.framework.ServiceReference;
@@ -48,7 +47,7 @@ public class CXFJaxRsServiceRegistrator {
private final Application _application;
private final Bus _bus;
private final Collection<ServiceTuple<?>> _providers = new TreeSet<>(
- Comparator.comparing(ServiceTuple::getServiceReference));
+ Comparator.comparing(ServiceTuple::getCachingServiceReference));
private final Collection<ResourceProvider> _services = new ArrayList<>();
private volatile boolean _closed = false;
private Server _server;
@@ -129,7 +128,7 @@ public class CXFJaxRsServiceRegistrator {
static {
comparator = Comparator.comparing(
- ServiceReferenceResourceProvider::getServiceReference);
+ srrp -> srrp.getImmutableServiceReference());
}
@Override
@@ -198,7 +197,8 @@ public class CXFJaxRsServiceRegistrator {
jaxRsServerFactoryBean.setProvider(
(Feature) featureContext -> {
ServiceReference<?> serviceReference =
- provider.getServiceReference();
+ provider.getCachingServiceReference().
+ getServiceReference();
String[] interfaces = canonicalize(
serviceReference.getProperty("objectClass"));
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d825a6c4/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TargetFilter.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TargetFilter.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TargetFilter.java
index 901f23a..1340989 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TargetFilter.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/TargetFilter.java
@@ -4,6 +4,7 @@ import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_
import java.util.function.Predicate;
+import org.apache.aries.osgi.functional.CachingServiceReference;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
@@ -11,14 +12,14 @@ import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TargetFilter<T> implements Predicate<ServiceReference<T>> {
+public class TargetFilter<T> implements Predicate<CachingServiceReference<T>> {
public TargetFilter(ServiceReference<?> serviceRuntimeReference) {
_serviceRuntimeReference = serviceRuntimeReference;
}
@Override
- public boolean test(ServiceReference<T> ref) {
+ public boolean test(CachingServiceReference<T> ref) {
String target = (String)ref.getProperty(JAX_RS_WHITEBOARD_TARGET);
if (target == null) {
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d825a6c4/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 ea1766b..a509720 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
@@ -18,6 +18,7 @@
package org.apache.aries.jax.rs.whiteboard.internal;
import org.apache.aries.osgi.functional.Event;
+import org.apache.aries.osgi.functional.CachingServiceReference;
import org.apache.aries.osgi.functional.OSGi;
import org.apache.aries.osgi.functional.SentEvent;
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
@@ -25,18 +26,15 @@ import org.apache.cxf.message.Message;
import org.osgi.framework.ServiceObjects;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
import java.util.Collection;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -77,7 +75,7 @@ public class Utils {
return ".generated.for." + propertyHolder.get("service.id");
}
- public static Map<String, Object> getProperties(ServiceReference<?> sref) {
+ public static Map<String, Object> getProperties(CachingServiceReference<?> sref) {
String[] propertyKeys = sref.getPropertyKeys();
Map<String, Object> properties = new HashMap<>(propertyKeys.length);
@@ -91,8 +89,9 @@ public class Utils {
public static <T> ResourceProvider getResourceProvider(
ServiceObjects<T> serviceObjects) {
- ServiceReference<T> serviceReference =
- serviceObjects.getServiceReference();
+ CachingServiceReference<T> serviceReference =
+ new CachingServiceReference<>(
+ serviceObjects.getServiceReference());
return new ServiceReferenceResourceProvider(
serviceReference, serviceObjects);
@@ -108,35 +107,37 @@ public class Utils {
}
public static <T> OSGi<ServiceTuple<T>> onlyGettables(
- OSGi<ServiceReference<T>> program,
- Consumer<ServiceReference<T>> whenAddedNotGettable,
- Consumer<ServiceReference<T>> whenLeavingNotGettable) {
+ OSGi<CachingServiceReference<T>> program,
+ Consumer<CachingServiceReference<T>> whenAddedNotGettable,
+ Consumer<CachingServiceReference<T>> whenLeavingNotGettable) {
return bundleContext().flatMap(bundleContext ->
- program.flatMap(serviceReference -> {
+ program.flatMap(immutable -> {
T service = null;
try {
- service = bundleContext.getService(serviceReference);
+ service = bundleContext.getService(
+ immutable.getServiceReference());
}
catch (Exception e){
}
if (service == null) {
- whenAddedNotGettable.accept(serviceReference);
+ whenAddedNotGettable.accept(immutable);
return
onClose(
() -> whenLeavingNotGettable.accept(
- serviceReference)
+ immutable)
).then(
nothing()
);
}
return
onClose(
- () -> bundleContext.ungetService(serviceReference)
+ () -> bundleContext.ungetService(
+ immutable.getServiceReference())
).then(
- just(new ServiceTuple<>(serviceReference, service))
+ just(new ServiceTuple<>(immutable, service))
);
}));
}
@@ -147,7 +148,12 @@ public class Utils {
return program.route(new HighestRankedRouter<>());
}
- public static <T> OSGi<T> service(ServiceReference<T> serviceReference) {
+ public static <T> OSGi<T> service(
+ CachingServiceReference<T> immutableServiceReference) {
+
+ ServiceReference<T> serviceReference =
+ immutableServiceReference.getServiceReference();
+
return
bundleContext().flatMap(bundleContext ->
onClose(() -> bundleContext.ungetService(serviceReference)).then(
@@ -156,11 +162,12 @@ public class Utils {
}
public static <T> OSGi<ServiceObjects<T>> serviceObjects(
- ServiceReference<T> serviceReference) {
+ CachingServiceReference<T> immutableServiceReference) {
return
bundleContext().flatMap(bundleContext ->
- just(bundleContext.getServiceObjects(serviceReference))
+ just(bundleContext.getServiceObjects(
+ immutableServiceReference.getServiceReference()))
);
}
@@ -174,8 +181,8 @@ public class Utils {
public static void updateProperty(
ServiceRegistration<?> serviceRegistration, String key, Object value) {
- ServiceReference<?> serviceReference =
- serviceRegistration.getReference();
+ CachingServiceReference<?> serviceReference =
+ new CachingServiceReference<>(serviceRegistration.getReference());
Dictionary<String, Object> properties = new Hashtable<>();
@@ -203,10 +210,10 @@ public class Utils {
implements ResourceProvider {
private final ServiceObjects<?> _serviceObjects;
- private ServiceReference<?> _serviceReference;
+ private CachingServiceReference<?> _serviceReference;
ServiceReferenceResourceProvider(
- ServiceReference<?> serviceReference,
+ CachingServiceReference<?> serviceReference,
ServiceObjects<?> serviceObjects) {
_serviceReference = serviceReference;
@@ -242,7 +249,7 @@ public class Utils {
return false;
}
- ServiceReference<?> getServiceReference() {
+ CachingServiceReference<?> getImmutableServiceReference() {
return _serviceReference;
}
@@ -250,10 +257,10 @@ public class Utils {
public static class ServiceTuple<T> implements Comparable<ServiceTuple<T>> {
- private final ServiceReference<T> _serviceReference;
+ private final CachingServiceReference<T> _serviceReference;
private final T _service;
- ServiceTuple(ServiceReference<T> a, T service) {
+ ServiceTuple(CachingServiceReference<T> a, T service) {
_serviceReference = a;
_service = service;
}
@@ -282,7 +289,7 @@ public class Utils {
return _serviceReference.equals(that._serviceReference);
}
- ServiceReference<T> getServiceReference() {
+ CachingServiceReference<T> getCachingServiceReference() {
return _serviceReference;
}
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d825a6c4/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
index 815dbac..c107941 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
@@ -20,6 +20,7 @@ package org.apache.aries.jax.rs.whiteboard.internal;
import org.apache.aries.jax.rs.whiteboard.internal.Utils.ApplicationExtensionRegistration;
import org.apache.aries.jax.rs.whiteboard.internal.Utils.PropertyHolder;
import org.apache.aries.jax.rs.whiteboard.internal.Utils.ServiceTuple;
+import org.apache.aries.osgi.functional.CachingServiceReference;
import org.apache.aries.osgi.functional.OSGi;
import org.apache.aries.osgi.functional.OSGiResult;
import org.apache.cxf.Bus;
@@ -125,13 +126,13 @@ public class Whiteboard {
static final String DEFAULT_NAME = ".default";
private static final Function<ServiceTuple<Application>, String>
APPLICATION_BASE =
- ((Function<ServiceTuple<Application>, ServiceReference<Application>>)
- ServiceTuple::getServiceReference).andThen(
+ ((Function<ServiceTuple<Application>, CachingServiceReference<Application>>)
+ ServiceTuple::getCachingServiceReference).andThen(
sr -> getApplicationBase(sr::getProperty));
private static final Function<ServiceTuple<Application>, String>
APPLICATION_NAME =
- ((Function<ServiceTuple<Application>, ServiceReference<Application>>)
- ServiceTuple::getServiceReference).andThen(
+ ((Function<ServiceTuple<Application>, CachingServiceReference<Application>>)
+ ServiceTuple::getCachingServiceReference).andThen(
sr -> getApplicationName(sr::getProperty));
private final AriesJaxRSServiceRuntime _runtime;
@@ -240,21 +241,21 @@ public class Whiteboard {
OSGi<ServiceTuple<Application>> highestRankedPerName = highestPer(
APPLICATION_NAME, gettableAplicationForWhiteboard,
- t -> _runtime.addClashingApplication(t.getServiceReference()),
- t -> _runtime.removeClashingApplication(t.getServiceReference())
+ t -> _runtime.addClashingApplication(t.getCachingServiceReference()),
+ t -> _runtime.removeClashingApplication(t.getCachingServiceReference())
);
OSGi<ServiceTuple<Application>> highestRankedPerPath = highestPer(
APPLICATION_BASE, highestRankedPerName,
- t -> _runtime.addShadowedApplication(t.getServiceReference()),
- t -> _runtime.removeShadowedApplication(t.getServiceReference())
+ t -> _runtime.addShadowedApplication(t.getCachingServiceReference()),
+ t -> _runtime.removeShadowedApplication(t.getCachingServiceReference())
);
return
highestRankedPerPath.flatMap(
this::deployApplication
).map(
- ServiceTuple::getServiceReference
+ ServiceTuple::getCachingServiceReference
).map(
Utils::getProperties
).foreach(
@@ -314,7 +315,7 @@ public class Whiteboard {
return bus;
}
- private OSGi<ServiceReference<CXFJaxRsServiceRegistrator>>
+ private OSGi<CachingServiceReference<CXFJaxRsServiceRegistrator>>
defaultApplication() {
return
@@ -335,8 +336,8 @@ public class Whiteboard {
return
just(this::createBus).flatMap(bus ->
just(() -> {
- ServiceReference<Application> serviceReference =
- tuple.getServiceReference();
+ CachingServiceReference<Application> serviceReference =
+ tuple.getCachingServiceReference();
Map<String, Object> properties = getProperties(
serviceReference);
@@ -371,8 +372,8 @@ public class Whiteboard {
);
}
catch (RuntimeException e) {
- ServiceReference<Application> serviceReference =
- tuple.getServiceReference();
+ CachingServiceReference<Application> serviceReference =
+ tuple.getCachingServiceReference();
_runtime.addErroredApplication(serviceReference);
@@ -386,14 +387,14 @@ public class Whiteboard {
}));
}
- private OSGi<ServiceReference<Object>>
+ private OSGi<CachingServiceReference<Object>>
getApplicationExtensionsForWhiteboard() {
return serviceReferences(getApplicationExtensionsFilter()).
filter(new TargetFilter<>(_runtimeReference));
}
- private OSGi<ServiceReference<Application>>
+ private OSGi<CachingServiceReference<Application>>
getApplicationsForWhiteboard() {
return
@@ -401,7 +402,7 @@ public class Whiteboard {
filter(new TargetFilter<>(_runtimeReference));
}
- private OSGi<ServiceReference<Object>> getResourcesForWhiteboard() {
+ private OSGi<CachingServiceReference<Object>> getResourcesForWhiteboard() {
return serviceReferences(getResourcesFilter()).
filter(
new TargetFilter<>(_runtimeReference));
@@ -463,8 +464,8 @@ public class Whiteboard {
}
private <T> OSGi<?> safeRegisterEndpoint(
- ServiceReference<T> serviceReference,
- ServiceReference<CXFJaxRsServiceRegistrator> registratorReference) {
+ CachingServiceReference<T> serviceReference,
+ CachingServiceReference<CXFJaxRsServiceRegistrator> registratorReference) {
String applicationName = getApplicationName(
registratorReference::getProperty);
@@ -507,8 +508,8 @@ public class Whiteboard {
}
private OSGi<?> safeRegisterExtension(
- ServiceReference<?> serviceReference,
- ServiceReference<CXFJaxRsServiceRegistrator> registratorReference) {
+ CachingServiceReference<?> serviceReference,
+ CachingServiceReference<CXFJaxRsServiceRegistrator> registratorReference) {
return
just(() -> getApplicationName(registratorReference::getProperty)).
@@ -563,10 +564,10 @@ public class Whiteboard {
- private OSGi<ServiceReference<Application>>
+ private OSGi<CachingServiceReference<Application>>
waitForApplicationDependencies(
- ServiceReference<Application> applicationReference,
- OSGi<ServiceReference<Application>> program) {
+ CachingServiceReference<Application> applicationReference,
+ OSGi<CachingServiceReference<Application>> program) {
String[] extensionDependencies = canonicalize(
applicationReference.getProperty(JAX_RS_EXTENSION_SELECT));
@@ -608,7 +609,9 @@ public class Whiteboard {
return nothing();
}
- if (filter.match(applicationReference)) {
+ if (filter.match(
+ applicationReference.getServiceReference())) {
+
return just(applicationReference);
}
@@ -631,7 +634,7 @@ public class Whiteboard {
}
private OSGi<?> waitForExtensionDependencies(
- ServiceReference<?> serviceReference, String applicationName,
+ CachingServiceReference<?> serviceReference, String applicationName,
OSGi<?> program) {
String[] extensionDependencies = canonicalize(
@@ -657,8 +660,9 @@ public class Whiteboard {
filter(
sr -> getApplicationName(sr::getProperty).equals(
applicationName)
- ).
- filter(
+ ).map(
+ CachingServiceReference::getServiceReference
+ ).filter(
extensionFilter::match
)).effects(
__ -> {},
@@ -687,16 +691,16 @@ public class Whiteboard {
return properties.get(JAX_RS_APPLICATION_BASE).toString();
}
- private static OSGi<ServiceReference<CXFJaxRsServiceRegistrator>>
+ private static OSGi<CachingServiceReference<CXFJaxRsServiceRegistrator>>
allApplicationReferences() {
return serviceReferences(CXFJaxRsServiceRegistrator.class);
}
- private static OSGi<ServiceReference<CXFJaxRsServiceRegistrator>>
+ private static OSGi<CachingServiceReference<CXFJaxRsServiceRegistrator>>
chooseApplication(
- ServiceReference<?> serviceReference,
- Supplier<OSGi<ServiceReference<CXFJaxRsServiceRegistrator>>>
+ CachingServiceReference<?> serviceReference,
+ Supplier<OSGi<CachingServiceReference<CXFJaxRsServiceRegistrator>>>
theDefault) {
Object applicationSelectProperty = serviceReference.getProperty(
@@ -747,10 +751,10 @@ public class Whiteboard {
return format("(%s=true)", JAX_RS_RESOURCE);
}
- private static OSGi<ServiceReference<Object>> onlySupportedInterfaces(
- OSGi<ServiceReference<Object>> program,
- Consumer<ServiceReference<?>> onInvalidAdded,
- Consumer<ServiceReference<?>> onInvalidRemoved) {
+ private static OSGi<CachingServiceReference<Object>> onlySupportedInterfaces(
+ OSGi<CachingServiceReference<Object>> program,
+ Consumer<CachingServiceReference<?>> onInvalidAdded,
+ Consumer<CachingServiceReference<?>> onInvalidRemoved) {
return program.flatMap(sr -> {
if (signalsValidInterface(sr)) {
@@ -806,7 +810,7 @@ public class Whiteboard {
}
private static boolean signalsValidInterface(
- ServiceReference<Object> serviceReference) {
+ CachingServiceReference<Object> serviceReference) {
String[] objectClasses = canonicalize(serviceReference.getProperty(
"objectClass"));