2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import com.lmax.disruptor.EventFactory;
14 import java.util.Collection;
15 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
16 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * A single notification event in the disruptor ringbuffer. These objects are reused,
23 * so they do have mutable state.
25 final class DOMNotificationRouterEvent {
26 private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
27 public static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
29 private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
30 private DOMNotification notification;
31 private SettableFuture<Void> future;
33 private DOMNotificationRouterEvent() {
34 // Hidden on purpose, initialized in initialize()
37 ListenableFuture<Void> initialize(final DOMNotification notification, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
38 this.notification = Preconditions.checkNotNull(notification);
39 this.subscribers = Preconditions.checkNotNull(subscribers);
40 this.future = SettableFuture.create();
44 void deliverNotification() {
45 LOG.trace("Start delivery of notification {}", notification);
46 for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
47 final DOMNotificationListener listener = r.getInstance();
48 if (listener != null) {
50 LOG.trace("Notifying listener {}", listener);
51 listener.onNotification(notification);
52 LOG.trace("Listener notification completed");
53 } catch (Exception e) {
54 LOG.error("Delivery of notification {} caused an error in listener {}", notification, listener, e);
58 LOG.trace("Delivery completed");