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.mdsal.dom.broker;
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.mdsal.dom.api.DOMNotification;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 * A single notification event in the disruptor ringbuffer. These objects are reused,
21 * so they do have mutable state.
23 final class DOMNotificationRouterEvent {
24 public static final EventFactory<DOMNotificationRouterEvent> FACTORY =
25 new EventFactory<DOMNotificationRouterEvent>() {
27 public DOMNotificationRouterEvent newInstance() {
28 return new DOMNotificationRouterEvent();
32 private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
33 private DOMNotification notification;
34 private SettableFuture<Void> future;
36 private DOMNotificationRouterEvent() {
37 // Hidden on purpose, initialized in initialize()
40 ListenableFuture<Void> initialize(final DOMNotification notification,
41 final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
42 this.notification = Preconditions.checkNotNull(notification);
43 this.subscribers = Preconditions.checkNotNull(subscribers);
44 this.future = SettableFuture.create();
48 void deliverNotification() {
49 for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
50 final DOMNotificationListener l = r.getInstance();
52 l.onNotification(notification);