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.controller.md.sal.dom.api;
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.TimeUnit;
13 import org.eclipse.jdt.annotation.NonNull;
16 * A {@link DOMService} which allows its user to send {@link DOMNotification}s. It
17 * provides two styles of initiating the notification delivery, similar to
18 * {@link java.util.concurrent.BlockingQueue}:
19 * - a put-style method which waits until the implementation can accept the notification
21 * - an offer-style method, which attempts to enqueue the notification, but allows
22 * the caller to specify that it should never wait, or put an upper bound on how
23 * long it is going to wait.
25 * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMNotificationPublishService} instead
28 public interface DOMNotificationPublishService extends DOMService {
30 * Well-known value indicating that the implementation is currently not
31 * able to accept a notification.
33 ListenableFuture<Object> REJECTED = Futures.immediateFailedFuture(
34 new DOMNotificationRejectedException("Unacceptable blocking conditions encountered"));
37 * Publish a notification. The result of this method is a {@link ListenableFuture}
38 * which will complete once the notification has been delivered to all immediate
39 * registrants. The type of the object resulting from the future is not defined
40 * and implementations may use it to convey additional information related to the
44 * Abstract subclasses can refine the return type as returning a promise of a
45 * more specific type, e.g.:
48 * public interface DeliveryStatus { int getListenerCount(); }
49 * ListenableFuture<? extends DeliveryStatus> putNotification(DOMNotification notification);
53 * Once the Future succeeds, the resulting object can be queried for traits using
57 * // Can block when (for example) the implemention's ThreadPool queue is full
58 * Object o = service.putNotification(notif).get();
59 * if (o instanceof DeliveryStatus) {
60 * DeliveryStatus ds = (DeliveryStatus)o;
61 * LOG.debug("Notification was received by {} listeners", ds.getListenerCount(););
66 * In case an implementation is running out of resources, it can block the calling
67 * thread until enough resources become available to accept the notification for
68 * processing, or it is interrupted.
71 * Caution: completion here means that the implementation has completed processing
72 * of the notification. This does not mean that all existing registrants
73 * have seen the notification. Most importantly, the delivery process at
74 * other cluster nodes may have not begun yet.
76 * @param notification Notification to be published.
77 * @return A listenable future which will report completion when the service
78 * has finished propagating the notification to its immediate registrants.
79 * @throws InterruptedException if interrupted while waiting
80 * @throws NullPointerException if notification is null.
82 @NonNull ListenableFuture<?> putNotification(@NonNull DOMNotification notification) throws InterruptedException;
85 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
86 * which will complete once the notification has been delivered to all immediate
87 * registrants. The type of the object resulting from the future is not defined
88 * and implementations may use it to convey additional information related to the
89 * publishing process. Unlike {@link #putNotification(DOMNotification)}, this method
90 * is guaranteed not to block if the underlying implementation encounters contention.
92 * @param notification Notification to be published.
93 * @return A listenable future which will report completion when the service
94 * has finished propagating the notification to its immediate registrants,
95 * or {@link #REJECTED} if resource constraints prevent
96 * the implementation from accepting the notification for delivery.
97 * @throws NullPointerException if notification is null.
99 @NonNull ListenableFuture<?> offerNotification(@NonNull DOMNotification notification);
102 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
103 * which will complete once the notification has been delivered to all immediate
104 * registrants. The type of the object resulting from the future is not defined
105 * and implementations may use it to convey additional information related to the
106 * publishing process. Unlike {@link #putNotification(DOMNotification)}, this method
107 * is guaranteed to block more than the specified timeout.
109 * @param notification Notification to be published.
110 * @param timeout how long to wait before giving up, in units of unit, must not be negative
111 * @param unit a TimeUnit determining how to interpret the timeout parameter
112 * @return A listenable future which will report completion when the service
113 * has finished propagating the notification to its immediate registrants,
114 * or {@link #REJECTED} if resource constraints prevent
115 * the implementation from accepting the notification for delivery.
116 * @throws InterruptedException if interrupted while waiting
117 * @throws NullPointerException if notification or unit is null.
118 * @throws IllegalArgumentException if timeout is negative.
120 @NonNull ListenableFuture<?> offerNotification(@NonNull DOMNotification notification,
121 long timeout, @NonNull TimeUnit unit) throws InterruptedException;