2 * Copyright (c) 2014 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.mdsal.binding.api;
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12 import org.opendaylight.yangtools.yang.binding.NotificationListener;
15 * Notification broker which allows clients to subscribe for and publish YANG-modeled notifications.
18 * Each YANG module which defines notifications results in a generated interface
19 * <code>{ModuleName}Listener</code> which handles all the notifications defined in the YANG model.
20 * Each notification type translates to a specific method of the form
21 * <code>on{NotificationType}</code> on the generated interface. The generated interface also
22 * extends the {@link org.opendaylight.yangtools.yang.binding.NotificationListener} interface and
23 * implementations are registered using
24 * {@link #registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener)}
27 * <b>Dispatch Listener Example</b>
30 * Lets assume we have following YANG model:
36 * notification start {
47 * The generated interface will be:
50 * public interface ExampleListener extends NotificationListener {
51 * void onStart(Start notification);
53 * void onStop(Stop notification);
58 * The following defines an implementation of the generated interface:
61 * public class MyExampleListener implements ExampleListener {
62 * public void onStart(Start notification) {
66 * public void onStop(Stop notification) {
73 * The implementation is registered as follows:
76 * MyExampleListener listener = new MyExampleListener();
77 * ListenerRegistration<NotificationListener> reg = service.registerNotificationListener(listener);
81 * The <code>onStart</code> method will be invoked when someone publishes a <code>Start</code>
82 * notification and the <code>onStop</code> method will be invoked when someone publishes a
83 * <code>Stop</code> notification.
85 public interface NotificationService extends BindingService {
87 * Registers a listener which implements a YANG-generated notification interface derived from
88 * {@link NotificationListener}. The listener is registered for all notifications present in
89 * the implemented interface.
92 * @param listener the listener implementation that will receive notifications.
93 * @return a {@link ListenerRegistration} instance that should be used to unregister the listener
94 * by invoking the {@link ListenerRegistration#close()} method when no longer needed.
96 <T extends NotificationListener> @NonNull ListenerRegistration<T> registerNotificationListener(@NonNull T listener);