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