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