Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / md / sal / dom / api / DOMNotificationPublishService.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.dom.api;
9
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
16 /**
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
21  *   for delivery, and
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.
25  *
26  * @deprecated Use {@link org.opendaylight.mdsal.dom.api.DOMNotificationPublishService} instead
27  */
28 @Deprecated
29 public interface DOMNotificationPublishService extends DOMService {
30     /**
31      * Well-known value indicating that the implementation is currently not
32      * able to accept a notification.
33      */
34     ListenableFuture<Object> REJECTED = Futures.immediateFailedFuture(
35             new DOMNotificationRejectedException("Unacceptable blocking conditions encountered"));
36
37     /**
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
42      * publishing process.
43      *
44      * <p>
45      * Abstract subclasses can refine the return type as returning a promise of a
46      * more specific type, e.g.:
47      *
48      * {@code
49      *     public interface DeliveryStatus { int getListenerCount(); }
50      *     ListenableFuture<? extends DeliveryStatus> putNotification(DOMNotification notification);
51      * }
52      *
53      * <p>
54      * Once the Future succeeds, the resulting object can be queried for traits using
55      * instanceof, e.g:
56      *
57      * {@code
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(););
63      *     }
64      * }
65      *
66      * <p>
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.
70      *
71      * <p>
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.
76      *
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.
82      */
83     @Nonnull ListenableFuture<?> putNotification(@Nonnull DOMNotification notification) throws InterruptedException;
84
85     /**
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.
92      *
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.
99      */
100     @Nonnull ListenableFuture<?> offerNotification(@Nonnull DOMNotification notification);
101
102     /**
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.
109      *
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.
120      */
121     @Nonnull ListenableFuture<?> offerNotification(@Nonnull DOMNotification notification,
122         @Nonnegative long timeout, @Nonnull TimeUnit unit) throws InterruptedException;
123 }