2 * Copyright (c) 2016 Brocade Communications 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.blueprint.ext;
10 import org.opendaylight.mdsal.binding.api.NotificationService;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12 import org.opendaylight.yangtools.yang.binding.NotificationListener;
13 import org.osgi.framework.Bundle;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Blueprint bean corresponding to the "notification-listener" element that registers a NotificationListener
19 * with the NotificationService.
21 * @author Thomas Pantelis
23 public class NotificationListenerBean {
24 private static final Logger LOG = LoggerFactory.getLogger(NotificationListenerBean.class);
25 static final String NOTIFICATION_LISTENER = "notification-listener";
27 private Bundle bundle;
28 private NotificationService notificationService;
29 private NotificationListener notificationListener;
30 private ListenerRegistration<?> registration;
32 public void setNotificationService(final NotificationService notificationService) {
33 this.notificationService = notificationService;
36 public void setNotificationListener(final NotificationListener notificationListener) {
37 this.notificationListener = notificationListener;
40 public void setBundle(final Bundle bundle) {
45 LOG.debug("{}: init - registering NotificationListener {}", bundle.getSymbolicName(), notificationListener);
47 registration = notificationService.registerNotificationListener(notificationListener);
50 public void destroy() {
51 if (registration != null) {
52 LOG.debug("{}: destroy - closing ListenerRegistration {}", bundle.getSymbolicName(), notificationListener);
55 LOG.debug("{}: destroy - listener was not registered", bundle.getSymbolicName());