Bug 3135 - Fixed support for InterestListener
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMNotificationPublishServiceAdapter.java
index 0a736ffc79a11f1128b19c1110129b780c499caa..084f423807df24f004c3aa1a6dd6c3424905d1b7 100644 (file)
@@ -12,16 +12,12 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
 import org.opendaylight.controller.md.sal.dom.api.DOMService;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yangtools.yang.binding.Notification;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
 
@@ -34,14 +30,22 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification
 
     };
 
-    private final BindingNormalizedNodeSerializer codecRegistry;
+    private final BindingToNormalizedNodeCodec codecRegistry;
     private final DOMNotificationPublishService domPublishService;
 
-    public BindingDOMNotificationPublishServiceAdapter(BindingNormalizedNodeSerializer codecRegistry, DOMNotificationPublishService domPublishService) {
-        this.codecRegistry = codecRegistry;
+    public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec, final DOMNotificationPublishService domPublishService) {
+        this.codecRegistry = codec;
         this.domPublishService = domPublishService;
     }
 
+    public BindingToNormalizedNodeCodec getCodecRegistry() {
+        return codecRegistry;
+    }
+
+    public DOMNotificationPublishService getDomPublishService() {
+        return domPublishService;
+    }
+
     @Override
     public void putNotification(final Notification notification) throws InterruptedException {
         domPublishService.putNotification(toDomNotification(notification));
@@ -61,8 +65,7 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification
     }
 
     private DOMNotification toDomNotification(final Notification notification) {
-        final ContainerNode domNotification = codecRegistry.toNormalizedNodeNotification(notification);
-        return new DOMNotificationImpl(domNotification);
+        return LazySerializedDOMNotification.create(codecRegistry, notification);
     }
 
     @Override
@@ -70,29 +73,6 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification
 
     }
 
-    private static class DOMNotificationImpl implements DOMNotification {
-
-        private final SchemaPath type;
-        private final ContainerNode body;
-
-        public DOMNotificationImpl(final ContainerNode body) {
-            this.type = SchemaPath.create(true, body.getIdentifier().getNodeType());
-            this.body = body;
-        }
-
-        @Nonnull
-        @Override
-        public SchemaPath getType() {
-            return this.type;
-        }
-
-        @Nonnull
-        @Override
-        public ContainerNode getBody() {
-            return this.body;
-        }
-    }
-
     protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
 
         @Override
@@ -101,11 +81,10 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification
         }
 
         @Override
-        protected NotificationPublishService createInstance(BindingToNormalizedNodeCodec codec,
-                ClassToInstanceMap<DOMService> delegates) {
-            BindingNormalizedNodeSerializer codecReg = codec.getCodecRegistry();
-            DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
-            return new BindingDOMNotificationPublishServiceAdapter(codecReg, domPublish);
+        protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
+                final ClassToInstanceMap<DOMService> delegates) {
+            final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
+            return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
         }
 
     }