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