Annotate mdsal-binding-api with @NonNull
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / NotificationService.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.mdsal.binding.api;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12 import org.opendaylight.yangtools.yang.binding.NotificationListener;
13
14 /**
15  * Notification broker which allows clients to subscribe for and publish YANG-modeled notifications.
16  *
17  *<p>
18  * Each YANG module which defines notifications results in a generated interface
19  * <code>{ModuleName}Listener</code> which handles all the notifications defined in the YANG model.
20  * Each notification type translates to a specific method of the form
21  * <code>on{NotificationType}</code> on the generated interface. The generated interface also
22  * extends the {@link org.opendaylight.yangtools.yang.binding.NotificationListener} interface and
23  * implementations are registered using
24  * {@link #registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener)}
25  * method.
26  *
27  * <b>Dispatch Listener Example</b>
28  *
29  * <p>
30  * Lets assume we have following YANG model:
31  *
32  * <pre>
33  * module example {
34  *      ...
35  *
36  *      notification start {
37  *          ...
38  *      }
39  *
40  *      notification stop {
41  *           ...
42  *      }
43  * }
44  * </pre>
45  *
46  * <p>
47  * The generated interface will be:
48  *
49  * <pre>
50  * public interface ExampleListener extends NotificationListener {
51  *     void onStart(Start notification);
52  *
53  *     void onStop(Stop notification);
54  * }
55  * </pre>
56  *
57  * <p>
58  * The following defines an implementation of the generated interface:
59  *
60  * <pre>
61  * public class MyExampleListener implements ExampleListener {
62  *     public void onStart(Start notification) {
63  *         // do something
64  *     }
65  *
66  *     public void onStop(Stop notification) {
67  *         // do something
68  *     }
69  * }
70  * </pre>
71  *
72  * <p>
73  * The implementation is registered as follows:
74  *
75  * <pre>
76  * MyExampleListener listener = new MyExampleListener();
77  * ListenerRegistration&lt;NotificationListener&gt; reg = service.registerNotificationListener(listener);
78  * </pre>
79  *
80  * <p>
81  * The <code>onStart</code> method will be invoked when someone publishes a <code>Start</code>
82  * notification and the <code>onStop</code> method will be invoked when someone publishes a
83  * <code>Stop</code> notification.
84  */
85 public interface NotificationService extends BindingService {
86     /**
87      * Registers a listener which implements a YANG-generated notification interface derived from
88      * {@link NotificationListener}. The listener is registered for all notifications present in
89      * the implemented interface.
90      *
91      * <p>
92      * @param listener the listener implementation that will receive notifications.
93      * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
94      *         by invoking the {@link ListenerRegistration#close()} method when no longer needed.
95      */
96     <T extends NotificationListener> @NonNull ListenerRegistration<T> registerNotificationListener(@NonNull T listener);
97 }