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 2021/04/11 16:16:19 UTC

[aries-jax-rs-whiteboard] 01/02: remove usage of internal dsl classes

This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git

commit 853af5058b474c6a6d09ba2afa57bef47631fa6e
Author: Raymond Auge <ro...@apache.org>
AuthorDate: Thu Apr 8 12:59:35 2021 -0400

    remove usage of internal dsl classes
    
    Signed-off-by: Raymond Auge <ro...@apache.org>
---
 .../aries/jax/rs/whiteboard/internal/Registry.java | 49 ++++++++++++++++------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Registry.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Registry.java
index 0e61ad3..24e774a 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Registry.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Registry.java
@@ -19,22 +19,25 @@ package org.apache.aries.jax.rs.whiteboard.internal;
 
 import org.apache.aries.component.dsl.OSGi;
 import org.apache.aries.component.dsl.OSGiResult;
-import org.apache.aries.component.dsl.internal.ConcurrentDoublyLinkedList;
+import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
+import static java.util.Objects.requireNonNull;
 import static org.apache.aries.component.dsl.OSGi.fromOsgiRunnable;
 
 public class Registry<T> implements AutoCloseable {
 
     public Registry() {
         _publishers = new HashSet<>();
-        _servicesWithPropertiesList = new ConcurrentDoublyLinkedList<>();
+        _servicesWithPropertiesList = new ArrayList<>();
     }
 
     @Override
@@ -87,9 +90,10 @@ public class Registry<T> implements AutoCloseable {
     public OSGi<T> registerService(T service, Map<String, ?> properties) {
         return (bc, p) -> {
             synchronized (Registry.this) {
-                ConcurrentDoublyLinkedList.Node node =
-                    _servicesWithPropertiesList.addLast(
-                        new ServiceWithProperties<>(service, properties));
+                final ServiceWithProperties<T> serviceWithProperties =
+                    new ServiceWithProperties<>(service, properties);
+
+                _servicesWithPropertiesList.add(serviceWithProperties);
 
                 OSGiResult result = p.publish(service);
 
@@ -108,7 +112,8 @@ public class Registry<T> implements AutoCloseable {
                         }
 
                         result.close();
-                        node.remove();
+                        _servicesWithPropertiesList.remove(
+                            serviceWithProperties);
                     }
                 };
             }
@@ -117,18 +122,38 @@ public class Registry<T> implements AutoCloseable {
 
 
     private final HashSet<FilteredPublisher<T>> _publishers;
-    private final ConcurrentDoublyLinkedList<ServiceWithProperties<T>>
-        _servicesWithPropertiesList;
+    private final List<ServiceWithProperties<T>> _servicesWithPropertiesList;
 
     private static class ServiceWithProperties<T> {
 
-        T service;
-        Map<String, ?> properties;
+        final T service;
+        final Map<String, ?> properties;
+        final Long serviceId;
 
         ServiceWithProperties(T service, Map<String, ?> properties) {
-            this.service = service;
-            this.properties = properties;
+            this.service = requireNonNull(service);
+            this.properties = requireNonNull(properties);
+            this.serviceId = requireNonNull(
+                (Long)properties.get(Constants.SERVICE_ID));
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(serviceId);
         }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            ServiceWithProperties<?> other = (ServiceWithProperties<?>) obj;
+            return Objects.equals(other.serviceId, serviceId);
+        }
+
     }
 
 }