Binding v2 runtime - adapters - impl - notifications
[mdsal.git] / binding2 / mdsal-binding2-api / src / main / java / org / opendaylight / mdsal / binding / javav2 / api / NotificationPublishService.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.api;
10
11 import com.google.common.annotations.Beta;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.TimeUnit;
15 import org.opendaylight.mdsal.binding.javav2.spec.base.Notification;
16
17 /**
18  * A {@link NotificationService} which also allows its users to submit YANG-modeled notifications for delivery.
19  *
20  * <p>
21  * There are three methods of submission, following the patters from {@link java.util.concurrent.BlockingQueue}:
22  *
23  * <p>
24  * - {@link #putNotification(org.opendaylight.mdsal.binding.javav2.spec.base.Notification)}, which may block
25  * indefinitely if the implementation cannot allocate resources to accept the notification,
26  * - {@link #offerNotification(org.opendaylight.mdsal.binding.javav2.spec.base.Notification)}, which does not block if
27  * face of resource starvation,
28  * - {@link #offerNotification(org.opendaylight.mdsal.binding.javav2.spec.base.Notification, int, TimeUnit)}, which may
29  * block for specified time if resources are thin.
30  *
31  *<p>
32  * The actual delivery to listeners is asynchronous and implementation-specific.
33  * Users of this interface should not make any assumptions as to whether the
34  * notification has or has not been seen.
35  */
36
37 @Beta
38 public interface NotificationPublishService extends BindingService {
39
40     ListenableFuture<Object> REJECTED = Futures.immediateFailedFuture(
41         new NotificationRejectedException("Rejected due to resource constraints."));
42
43     void putNotification(Notification<?> notification) throws InterruptedException;
44
45     ListenableFuture<?> offerNotification(Notification<?> notification);
46
47     ListenableFuture<?> offerNotification(Notification<?> notification, int timeout, TimeUnit unit)
48         throws InterruptedException;
49
50 }