Deprecate ListenerRegistry for removal 26/109226/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 8 Dec 2023 13:43:52 +0000 (14:43 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 8 Dec 2023 16:26:16 +0000 (16:26 +0000)
ListenerRegistry is intrinsically tied to EventListener. We have
ObjectRegistry which has the same functionality without the excess
baggage.

Add ObjectRegistryTest and deprecate ListenerRegistry for removal.

JIRA: YANGTOOLS-1551
Change-Id: I10bc98420abe5f760e08f4a05ef189df85cc7ee0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java
common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java
common/util/src/test/java/org/opendaylight/yangtools/util/ObjectRegistryTest.java [new file with mode: 0644]

index 100acc9eb904112199f64f080db16c8e97b2d899..ea6a870ffaf4d9926578ae972df3e7ac544f244b 100644 (file)
@@ -24,7 +24,9 @@ import org.opendaylight.yangtools.concepts.Mutable;
  * A registry of EventListeners, maintaining a set of registrations. This class is thread-safe.
  *
  * @param <T> Type of listeners this registry handles
+ * @deprecated Use {@link ObjectRegistry} instead
  */
+@Deprecated(since = "12.0.0", forRemoval = true)
 public final class ListenerRegistry<T extends EventListener> implements Mutable {
     private final Set<RegistrationImpl<? extends T>> listeners = ConcurrentHashMap.newKeySet();
     private final String name;
index 288c31d472b3ac4fb062e0407f2fcc09f42efce1..996bed606360af809ddd073c98a3ab284d3dc0ce 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import java.util.EventListener;
 import org.junit.jupiter.api.Test;
 
+@Deprecated(since = "12.0.0", forRemoval = true)
 class ListenerRegistryTest {
     private final ExtendedTestEventListener extendedTestEventListener = new ExtendedTestEventListener() {};
     private final ListenerRegistry<TestEventListener> registry = ListenerRegistry.create();
diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ObjectRegistryTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ObjectRegistryTest.java
new file mode 100644 (file)
index 0000000..6663382
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+
+class ObjectRegistryTest {
+    private final ObjectRegistry<TestEventListener> registry = ObjectRegistry.createSimple("testName");
+
+    @Test
+    void testCreateNewInstance() {
+        assertNotNull(registry, "Intance of listener registry should not be null.");
+    }
+
+    @Test
+    void testGetListenersMethod() {
+        assertEquals(0, registry.streamObjects().count(), "Listener registry should not have any listeners.");
+    }
+
+    @Test
+    void testRegisterMethod() {
+        final var extendedTestEventListener = new ExtendedTestEventListener() {
+            // Nothing else
+        };
+        final var listenerRegistration = registry.register(extendedTestEventListener);
+        assertEquals(extendedTestEventListener, listenerRegistration.getInstance(), "Listeners should be the same.");
+    }
+
+    interface TestEventListener {
+        // Nothing else
+    }
+
+    interface ExtendedTestEventListener extends TestEventListener {
+        // Nothing else
+    }
+}