2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.api;
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.yang.binding.Notification;
14 * Notification broker which allows clients to subscribe for and publish YANG-modeled notifications.
17 * Two styles of listeners are supported:
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).
25 * <h3>Generic Listener</h3>
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.
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.
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
38 * service.registerNotificationListener(Notification.class, listener);
41 * <h3>Dispatch Listener</h3>
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)}
51 * <h4>Dispatch Listener Example</h4>
53 * Lets assume we have following YANG model:
59 * notification start {
69 * The generated interface will be:
71 * public interface ExampleListener extends NotificationListener {
72 * void onStart(Start notification);
73 * void onStop(Stop notification);
76 * The following defines an implementation of the generated interface:
78 * public class MyExampleListener implements ExampleListener {
79 * public void onStart(Start notification) {
83 * public void onStop(Stop notification) {
88 * The implementation is registered as follows:
90 * MyExampleListener listener = new MyExampleListener();
91 * ListenerRegistration<NotificationListener> reg = service.registerNotificationListener( listener );
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.
96 * @deprecated Please use {@link org.opendaylight.controller.md.sal.binding.api.NotificationService} instead.
99 public interface NotificationService extends BindingAwareService {
101 * Registers a generic listener implementation for a specified notification type.
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.
108 <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
109 Class<T> notificationType, NotificationListener<T> listener);
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.
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.
120 ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
121 org.opendaylight.yangtools.yang.binding.NotificationListener listener);