X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2FBindingDOMNotificationPublishServiceAdapter.java;h=9354986195183085f31a7bd3688e162fd4bd0864;hb=refs%2Fchanges%2F35%2F100435%2F10;hp=e60aa9b6ca6629be1d14efbb56b1364d517b61d9;hpb=c875e567d2c681879f272259ed47f5bfcc25509a;p=mdsal.git diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMNotificationPublishServiceAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMNotificationPublishServiceAdapter.java index e60aa9b6ca..9354986195 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMNotificationPublishServiceAdapter.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMNotificationPublishServiceAdapter.java @@ -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 + implements NotificationPublishService { static final Factory 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 offerNotification(final Notification notification) { - ListenableFuture offerResult = domPublishService.offerNotification(toDomNotification(notification)); - return DOMNotificationPublishService.REJECTED.equals(offerResult) - ? NotificationPublishService.REJECTED - : offerResult; + public ListenableFuture offerNotification(final Notification notification) { + return toBindingResult(getDelegate().offerNotification(toDomNotification(notification))); } @Override - 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; + public ListenableFuture 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 toBindingResult( + final @NonNull ListenableFuture 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 { + Builder(final AdapterContext adapterContext) { + super(adapterContext); + } @Override public Set> getRequiredDelegates() { @@ -80,11 +76,9 @@ public class BindingDOMNotificationPublishServiceAdapter implements Notification } @Override - protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec, - final ClassToInstanceMap delegates) { - final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class); - return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish); + protected NotificationPublishService createInstance(final ClassToInstanceMap delegates) { + return new BindingDOMNotificationPublishServiceAdapter(adapterContext(), + delegates.getInstance(DOMNotificationPublishService.class)); } - } }