Split out RpcInvocationStrategy
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMNotificationServiceAdapter.java
index ce26cbca98224edf2da4bae818bff06faff324e1..00709df52093d3a5bf42851b0be7910342e75048 100644 (file)
@@ -12,19 +12,24 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableSet;
+import java.util.HashMap;
 import java.util.Set;
 import java.util.concurrent.Executor;
 import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMService;
 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
 @VisibleForTesting
+// FIXME: 10.0.0: make this class final
 public class BindingDOMNotificationServiceAdapter implements NotificationService {
     public static final Factory<NotificationService> BUILDER_FACTORY = Builder::new;
 
@@ -38,26 +43,34 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService
     }
 
     @Override
+    @Deprecated(since = "10.0.0", forRemoval = true)
     public <T extends NotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener) {
-        final BindingDOMNotificationListenerAdapter domListener
-                = new BindingDOMNotificationListenerAdapter(adapterContext, listener);
-        final ListenerRegistration<BindingDOMNotificationListenerAdapter> domRegistration =
-                domNotifService.registerNotificationListener(domListener, domListener.getSupportedNotifications());
-        return new ListenerRegistrationImpl<>(listener, domRegistration);
+        final var domListener = new BindingDOMNotificationListenerAdapter(adapterContext, listener);
+        return new ListenerRegistrationImpl<>(listener,
+            domNotifService.registerNotificationListener(domListener, domListener.getSupportedNotifications()));
     }
 
     @Override
-    public <N extends Notification> Registration registerListener(final Class<N> type, final Listener<N> listener,
-            final Executor executor) {
+    public <N extends Notification<N> & DataObject> Registration registerListener(final Class<N> type,
+            final Listener<N> listener, final Executor executor) {
         final var domListener = new SingleBindingDOMNotificationAdapter<>(adapterContext, type, listener, executor);
         return domNotifService.registerNotificationListener(domListener, domListener.getSupportedNotifications());
     }
 
-    public DOMNotificationService getDomService() {
-        return domNotifService;
+    @Override
+    public Registration registerCompositeListener(final CompositeListener listener, final Executor executor) {
+        final var exec = requireNonNull(executor);
+        final var listeners = new HashMap<Absolute, DOMNotificationListener>();
+        for (var constituent : listener.constituents()) {
+            final var domListener = new SingleBindingDOMNotificationAdapter<>(adapterContext, constituent, exec);
+            listeners.put(domListener.getSupportedNotifications().iterator().next(), domListener);
+        }
+
+        return domNotifService.registerNotificationListeners(listeners);
     }
 
-    private static class ListenerRegistrationImpl<T extends NotificationListener>
+    @Deprecated(since = "10.0.0", forRemoval = true)
+    private static final class ListenerRegistrationImpl<T extends NotificationListener>
             extends AbstractListenerRegistration<T> {
         private final ListenerRegistration<?> listenerRegistration;