2 * Copyright (c) 2022 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.binding.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.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.InstanceNotification;
20 * A {@link BindingService} which allows its users to submit YANG-modeled top-level (YANG 1.1)
21 * {@link InstanceNotification}s for delivery.
24 public interface InstanceNotificationPublishService extends BindingService {
26 * Create a new {@link Publisher} for a {@link InstanceNotificationSpec}. Returned interface may be freely reused
27 * and accessed concurrently from multiple threads.
29 * @param <N> Generated InstanceNotification interface type
30 * @param <P> Notification parent type
31 * @param notificationSpec Specification of an {@link InstanceNotification}
32 * @return A {@link Publisher} handle
33 * @throws NullPointerException if {@code notificationSpec} is {@code null}
34 * @throws IllegalArgumentException when {@code notificationSpec} cannot be resolved
36 <N extends InstanceNotification<N, P>, P extends DataObject> @NonNull Publisher<N, P> newPublisher(
37 InstanceNotificationSpec<N, P> notificationSpec);
40 * Interface for publishing {@link InstanceNotification} of a particular type bound to an instantiation. There are
41 * three methods of submission, following the patters from {@link java.util.concurrent.BlockingQueue}:
43 * <li>{@link #putNotification(InstanceIdentifier, InstanceNotification)}, which may block indefinitely if the
44 * implementation cannot allocate resources to accept the notification,</li>
45 * <li>{@link #offerNotification(InstanceIdentifier, InstanceNotification)}, which does not block if face of
46 * resource starvation,</li>
47 * <li>{@link #offerNotification(InstanceIdentifier, InstanceNotification, long, TimeUnit)}, which may block for
48 * specified time if resources are thin.</li>
52 * The actual delivery to listeners is asynchronous and implementation-specific. Users of this interface should not
53 * make any assumptions as to whether the notification has or has not been seen.
55 * @param <N> Generated InstanceNotification interface type
56 * @param <P> Notification parent type
59 interface Publisher<N extends InstanceNotification<N, P>, P extends DataObject> {
61 * Well-known value indicating that the binding-aware implementation is currently not able to accept a
64 @NonNull ListenableFuture<Object> REJECTED = FluentFutures.immediateFailedFluentFuture(
65 new NotificationRejectedException("Rejected due to resource constraints."));
68 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
69 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns.
71 * <b>Note:</b> This call will block when the notification queue is full.
73 * @param path parent path
74 * @param notification the notification to publish.
75 * @throws InterruptedException if interrupted while waiting
76 * @throws NullPointerException if any argument is null
78 void putNotification(@NonNull InstanceIdentifier<P> path, @NonNull N notification) throws InterruptedException;
81 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
82 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns.
85 * Still guaranteed not to block. Returns Listenable Future which will complete once the delivery is completed.
87 * @param path parent path
88 * @param notification the notification to publish.
89 * @return A listenable future which will report completion when the service has finished propagating the
90 * notification to its immediate registrants, or {@link #REJECTED} if resource constraints prevent
91 * @throws NullPointerException if any argument is null
93 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull InstanceIdentifier<P> path,
94 @NonNull N notification);
97 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
98 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns. This
99 * method is guaranteed not to block more than the specified timeout.
101 * @param path parent path
102 * @param notification the notification to publish.
103 * @param timeout how long to wait before giving up, in units of unit
104 * @param unit a TimeUnit determining how to interpret the timeout parameter
105 * @return A listenable future which will report completion when the service has finished propagating the
106 * notification to its immediate registrants, or {@link #REJECTED} if resource constraints prevent
107 * @throws InterruptedException if interrupted while waiting
108 * @throws NullPointerException if any argument is null
109 * @throws IllegalArgumentException if timeout is negative.
111 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull InstanceIdentifier<P> path,
112 @NonNull N notification, long timeout, @NonNull TimeUnit unit) throws InterruptedException;