2 * Copyright (c) 2014 Cisco Systems, Inc. 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.util.concurrent.ListenableFuture;
11 import java.util.concurrent.TimeUnit;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
14 import org.opendaylight.yangtools.yang.binding.Notification;
17 * A {@link BindingService} which allows its users to submit YANG-modeled top-level (YANG 1) {@link Notification}s for
18 * delivery. There are three methods of submission, following the patters from
19 * {@link java.util.concurrent.BlockingQueue}:
21 * <li>{@link #putNotification(Notification)}, which may block indefinitely if the implementation cannot allocate
22 * resources to accept the notification,</li>
23 * <li>{@link #offerNotification(Notification)}, which does not block if face of resource starvation,</li>
24 * <li>{@link #offerNotification(Notification, int, TimeUnit)}, which may block for specified time if resources are
29 * The actual delivery to listeners is asynchronous and implementation-specific. Users of this interface should not make
30 * any assumptions as to whether the notification has or has not been seen.
32 public interface NotificationPublishService extends BindingService {
34 * Well-known value indicating that the binding-aware implementation is currently not able to accept a notification.
36 @NonNull ListenableFuture<Object> REJECTED = FluentFutures.immediateFailedFluentFuture(
37 new NotificationRejectedException("Rejected due to resource constraints."));
40 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
41 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns.
43 * <b>Note:</b> This call will block when the notification queue is full.
45 * @param notification the notification to publish.
46 * @throws InterruptedException if interrupted while waiting
47 * @throws NullPointerException if the notification is null
49 void putNotification(@NonNull Notification<?> notification) throws InterruptedException;
52 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
53 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns.
56 * Still guaranteed not to block. Returns Listenable Future which will complete once.
58 * @param notification the notification to publish.
59 * @return A listenable future which will report completion when the service has finished propagating the
60 * notification to its immediate registrants, or {@link #REJECTED} if resource constraints prevent
61 * @throws NullPointerException if the notification is null
63 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification<?> notification);
66 * Publishes a notification to subscribed listeners. This initiates the process of sending the notification, but
67 * delivery to the listeners can happen asynchronously, potentially after a call to this method returns. This method
68 * is guaranteed not to block more than the specified timeout.
70 * @param notification the notification to publish.
71 * @param timeout how long to wait before giving up, in units of unit
72 * @param unit a TimeUnit determining how to interpret the timeout parameter
73 * @return A listenable future which will report completion when the service has finished propagating the
74 * notification to its immediate registrants, or {@link #REJECTED} if resource constraints prevent
75 * @throws InterruptedException if interrupted while waiting
76 * @throws NullPointerException if the notification or unit is null
77 * @throws IllegalArgumentException if timeout is negative.
79 @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification<?> notification,
80 int timeout, @NonNull TimeUnit unit) throws InterruptedException;