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