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