Fix modernization issues
[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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import com.lmax.disruptor.EventFactory;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import java.util.Collection;
17 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
18 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * A single notification event in the disruptor ringbuffer. These objects are reused,
25  * so they do have mutable state.
26  */
27 @Deprecated
28 final class DOMNotificationRouterEvent {
29     private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
30     public static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
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     @SuppressWarnings("checkstyle:hiddenField")
41     ListenableFuture<Void> initialize(final DOMNotification notification,
42                                       final Collection<ListenerRegistration<? extends DOMNotificationListener>>
43                                               subscribers) {
44         this.notification = requireNonNull(notification);
45         this.subscribers = requireNonNull(subscribers);
46         this.future = SettableFuture.create();
47         return this.future;
48     }
49
50     void deliverNotification() {
51         LOG.trace("Start delivery of notification {}", notification);
52         for (ListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
53             final DOMNotificationListener listener = r.getInstance();
54             LOG.trace("Notifying listener {}", listener);
55             listener.onNotification(notification);
56             LOG.trace("Listener notification completed");
57         }
58         LOG.trace("Delivery completed");
59     }
60
61     @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Void is the only allowed value")
62     void setFuture() {
63         future.set(null);
64         notification = null;
65         subscribers = null;
66         future = null;
67     }
68 }