Cache full datastore context
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / DOMNotificationRouter.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.util.concurrent.ListenableFuture;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.util.Collection;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
15 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
16 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
17 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
18 import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListener;
19 import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
20 import org.opendaylight.controller.sal.core.compat.LegacyDOMNotificationServiceAdapter;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23
24 /**
25  * Joint implementation of {@link DOMNotificationPublishService} and {@link DOMNotificationService}. Provides
26  * routing of notifications from publishers to subscribers.
27  *
28  * <p>
29  * Internal implementation works by allocating a two-handler Disruptor. The first handler delivers notifications
30  * to subscribed listeners and the second one notifies whoever may be listening on the returned future. Registration
31  * state tracking is performed by a simple immutable multimap -- when a registration or unregistration occurs we
32  * re-generate the entire map from scratch and set it atomically. While registrations/unregistrations synchronize
33  * on this instance, notifications do not take any locks here.
34  *
35  * <p>
36  * The fully-blocking {@link #offerNotification(DOMNotification)}
37  * is realized using the Disruptor's native operations. The bounded-blocking
38  * {@link #offerNotification(DOMNotification, long, TimeUnit)}
39  * is realized by arming a background wakeup interrupt.
40  */
41 @Deprecated(forRemoval = true)
42 @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Void is the only allowed value")
43 public final class DOMNotificationRouter extends LegacyDOMNotificationServiceAdapter implements AutoCloseable,
44         DOMNotificationPublishService, DOMNotificationSubscriptionListenerRegistry {
45
46     private final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService;
47     private final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry;
48
49     private DOMNotificationRouter(
50             final org.opendaylight.mdsal.dom.api.DOMNotificationService delegateNotificationService,
51             final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService,
52             final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry) {
53         super(delegateNotificationService);
54         this.delegateNotificationPublishService = delegateNotificationPublishService;
55         this.delegateListenerRegistry = delegateListenerRegistry;
56     }
57
58     public static DOMNotificationRouter create(final int queueDepth) {
59         final org.opendaylight.mdsal.dom.broker.DOMNotificationRouter delegate =
60                 org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.create(queueDepth);
61         return create(delegate, delegate, delegate);
62     }
63
64     public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime,
65                                                final TimeUnit unit) {
66         final org.opendaylight.mdsal.dom.broker.DOMNotificationRouter delegate =
67                 org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.create(queueDepth, spinTime, parkTime, unit);
68         return create(delegate, delegate, delegate);
69     }
70
71     public static DOMNotificationRouter create(
72             final org.opendaylight.mdsal.dom.api.DOMNotificationService delegateNotificationService,
73             final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService,
74             final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry) {
75         return new DOMNotificationRouter(delegateNotificationService, delegateNotificationPublishService,
76                 delegateListenerRegistry);
77     }
78
79     @Override
80     public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
81             final T listener, final Collection<SchemaPath> types) {
82         return super.registerNotificationListener(listener, types);
83     }
84
85     @Override
86     public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
87             final L listener) {
88         return delegateListenerRegistry.registerSubscriptionListener(listener);
89     }
90
91     @Override
92     public ListenableFuture<?> putNotification(final DOMNotification notification) throws InterruptedException {
93         return delegateNotificationPublishService.putNotification(notification);
94     }
95
96     @Override
97     public ListenableFuture<?> offerNotification(final DOMNotification notification) {
98         return delegateNotificationPublishService.offerNotification(notification);
99     }
100
101     @Override
102     public ListenableFuture<?> offerNotification(final DOMNotification notification, final long timeout,
103                                                  final TimeUnit unit) throws InterruptedException {
104         return delegateNotificationPublishService.offerNotification(notification, timeout, unit);
105     }
106
107     @Override
108     public void close() {
109     }
110 }

©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.