*/
package org.opendaylight.mdsal.dom.broker;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
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.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
+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 disruptor ringbuffer. These objects are reused, so they do have mutable state.
*/
final class DOMNotificationRouterEvent {
- public static final EventFactory<DOMNotificationRouterEvent> FACTORY = new EventFactory<DOMNotificationRouterEvent>() {
- @Override
- public DOMNotificationRouterEvent newInstance() {
- return new DOMNotificationRouterEvent();
- }
- };
+ private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
+
+ static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
- private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
+ private Collection<AbstractListenerRegistration<? extends DOMNotificationListener>> subscribers;
private DOMNotification notification;
private SettableFuture<Void> future;
// Hidden on purpose, initialized in initialize()
}
- ListenableFuture<Void> initialize(final DOMNotification notification, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
- this.notification = Preconditions.checkNotNull(notification);
- this.subscribers = Preconditions.checkNotNull(subscribers);
+ @SuppressWarnings("checkstyle:hiddenField")
+ ListenableFuture<Void> initialize(final DOMNotification notification,
+ final Collection<AbstractListenerRegistration<? extends DOMNotificationListener>> subscribers) {
+ this.notification = requireNonNull(notification);
+ this.subscribers = requireNonNull(subscribers);
this.future = SettableFuture.create();
return this.future;
}
+ @SuppressWarnings("checkstyle:illegalCatch")
void deliverNotification() {
- for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
- final DOMNotificationListener l = r.getInstance();
- if (l != null) {
- l.onNotification(notification);
+ for (AbstractListenerRegistration<? extends DOMNotificationListener> reg : subscribers) {
+ if (reg.notClosed()) {
+ final DOMNotificationListener listener = reg.getInstance();
+ try {
+ listener.onNotification(notification);
+ } catch (Exception e) {
+ LOG.warn("Listener {} failed during notification delivery", listener, e);
+ }
}
}
}
void setFuture() {
future.set(null);
}
-
-}
\ No newline at end of file
+}