Add InstanceNotification(Publish)ServiceAdapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMNotificationPublishServiceAdapter.java
index e60aa9b6ca6629be1d14efbb56b1364d517b61d9..9354986195183085f31a7bd3688e162fd4bd0864 100644 (file)
@@ -7,11 +7,13 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
@@ -19,60 +21,54 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
 import org.opendaylight.mdsal.dom.api.DOMService;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
-public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
+@VisibleForTesting
+// FIXME: 10.0.0: make this class final
+public class BindingDOMNotificationPublishServiceAdapter extends AbstractBindingAdapter<DOMNotificationPublishService>
+        implements NotificationPublishService {
 
     static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
 
-    private final BindingToNormalizedNodeCodec codecRegistry;
-    private final DOMNotificationPublishService domPublishService;
-
-    public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
+    public BindingDOMNotificationPublishServiceAdapter(final AdapterContext adapterContext,
             final DOMNotificationPublishService domPublishService) {
-        this.codecRegistry = codec;
-        this.domPublishService = domPublishService;
-    }
-
-    public BindingToNormalizedNodeCodec getCodecRegistry() {
-        return codecRegistry;
+        super(adapterContext, domPublishService);
     }
 
+    @Deprecated(forRemoval = true, since = "9.0.2")
     public DOMNotificationPublishService getDomPublishService() {
-        return domPublishService;
+        return getDelegate();
     }
 
     @Override
-    public void putNotification(final Notification notification) throws InterruptedException {
-        domPublishService.putNotification(toDomNotification(notification));
+    public void putNotification(final Notification<?> notification) throws InterruptedException {
+        getDelegate().putNotification(toDomNotification(notification));
     }
 
     @Override
-    public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
-        ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
-        return DOMNotificationPublishService.REJECTED.equals(offerResult)
-                ? NotificationPublishService.REJECTED
-                : offerResult;
+    public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification) {
+        return toBindingResult(getDelegate().offerNotification(toDomNotification(notification)));
     }
 
     @Override
-    public ListenableFuture<? extends Object> offerNotification(final Notification notification,
-                                                 final int timeout, final TimeUnit unit) throws InterruptedException {
-        ListenableFuture<?> offerResult = domPublishService.offerNotification(
-                toDomNotification(notification), timeout, unit);
-        return DOMNotificationPublishService.REJECTED.equals(offerResult)
-                ? NotificationPublishService.REJECTED
-                : offerResult;
+    public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification, final int timeout,
+            final TimeUnit unit) throws InterruptedException {
+        return toBindingResult(getDelegate().offerNotification(toDomNotification(notification), timeout, unit));
     }
 
-    private DOMNotification toDomNotification(final Notification notification) {
-        return LazySerializedDOMNotification.create(codecRegistry, notification);
+    private @NonNull DOMNotification toDomNotification(final Notification<?> notification) {
+        return new LazySerializedNotification(currentSerializer(), notification);
     }
 
-    @Override
-    public void close() throws Exception {
-
+    private static @NonNull ListenableFuture<? extends Object> toBindingResult(
+            final @NonNull ListenableFuture<? extends Object> domResult) {
+        return DOMNotificationPublishService.REJECTED.equals(domResult) ? NotificationPublishService.REJECTED
+            : domResult;
     }
 
+    // FIXME: 10.0.0: hide this class and make it final
     protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
+        Builder(final AdapterContext adapterContext) {
+            super(adapterContext);
+        }
 
         @Override
         public Set<Class<? extends DOMService>> getRequiredDelegates() {
@@ -80,11 +76,9 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification
         }
 
         @Override
-        protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
-                final ClassToInstanceMap<DOMService> delegates) {
-            final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
-            return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
+        protected NotificationPublishService createInstance(final ClassToInstanceMap<DOMService> delegates) {
+            return new BindingDOMNotificationPublishServiceAdapter(adapterContext(),
+                delegates.getInstance(DOMNotificationPublishService.class));
         }
-
     }
 }