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.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(new DOMNotificationRejectedException("Unacceptable blocking conditions encountered"));
35 * Publish a notification. The result of this method is a {@link ListenableFuture} which will
36 * complete once the notification has been delivered to all immediate registrants. The type of
37 * the object resulting from the future is not defined and implementations may use it to convey
38 * additional information related to the publishing process.
40 * Abstract subclasses can refine the return type as returning a promise of a more specific
43 * public interface DeliveryStatus { int getListenerCount(); } ListenableFuture<? extends
44 * DeliveryStatus>[ putNotification(DOMNotification notification);
46 * Once the Future succeeds, the resulting object can be queried for traits using instanceof,
49 * // Can block when (for example) the implemention's ThreadPool queue is full Object o =
50 * service.putNotification(notif).get(); if (o instanceof DeliveryStatus) { DeliveryStatus ds =
51 * (DeliveryStatus)o; LOG.debug("Notification was received by {} listeners",
52 * ds.getListenerCount();); } }
54 * In case an implementation is running out of resources, it can block the calling thread until
55 * enough resources become available to accept the notification for processing, or it is
58 * Caution: completion here means that the implementation has completed processing of the
59 * notification. This does not mean that all existing registrants have seen the notification.
60 * Most importantly, the delivery process at other cluster nodes may have not begun yet.
62 * @param notification Notification to be published.
63 * @return A listenable future which will report completion when the service has finished
64 * propagating the notification to its immediate registrants.
65 * @throws InterruptedException if interrupted while waiting
66 * @throws NullPointerException if notification is null.
68 @Nonnull ListenableFuture<? extends Object> putNotification(@Nonnull DOMNotification notification) throws InterruptedException;
71 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
72 * which will complete once the notification has been delivered to all immediate registrants.
73 * The type of the object resulting from the future is not defined and implementations may use
74 * it to convey additional information related to the publishing process. Unlike
75 * {@link #putNotification(DOMNotification)}, this method is guaranteed not to block if the
76 * underlying implementation encounters contention.
78 * @param notification Notification to be published.
79 * @return A listenable future which will report completion when the service has finished
80 * propagating the notification to its immediate registrants, or {@link #REJECTED} if
81 * resource constraints prevent the implementation from accepting the notification for
83 * @throws NullPointerException if notification is null.
85 @Nonnull ListenableFuture<? extends Object> offerNotification(@Nonnull DOMNotification notification);
88 * Attempt to publish a notification. The result of this method is a {@link ListenableFuture}
89 * which will complete once the notification has been delivered to all immediate registrants.
90 * The type of the object resulting from the future is not defined and implementations may use
91 * it to convey additional information related to the publishing process. Unlike
92 * {@link #putNotification(DOMNotification)}, this method is guaranteed to block more than the
95 * @param notification Notification to be published.
96 * @param timeout how long to wait before giving up, in units of unit
97 * @param unit a TimeUnit determining how to interpret the timeout parameter
98 * @return A listenable future which will report completion when the service has finished
99 * propagating the notification to its immediate registrants, or {@link #REJECTED} if
100 * resource constraints prevent the implementation from accepting the notification for
102 * @throws InterruptedException if interrupted while waiting
103 * @throws NullPointerException if notification or unit is null.
104 * @throws IllegalArgumentException if timeout is negative.
106 @Nonnull ListenableFuture<? extends Object> offerNotification(@Nonnull DOMNotification notification,
107 @Nonnegative long timeout, @Nonnull TimeUnit unit) throws InterruptedException;