8f3e1470e48e6c6a109781081193b3d35fd3f01f
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / sal / binding / api / NotificationService.java
1 /*
2  * Copyright (c) 2013 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.sal.binding.api;
9
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.yang.binding.Notification;
12
13 /**
14  * Notification broker which allows clients to subscribe for and publish YANG-modeled notifications.
15  *
16  *<p>
17  * Two styles of listeners are supported:
18  * <ul>
19  * <li>Generic listener</li>
20  * <li>Dispatch listener - listener, which implements <code>{ModelName}Listener</code> interface,
21  * which has dispatch methods for each defined notification. Methods are invoked based on notification type (class).
22  * </li>
23  * </ul>
24  *
25  * <h3>Generic Listener</h3>
26  *
27  * <p>
28  * A generic listener implements the {@link NotificationListener} interface which has one callback method
29  * <code>onNotification</code> that is invoked for any notification type the listener is subscribed to.
30  *
31  * <p>
32  * A generic listener is subscribed using the {@link #registerNotificationListener(Class, NotificationListener)}
33  * method by which you specify the type of notification to receive. A generic listener may be registered for
34  * multiple notification types via multiple subscriptions.
35  *
36  * <p>
37  * Generic listeners allow for a more flexible approach, allowing you to subscribe for just
38  * one type of notification from a YANG model. You could also have a general subscription
39  * for all notification in the system via
40  * <pre>
41  *   service.registerNotificationListener(Notification.class, listener);
42  * </pre>
43  *
44  * <h3>Dispatch Listener</h3>
45  *
46  * <p>
47  * A dispatch listener implements a YANG-generated module interface <code>{ModuleName}Listener</code>
48  * which handles all the notifications defined in the YANG model. Each notification type translates to
49  * a specific method of the form <code>on{NotificationType}</code> on the generated interface.
50  * The generated interface also extends the
51  * {@link org.opendaylight.yangtools.yang.binding.NotificationListener} interface and implementations
52  * are registered using
53  * {@link #registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener)} method.
54  *
55  * <h4>Dispatch Listener Example</h4>
56  *
57  * <p>
58  * Lets assume we have following YANG model:
59  *
60  * {@code
61  * module example {
62  *      ...
63  *
64  *      notification start {
65  *          ...
66  *      }
67  *
68  *      notification stop {
69  *           ...
70  *      }
71  * }
72  * }
73  *
74  * <p>
75  * The generated interface will be:
76  * {@code
77  *  public interface ExampleListener extends NotificationListener {
78  *      void onStart(Start notification);
79  *      void onStop(Stop notification);
80  *  }
81  * }
82  * The following defines an implementation of the generated interface:
83  * {@code
84  *  public class MyExampleListener implements ExampleListener {
85  *      public void onStart(Start notification) {
86  *          // do something
87  *      }
88  *
89  *      public void onStop(Stop notification) {
90  *          // do something
91  *      }
92  *  }
93  * }
94  * The implementation is registered as follows:
95  * {@code
96  *  MyExampleListener listener = new MyExampleListener();
97  *  ListenerRegistration<NotificationListener> reg = service.registerNotificationListener( listener );
98  * }
99  * The <code>onStart</code> method will be invoked when someone publishes a <code>Start</code> notification and
100  * the <code>onStop</code> method will be invoked when someone publishes a <code>Stop</code> notification.
101  *
102  * @deprecated Please use {@link org.opendaylight.controller.md.sal.binding.api.NotificationService} instead.
103  */
104 @Deprecated
105 public interface NotificationService extends BindingAwareService {
106     /**
107      * Registers a generic listener implementation for a specified notification type.
108      *
109      * @param notificationType the YANG-generated interface of the notification type.
110      * @param listener the listener implementation that will receive notifications.
111      * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
112      *         by invoking the {@link ListenerRegistration#close()} method when no longer needed.
113      */
114     <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
115             Class<T> notificationType, NotificationListener<T> listener);
116
117     /**
118      * Registers a listener which implements a YANG-generated notification interface derived from
119      * {@link org.opendaylight.yangtools.yang.binding.NotificationListener}.
120      * The listener is registered for all notifications present in the implemented interface.
121      *
122      * @param listener the listener implementation that will receive notifications.
123      * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
124      *         by invoking the {@link ListenerRegistration#close()} method when no longer needed.
125      */
126     ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
127             org.opendaylight.yangtools.yang.binding.NotificationListener listener);
128 }