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>
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.
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.
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
41 * service.registerNotificationListener(Notification.class, listener);
44 * <h3>Dispatch Listener</h3>
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.
55 * <h4>Dispatch Listener Example</h4>
58 * Lets assume we have following YANG model:
64 * notification start {
75 * The generated interface will be:
77 * public interface ExampleListener extends NotificationListener {
78 * void onStart(Start notification);
79 * void onStop(Stop notification);
82 * The following defines an implementation of the generated interface:
84 * public class MyExampleListener implements ExampleListener {
85 * public void onStart(Start notification) {
89 * public void onStop(Stop notification) {
94 * The implementation is registered as follows:
96 * MyExampleListener listener = new MyExampleListener();
97 * ListenerRegistration<NotificationListener> reg = service.registerNotificationListener( listener );
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.
102 * @deprecated Please use {@link org.opendaylight.controller.md.sal.binding.api.NotificationService} instead.
105 public interface NotificationService extends BindingAwareService {
107 * Registers a generic listener implementation for a specified notification type.
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.
114 <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
115 Class<T> notificationType, NotificationListener<T> listener);
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.
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.
126 ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
127 org.opendaylight.yangtools.yang.binding.NotificationListener listener);