Do not use ListenerRegistration in DOMSchemaService 90/101490/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Jun 2022 08:10:24 +0000 (10:10 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 8 Jun 2022 11:24:49 +0000 (11:24 +0000)
Expose only Registration.

Change-Id: Ia5ddf7e97760b9d5a7bfb8c28f0aa21989b7f5e7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMSchemaService.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMRpcRouter.java
dom/mdsal-dom-schema-osgi/src/main/java/org/opendaylight/mdsal/dom/schema/osgi/impl/OSGiDOMSchemaService.java
dom/mdsal-dom-spi/src/main/java/module-info.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/FixedDOMSchemaService.java

index dfacb4889e95142bc88ee4f1891d069969a27cfc..ead53a85766eb0c9c66ddd55c046c637ce4c53b6 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.mdsal.dom.api;
 
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
 
@@ -24,7 +25,7 @@ public interface DOMSchemaService extends DOMExtensibleService<DOMSchemaService,
      *
      * @param listener Listener which should be registered
      * @return Listener registration handle
+     * @throws NullPointerException if {@code listener} is {@code null}
      */
-    ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
-            EffectiveModelContextListener listener);
+    @NonNull Registration registerSchemaContextListener(EffectiveModelContextListener listener);
 }
index d997dfa3f5e00b98afb33b88750bbca602448ed4..e66a29d68422d0af1e4fdd625dce8ad26ad5aa57 100644 (file)
@@ -67,6 +67,7 @@ import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
 import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -99,7 +100,7 @@ public final class DOMRpcRouter extends AbstractRegistration
     private final @NonNull DOMRpcService rpcService = new RpcServiceFacade();
 
     @GuardedBy("this")
-    private ImmutableList<Registration<?>> listeners = ImmutableList.of();
+    private ImmutableList<RegImpl<?>> listeners = ImmutableList.of();
 
     @GuardedBy("this")
     private ImmutableList<ActionRegistration<?>> actionListeners = ImmutableList.of();
@@ -108,7 +109,7 @@ public final class DOMRpcRouter extends AbstractRegistration
 
     private volatile DOMActionRoutingTable actionRoutingTable = DOMActionRoutingTable.EMPTY;
 
-    private ListenerRegistration<?> listenerRegistration;
+    private Registration listenerRegistration;
 
     @Deprecated
     @VisibleForTesting
@@ -190,14 +191,14 @@ public final class DOMRpcRouter extends AbstractRegistration
     }
 
     private synchronized void notifyAdded(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
-        for (Registration<?> l : listeners) {
+        for (RegImpl<?> l : listeners) {
             l.addRpc(newTable, impl);
         }
     }
 
     private synchronized void notifyAdded(final DOMRpcRoutingTable newTable,
             final Collection<? extends DOMRpcImplementation> impls) {
-        for (Registration<?> l : listeners) {
+        for (RegImpl<?> l : listeners) {
             for (DOMRpcImplementation impl : impls) {
                 l.addRpc(newTable, impl);
             }
@@ -205,14 +206,14 @@ public final class DOMRpcRouter extends AbstractRegistration
     }
 
     private synchronized void notifyRemoved(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
-        for (Registration<?> l : listeners) {
+        for (RegImpl<?> l : listeners) {
             l.removeRpc(newTable, impl);
         }
     }
 
     private synchronized void notifyRemoved(final DOMRpcRoutingTable newTable,
             final Collection<? extends DOMRpcImplementation> impls) {
-        for (Registration<?> l : listeners) {
+        for (RegImpl<?> l : listeners) {
             for (DOMRpcImplementation impl : impls) {
                 l.removeRpc(newTable, impl);
             }
@@ -263,13 +264,11 @@ public final class DOMRpcRouter extends AbstractRegistration
         return routingTable;
     }
 
-    private static final class Registration<T extends DOMRpcAvailabilityListener>
-        extends AbstractListenerRegistration<T> {
-
+    private static final class RegImpl<T extends DOMRpcAvailabilityListener> extends AbstractListenerRegistration<T> {
         private Map<QName, Set<YangInstanceIdentifier>> prevRpcs;
         private DOMRpcRouter router;
 
-        Registration(final DOMRpcRouter router, final T listener, final Map<QName, Set<YangInstanceIdentifier>> rpcs) {
+        RegImpl(final DOMRpcRouter router, final T listener, final Map<QName, Set<YangInstanceIdentifier>> rpcs) {
             super(listener);
             this.router = requireNonNull(router);
             this.prevRpcs = requireNonNull(rpcs);
@@ -487,9 +486,8 @@ public final class DOMRpcRouter extends AbstractRegistration
         @Override
         public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T listener) {
             synchronized (DOMRpcRouter.this) {
-                final Registration<T> ret = new Registration<>(DOMRpcRouter.this, listener,
-                    routingTable.getOperations(listener));
-                listeners = ImmutableList.<Registration<?>>builder().addAll(listeners).add(ret).build();
+                final RegImpl<T> ret = new RegImpl<>(DOMRpcRouter.this, listener, routingTable.getOperations(listener));
+                listeners = ImmutableList.<RegImpl<?>>builder().addAll(listeners).add(ret).build();
 
                 listenerNotifier.execute(ret::initialTable);
                 return ret;
index e734351fd3a765757f132aacb6f1f18052200d3a..50476c4e1aab615c3fdf0663e864d40b990cb081 100644 (file)
@@ -18,13 +18,13 @@ import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
 import org.opendaylight.mdsal.dom.spi.AbstractDOMSchemaService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.AbstractRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.osgi.service.component.ComponentFactory;
-import org.osgi.service.component.ComponentInstance;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -56,8 +56,7 @@ public final class OSGiDOMSchemaService extends AbstractDOMSchemaService.WithYan
     }
 
     @Override
-    public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
-            final EffectiveModelContextListener listener) {
+    public Registration registerSchemaContextListener(final EffectiveModelContextListener listener) {
         return registerListener(requireNonNull(listener));
     }
 
@@ -109,18 +108,11 @@ public final class OSGiDOMSchemaService extends AbstractDOMSchemaService.WithYan
         deactivated = true;
     }
 
-    private @NonNull ListenerRegistration<EffectiveModelContextListener> registerListener(
-            final @NonNull EffectiveModelContextListener listener) {
-        final ComponentInstance<EffectiveModelContextImpl> reg =
-            listenerFactory.newInstance(EffectiveModelContextImpl.props(listener));
-        return new ListenerRegistration<>() {
-            @Override
-            public EffectiveModelContextListener getInstance() {
-                return listener;
-            }
-
+    private @NonNull Registration registerListener(final @NonNull EffectiveModelContextListener listener) {
+        final var reg = listenerFactory.newInstance(EffectiveModelContextImpl.props(listener));
+        return new AbstractRegistration() {
             @Override
-            public void close() {
+            protected void removeRegistration() {
                 reg.dispose();
             }
         };
index c14f74e20f7f15049ae6a442ffd964a89f1d6634..6b4bb0e8b1170c7bdba8eeb42f350a36c3b86d10 100644 (file)
@@ -18,6 +18,7 @@ module org.opendaylight.mdsal.dom.spi {
     requires transitive org.opendaylight.yangtools.yang.repo.api;
     requires transitive org.opendaylight.yangtools.yang.repo.spi;
     requires com.google.common;
+    requires org.opendaylight.yangtools.concepts;
     requires org.opendaylight.yangtools.odlext.model.api;
     requires org.opendaylight.yangtools.util;
     requires org.opendaylight.yangtools.yang.data.api;
index a6df91f642846e2a2f18d972f6aa6af7a0b811be..7fa48dab6a539ec344116099cfbff27b04396a74 100644 (file)
@@ -17,8 +17,8 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.NoOpListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
@@ -81,8 +81,7 @@ public class FixedDOMSchemaService extends AbstractDOMSchemaService {
     }
 
     @Override
-    public final @NonNull ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
-            final EffectiveModelContextListener listener) {
+    public final Registration registerSchemaContextListener(final EffectiveModelContextListener listener) {
         listener.onModelContextUpdated(getGlobalContext());
         return NoOpListenerRegistration.of(listener);
     }