Remove unused exceptions
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMNotificationPublishServiceAdapter.java
index 0a736ffc79a11f1128b19c1110129b780c499caa..c2558c3637eb02673f3f528d18c8bd2cf40a9f9c 100644 (file)
@@ -12,85 +12,64 @@ 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 {
 
-    static final Factory<NotificationPublishService> BUILDER_FACTORY = new BindingDOMAdapterBuilder.Factory<NotificationPublishService>() {
+    static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
 
-        @Override
-        public BindingDOMAdapterBuilder<NotificationPublishService> newBuilder() {
-            return new Builder();
-        }
-
-    };
-
-    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));
     }
 
     @Override
-    public boolean offerNotification(final Notification notification) {
-        final ListenableFuture<?> listenableFuture = domPublishService.offerNotification(toDomNotification(notification));
-        return !DOMNotificationPublishService.REJECTED.equals(listenableFuture);
+    public ListenableFuture<?> offerNotification(final Notification notification) {
+        ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
+        return DOMNotificationPublishService.REJECTED.equals(offerResult)
+                ? NotificationPublishService.REJECTED
+                : offerResult;
     }
 
     @Override
-    public boolean offerNotification(final Notification notification, final int timeout, final TimeUnit unit) throws InterruptedException {
-        final ListenableFuture<?> listenableFuture =
-                domPublishService.offerNotification(toDomNotification(notification), timeout, unit);
-        return !DOMNotificationPublishService.REJECTED.equals(listenableFuture);
+    public ListenableFuture<?> 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;
     }
 
     private DOMNotification toDomNotification(final Notification notification) {
-        final ContainerNode domNotification = codecRegistry.toNormalizedNodeNotification(notification);
-        return new DOMNotificationImpl(domNotification);
+        return LazySerializedDOMNotification.create(codecRegistry, notification);
     }
 
     @Override
-    public void close() throws Exception {
-
-    }
+    public void close() {
 
-    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> {
@@ -101,12 +80,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);
         }
-
     }
 }