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