Add InstanceNotification(Publish)ServiceAdapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMNotificationPublishServiceAdapter.java
index 58c44c171ef54c60874f4c702a7759580c10ae1a..9354986195183085f31a7bd3688e162fd4bd0864 100644 (file)
@@ -11,7 +11,6 @@ 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.time.Instant;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNull;
@@ -20,10 +19,10 @@ import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Facto
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
 import org.opendaylight.mdsal.dom.api.DOMService;
-import org.opendaylight.yangtools.yang.binding.EventInstantAware;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 @VisibleForTesting
+// FIXME: 10.0.0: make this class final
 public class BindingDOMNotificationPublishServiceAdapter extends AbstractBindingAdapter<DOMNotificationPublishService>
         implements NotificationPublishService {
 
@@ -34,39 +33,38 @@ public class BindingDOMNotificationPublishServiceAdapter extends AbstractBinding
         super(adapterContext, domPublishService);
     }
 
+    @Deprecated(forRemoval = true, since = "9.0.2")
     public DOMNotificationPublishService getDomPublishService() {
         return getDelegate();
     }
 
     @Override
-    public void putNotification(final Notification notification) throws InterruptedException {
+    public void putNotification(final Notification<?> notification) throws InterruptedException {
         getDelegate().putNotification(toDomNotification(notification));
     }
 
     @Override
-    public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
-        ListenableFuture<?> offerResult = getDelegate().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 = getDelegate().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 @NonNull DOMNotification toDomNotification(final Notification notification) {
-        final Instant instant = notification instanceof EventInstantAware
-                ? ((EventInstantAware) notification).eventInstant() : Instant.now();
-        return LazySerializedDOMNotification.create(currentSerializer(), notification, instant);
+    private @NonNull DOMNotification toDomNotification(final Notification<?> notification) {
+        return new LazySerializedNotification(currentSerializer(), notification);
     }
 
+    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);