2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.api;
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;
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}:
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>
27 public interface DOMInstanceNotificationPublishService extends DOMService {
29 * Well-known value indicating that the implementation is currently not
30 * able to accept a notification.
32 ListenableFuture<Object> REJECTED = FluentFutures.immediateFailedFluentFuture(
33 new DOMNotificationRejectedException("Unacceptable blocking conditions encountered"));
36 * Publish a notification. The result of this method is a {@link ListenableFuture} which will
37 * complete once the notification has been delivered to all immediate registrants. The type of
38 * the object resulting from the future is not defined and implementations may use it to convey
39 * additional information related to the publishing process.
40 * Abstract subclasses can refine the return type as returning a promise of a more specific
42 * public interface DeliveryStatus { int getListenerCount(); } ListenableFuture<? extends
43 * DeliveryStatus>[ putNotification(DOMNotification notification);
44 * Once the Future succeeds, the resulting object can be queried for traits using instanceof,
46 * // Can block when (for example) the implemention's ThreadPool queue is full Object o =
47 * service.putNotification(notif).get(); if (o instanceof DeliveryStatus) { DeliveryStatus ds =
48 * (DeliveryStatus)o; LOG.debug("Notification was received by {} listeners",
49 * ds.getListenerCount();); } }
50 * In case an implementation is running out of resources, it can block the calling thread until
51 * enough resources become available to accept the notification for processing, or it is
55 * Caution: completion here means that the implementation has completed processing of the
56 * notification. This does not mean that all existing registrants have seen the notification.
57 * Most importantly, the delivery process at other cluster nodes may have not begun yet.
59 * @param path parent reference path
60 * @param notification Notification to be published.
61 * @return A listenable future which will report completion when the service has finished
62 * propagating the notification to its immediate registrants.
63 * @throws InterruptedException if interrupted while waiting
64 * @throws NullPointerException if notification is null.
66 @NonNull ListenableFuture<? extends Object> putNotification(@NonNull DOMDataTreeIdentifier path,
67 @NonNull DOMNotification notification) throws InterruptedException;
70 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
71 * which will complete once the notification has been delivered to all immediate registrants.
72 * The type of the object resulting from the future is not defined and implementations may use
73 * it to convey additional information related to the publishing process. Unlike
74 * {@link #putNotification(DOMDataTreeIdentifier, DOMNotification)}, this method is guaranteed not to block if the
75 * underlying implementation encounters contention.
77 * @param path parent reference path
78 * @param notification Notification to be published.
79 * @return A listenable future which will report completion when the service has finished
80 * propagating the notification to its immediate registrants, or {@link #REJECTED} if
81 * resource constraints prevent the implementation from accepting the notification for
83 * @throws NullPointerException if notification is null.
85 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull DOMDataTreeIdentifier path,
86 @NonNull DOMNotification notification);
89 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
90 * which will complete once the notification has been delivered to all immediate registrants.
91 * The type of the object resulting from the future is not defined and implementations may use
92 * it to convey additional information related to the publishing process. Unlike
93 * {@link #putNotification(DOMDataTreeIdentifier, DOMNotification)}, this method is guaranteed to block more than
94 * the specified timeout.
96 * @param path parent reference path
97 * @param notification Notification to be published.
98 * @param timeout how long to wait before giving up, in units of unit
99 * @param unit a TimeUnit determining how to interpret the timeout parameter
100 * @return A listenable future which will report completion when the service has finished
101 * propagating the notification to its immediate registrants, or {@link #REJECTED} if
102 * resource constraints prevent the implementation from accepting the notification for
104 * @throws InterruptedException if interrupted while waiting
105 * @throws NullPointerException if notification or unit is null.
106 * @throws IllegalArgumentException if timeout is negative.
108 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull DOMDataTreeIdentifier path,
109 @NonNull DOMNotification notification, @NonNegative long timeout, @NonNull TimeUnit unit)
110 throws InterruptedException;