checkStyleViolationSeverity=error implemented for mdsal-dom-broker
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / DOMNotificationRouterEvent.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.broker;
9
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;
18
19 /**
20  * A single notification event in the disruptor ringbuffer. These objects are reused,
21  * so they do have mutable state.
22  */
23 final class DOMNotificationRouterEvent {
24     public static final EventFactory<DOMNotificationRouterEvent> FACTORY =
25             new EventFactory<DOMNotificationRouterEvent>() {
26         @Override
27         public DOMNotificationRouterEvent newInstance() {
28             return new DOMNotificationRouterEvent();
29         }
30     };
31
32     private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
33     private DOMNotification notification;
34     private SettableFuture<Void> future;
35
36     private DOMNotificationRouterEvent() {
37         // Hidden on purpose, initialized in initialize()
38     }
39
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();
45         return this.future;
46     }
47
48     void deliverNotification() {
49         for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
50             final DOMNotificationListener l = r.getInstance();
51             if (l != null) {
52                 l.onNotification(notification);
53             }
54         }
55     }
56
57     void setFuture() {
58         future.set(null);
59     }
60
61 }