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