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 org.opendaylight.mdsal.dom.api.DOMNotification;
11 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
13 import com.google.common.base.Preconditions;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.SettableFuture;
16 import com.lmax.disruptor.EventFactory;
17 import java.util.Collection;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 * A single notification event in the disruptor ringbuffer. These objects are reused,
22 * so they do have mutable state.
24 final class DOMNotificationRouterEvent {
25 public static final EventFactory<DOMNotificationRouterEvent> FACTORY = 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, final Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers) {
41 this.notification = Preconditions.checkNotNull(notification);
42 this.subscribers = Preconditions.checkNotNull(subscribers);
43 this.future = SettableFuture.create();
47 void deliverNotification() {
48 for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
49 final DOMNotificationListener l = r.getInstance();
51 l.onNotification(notification);