Fix checkstyle issues in module sal-dom-broker
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / 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.controller.md.sal.dom.broker.impl;
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.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;
20
21 /**
22  * A single notification event in the disruptor ringbuffer. These objects are reused,
23  * so they do have mutable state.
24  */
25 final class DOMNotificationRouterEvent {
26     private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
27     public static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
28
29     private Collection<ListenerRegistration<? extends DOMNotificationListener>> subscribers;
30     private DOMNotification notification;
31     private SettableFuture<Void> future;
32
33     private DOMNotificationRouterEvent() {
34         // Hidden on purpose, initialized in initialize()
35     }
36
37     ListenableFuture<Void> initialize(final DOMNotification notification,
38                                       final Collection<ListenerRegistration<? extends DOMNotificationListener>>
39                                               subscribers) {
40         this.notification = Preconditions.checkNotNull(notification);
41         this.subscribers = Preconditions.checkNotNull(subscribers);
42         this.future = SettableFuture.create();
43         return this.future;
44     }
45
46     void deliverNotification() {
47         LOG.trace("Start delivery of notification {}", notification);
48         for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
49             final DOMNotificationListener listener = r.getInstance();
50             if (listener != null) {
51                 LOG.trace("Notifying listener {}", listener);
52                 listener.onNotification(notification);
53                 LOG.trace("Listener notification completed");
54             }
55         }
56         LOG.trace("Delivery completed");
57     }
58
59     void setFuture() {
60         future.set(null);
61         notification = null;
62         subscribers = null;
63         future = null;
64     }
65 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.