Expose completion future from WriteOperations
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / DOMNotificationRouterEvent.java
index ea79cae321a0842cee33c14410fd09778876598f..83fe2e75d20dc8ac4076a51948de1ca6b7a1262c 100644 (file)
@@ -7,50 +7,46 @@
  */
 package org.opendaylight.mdsal.dom.broker;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
-import com.lmax.disruptor.EventFactory;
-import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * A single notification event in the disruptor ringbuffer. These objects are reused,
- * so they do have mutable state.
+ * A single notification event in the notification router.
  */
 final class DOMNotificationRouterEvent {
-    static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
+    private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
 
-    private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
-    private DOMNotification notification;
-    private SettableFuture<Void> future;
+    private final SettableFuture<Empty> future = SettableFuture.create();
+    private final @NonNull DOMNotification notification;
 
-    private DOMNotificationRouterEvent() {
-        // Hidden on purpose, initialized in initialize()
+    DOMNotificationRouterEvent(final DOMNotification notification) {
+        this.notification = requireNonNull(notification);
     }
 
-    @SuppressWarnings("checkstyle:hiddenField")
-    ListenableFuture<Void> initialize(final DOMNotification notification,
-            final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
-        this.notification = Preconditions.checkNotNull(notification);
-        this.subscribers = Preconditions.checkNotNull(subscribers);
-        this.future = SettableFuture.create();
-        return this.future;
+    ListenableFuture<Empty> future() {
+        return future;
     }
 
-    void deliverNotification() {
-        for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
-            final DOMNotificationListener l = r.getInstance();
-            if (l != null) {
-                l.onNotification(notification);
-            }
+    @SuppressWarnings("checkstyle:illegalCatch")
+    void deliverTo(final DOMNotificationListener listener) {
+        try {
+            listener.onNotification(notification);
+        } catch (Exception e) {
+            LOG.warn("Listener {} failed during notification delivery", listener, e);
+        } finally {
+            clear();
         }
     }
 
-    void setFuture() {
-        future.set(null);
+    void clear() {
+        future.set(Empty.value());
     }
-
-}
\ No newline at end of file
+}