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).
24 * <h3>Generic Listener</h3>
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.
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.
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
37 * service.registerNotificationListener(Notification.class, listener);
40 * <h3>Dispatch Listener</h3>
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)}
50 * <h5>Dispatch Listener Example</h5>
52 * Lets assume we have following YANG model:
58 * notification start {
68 * The generated interface will be:
70 * public interface ExampleListener extends NotificationListener {
71 * void onStart(Start notification);
72 * void onStop(Stop notification);
75 * The following defines an implementation of the generated interface:
77 * public class MyExampleListener implements ExampleListener {
78 * public void onStart(Start notification) {
82 * public void onStop(Stop notification) {
87 * The implementation is registered as follows:
89 * MyExampleListener listener = new MyExampleListener();
90 * ListenerRegistration<NotificationListener> reg = service.registerNotificationListener( listener );
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.
95 public interface NotificationService extends BindingAwareService {
97 * Registers a generic listener implementation for a specified notification type.
99 * @param notificationType the YANG-generated interface of the notification type.
100 * @param listener the listener implementation that will receive notifications.
101 * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
102 * by invoking the {@link ListenerRegistration#close()} method when no longer needed.
104 <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(
105 Class<T> notificationType, NotificationListener<T> listener);
108 * Registers a listener which implements a YANG-generated notification interface derived from
109 * {@link org.opendaylight.yangtools.yang.binding.NotificationListener}.
110 * The listener is registered for all notifications present in the implemented interface.
112 * @param listener the listener implementation that will receive notifications.
113 * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
114 * by invoking the {@link ListenerRegistration#close()} method when no longer needed.
116 ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(
117 org.opendaylight.yangtools.yang.binding.NotificationListener listener);