Proxy controller services in DOMMountPointServiceImpl
[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 @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Void is the only allowed value")
42 public final class DOMNotificationRouter extends LegacyDOMNotificationServiceAdapter implements AutoCloseable,
43         DOMNotificationPublishService, DOMNotificationSubscriptionListenerRegistry {
44
45     private final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService;
46     private final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry;
47
48     private DOMNotificationRouter(
49             final org.opendaylight.mdsal.dom.api.DOMNotificationService delegateNotificationService,
50             final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService,
51             final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry) {
52         super(delegateNotificationService);
53         this.delegateNotificationPublishService = delegateNotificationPublishService;
54         this.delegateListenerRegistry = delegateListenerRegistry;
55     }
56
57     public static DOMNotificationRouter create(final int queueDepth) {
58         final org.opendaylight.mdsal.dom.broker.DOMNotificationRouter delegate =
59                 org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.create(queueDepth);
60         return create(delegate, delegate, delegate);
61     }
62
63     public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime,
64                                                final TimeUnit unit) {
65         final org.opendaylight.mdsal.dom.broker.DOMNotificationRouter delegate =
66                 org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.create(queueDepth, spinTime, parkTime, unit);
67         return create(delegate, delegate, delegate);
68     }
69
70     public static DOMNotificationRouter create(
71             final org.opendaylight.mdsal.dom.api.DOMNotificationService delegateNotificationService,
72             final org.opendaylight.mdsal.dom.api.DOMNotificationPublishService delegateNotificationPublishService,
73             final org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry delegateListenerRegistry) {
74         return new DOMNotificationRouter(delegateNotificationService, delegateNotificationPublishService,
75                 delegateListenerRegistry);
76     }
77
78     @Override
79     public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
80             final T listener, final Collection<SchemaPath> types) {
81         return super.registerNotificationListener(listener, types);
82     }
83
84     @Override
85     public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
86             final L listener) {
87         return delegateListenerRegistry.registerSubscriptionListener(listener);
88     }
89
90     @Override
91     public ListenableFuture<?> putNotification(final DOMNotification notification) throws InterruptedException {
92         return delegateNotificationPublishService.putNotification(notification);
93     }
94
95     @Override
96     public ListenableFuture<?> offerNotification(final DOMNotification notification) {
97         return delegateNotificationPublishService.offerNotification(notification);
98     }
99
100     @Override
101     public ListenableFuture<?> offerNotification(final DOMNotification notification, final long timeout,
102                                                  final TimeUnit unit) throws InterruptedException {
103         return delegateNotificationPublishService.offerNotification(notification, timeout, unit);
104     }
105
106     @Override
107     public void close() {
108     }
109 }