Fix checkstyle violations in sal-binding-api
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / NotificationPublishService.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.binding.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 org.opendaylight.yangtools.yang.binding.Notification;
14
15 /**
16  * A {@link NotificationService} which also allows its users to
17  * submit YANG-modeled notifications for delivery. There are three
18  * methods of submission, following the patters from {@link java.util.concurrent.BlockingQueue}:
19  * - {@link #putNotification(Notification)}, which may block indefinitely
20  *   if the implementation cannot allocate resources to accept the notification,
21  * - {@link #offerNotification(Notification)}, which does not block if face
22  *   of resource starvation,
23  * - {@link #offerNotification(Notification, int, TimeUnit)}, which may block
24  *   for specified time if resources are thin.
25  *
26  * <p>
27  * The actual delivery to listeners is asynchronous and implementation-specific.
28  * Users of this interface should not make any assumptions as to whether the
29  * notification has or has not been seen.
30  */
31 public interface NotificationPublishService extends BindingService {
32
33     /**
34      * Well-known value indicating that the binding-aware implementation is currently not
35      * able to accept a notification.
36      */
37     ListenableFuture<Object> REJECTED = Futures.immediateFailedFuture(new NotificationRejectedException(
38             "Rejected due to resource constraints."));
39
40     /**
41      * Publishes a notification to subscribed listeners. This initiates
42      * the process of sending the notification, but delivery to the
43      * listeners can happen asynchronously, potentially after a call to
44      * this method returns.
45      *
46      * <b>Note:</b> This call will block when the notification queue is full.
47      *
48      * @param notification
49      *            the notification to publish.
50      * @throws InterruptedException if interrupted while waiting
51      * @throws NullPointerException if the notification is null
52      */
53     void putNotification(Notification notification) throws InterruptedException;
54
55     /**
56      * Publishes a notification to subscribed listeners. This initiates
57      * the process of sending the notification, but delivery to the
58      * listeners can happen asynchronously, potentially after a call to
59      * this method returns.
60      *
61      * <p>
62      * Still guaranteed not to block. Returns Listenable Future which will complete once.
63      *
64      * @param notification
65      *            the notification to publish.
66      * @return A listenable future which will report completion when the service has finished
67      *     propagating the notification to its immediate registrants, or {@link #REJECTED} if resource
68      *     constraints prevent
69      * @throws NullPointerException if the notification is null
70      */
71     ListenableFuture<?> offerNotification(Notification notification);
72
73     /**
74      * Publishes a notification to subscribed listeners. This initiates
75      * the process of sending the notification, but delivery to the
76      * listeners can happen asynchronously, potentially after a call to
77      * this method returns. This method is guaranteed not to block more
78      * than the specified timeout.
79      *
80      * @param notification
81      *            the notification to publish.
82      * @param timeout how long to wait before giving up, in units of unit
83      * @param unit a TimeUnit determining how to interpret the
84      *             timeout parameter
85      * @return A listenable future which will report completion when the service has finished
86      *     propagating the notification to its immediate registrants, or {@link #REJECTED} if resource
87      *     constraints prevent
88      * @throws InterruptedException if interrupted while waiting
89      * @throws NullPointerException if the notification or unit is null
90      * @throws IllegalArgumentException if timeout is negative.
91      */
92     ListenableFuture<?> offerNotification(Notification notification, int timeout, TimeUnit unit)
93             throws InterruptedException;
94
95 }