Fix odl-mdsal-rfc8294-netty
[mdsal.git] / dom / mdsal-dom-api / src / main / java / org / opendaylight / mdsal / dom / api / DOMInstanceNotificationPublishService.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.mdsal.dom.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.TimeUnit;
13 import org.checkerframework.checker.index.qual.NonNegative;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
16
17 /**
18  * A {@link DOMService} which allows its user to publish instance (YANG 1.1) {@link DOMNotification}s. It provides two
19  * styles of initiating the notification delivery, similar to {@link java.util.concurrent.BlockingQueue}:
20  * <ul>
21  *   <li>a put-style method which waits until the implementation can accept the notification for delivery, and</li>
22  *   <li>an offer-style method, which attempts to enqueue the notification, but allows the caller to specify that it
23  *       should never wait, or put an upper bound on how long it is going to wait</li>
24  * </ul>
25  */
26 @Beta
27 public interface DOMInstanceNotificationPublishService extends
28         DOMService<DOMInstanceNotificationPublishService, DOMInstanceNotificationPublishService.Extension> {
29     /**
30      * Marker interface for an extension to {@link DOMInstanceNotificationPublishService}.
31      */
32     interface Extension extends DOMService.Extension<DOMInstanceNotificationPublishService, Extension> {
33         // Marker interface
34     }
35
36     /**
37      * Well-known value indicating that the implementation is currently not
38      * able to accept a notification.
39      */
40     ListenableFuture<Object> REJECTED = FluentFutures.immediateFailedFluentFuture(
41         new DOMNotificationRejectedException("Unacceptable blocking conditions encountered"));
42
43     /**
44      * Publish a notification. The result of this method is a {@link ListenableFuture} which will
45      * complete once the notification has been delivered to all immediate registrants. The type of
46      * the object resulting from the future is not defined and implementations may use it to convey
47      * additional information related to the publishing process.
48      * Abstract subclasses can refine the return type as returning a promise of a more specific
49      * type, e.g.:
50      * public interface DeliveryStatus { int getListenerCount(); } ListenableFuture&lt;? extends
51      * DeliveryStatus&gt;[ putNotification(DOMNotification notification);
52      * Once the Future succeeds, the resulting object can be queried for traits using instanceof,
53      * e.g:
54      * // Can block when (for example) the implemention's ThreadPool queue is full Object o =
55      * service.putNotification(notif).get(); if (o instanceof DeliveryStatus) { DeliveryStatus ds =
56      * (DeliveryStatus)o; LOG.debug("Notification was received by {} listeners",
57      * ds.getListenerCount();); } }
58      * In case an implementation is running out of resources, it can block the calling thread until
59      * enough resources become available to accept the notification for processing, or it is
60      * interrupted.
61      *
62      * <p>
63      * Caution: completion here means that the implementation has completed processing of the
64      * notification. This does not mean that all existing registrants have seen the notification.
65      * Most importantly, the delivery process at other cluster nodes may have not begun yet.
66      *
67      * @param path parent reference path
68      * @param notification Notification to be published.
69      * @return A listenable future which will report completion when the service has finished
70      *         propagating the notification to its immediate registrants.
71      * @throws InterruptedException if interrupted while waiting
72      * @throws NullPointerException if notification is null.
73      */
74     @NonNull ListenableFuture<? extends Object> putNotification(@NonNull DOMDataTreeIdentifier path,
75             @NonNull DOMNotification notification) throws InterruptedException;
76
77     /**
78      * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
79      * which will complete once the notification has been delivered to all immediate registrants.
80      * The type of the object resulting from the future is not defined and implementations may use
81      * it to convey additional information related to the publishing process. Unlike
82      * {@link #putNotification(DOMDataTreeIdentifier, DOMNotification)}, this method is guaranteed not to block if the
83      * underlying implementation encounters contention.
84      *
85      * @param path parent reference path
86      * @param notification Notification to be published.
87      * @return A listenable future which will report completion when the service has finished
88      *         propagating the notification to its immediate registrants, or {@link #REJECTED} if
89      *         resource constraints prevent the implementation from accepting the notification for
90      *         delivery.
91      * @throws NullPointerException if notification is null.
92      */
93     @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull DOMDataTreeIdentifier path,
94         @NonNull DOMNotification notification);
95
96     /**
97      * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
98      * which will complete once the notification has been delivered to all immediate registrants.
99      * The type of the object resulting from the future is not defined and implementations may use
100      * it to convey additional information related to the publishing process. Unlike
101      * {@link #putNotification(DOMDataTreeIdentifier, DOMNotification)}, this method is guaranteed to block more than
102      * the specified timeout.
103      *
104      * @param path parent reference path
105      * @param notification Notification to be published.
106      * @param timeout how long to wait before giving up, in units of unit
107      * @param unit a TimeUnit determining how to interpret the timeout parameter
108      * @return A listenable future which will report completion when the service has finished
109      *         propagating the notification to its immediate registrants, or {@link #REJECTED} if
110      *         resource constraints prevent the implementation from accepting the notification for
111      *         delivery.
112      * @throws InterruptedException if interrupted while waiting
113      * @throws NullPointerException if notification or unit is null.
114      * @throws IllegalArgumentException if timeout is negative.
115      */
116     @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull DOMDataTreeIdentifier path,
117         @NonNull DOMNotification notification, @NonNegative long timeout, @NonNull TimeUnit unit)
118             throws InterruptedException;
119 }