Revert "Remove support for actions/rpc/notifications"
[controller.git] / opendaylight / blueprint / src / main / java / org / opendaylight / controller / blueprint / ext / NotificationListenerBean.java
diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/NotificationListenerBean.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/NotificationListenerBean.java
new file mode 100644 (file)
index 0000000..55be59c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.blueprint.ext;
+
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Blueprint bean corresponding to the "notification-listener" element that registers a NotificationListener
+ * with the NotificationService.
+ *
+ * @author Thomas Pantelis
+ */
+public class NotificationListenerBean {
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationListenerBean.class);
+    static final String NOTIFICATION_LISTENER = "notification-listener";
+
+    private Bundle bundle = null;
+    private NotificationService notificationService = null;
+    private NotificationListener notificationListener = null;
+    private ListenerRegistration<?> registration = null;
+
+    public void setNotificationService(final NotificationService notificationService) {
+        this.notificationService = notificationService;
+    }
+
+    public void setNotificationListener(final NotificationListener notificationListener) {
+        this.notificationListener = notificationListener;
+    }
+
+    public void setBundle(final Bundle bundle) {
+        this.bundle = bundle;
+    }
+
+    public void init() {
+        LOG.debug("{}: init - registering NotificationListener {}", bundle.getSymbolicName(), notificationListener);
+
+        registration = notificationService.registerNotificationListener(notificationListener);
+    }
+
+    public void destroy() {
+        if (registration != null) {
+            LOG.debug("{}: destroy - closing ListenerRegistration {}", bundle.getSymbolicName(), notificationListener);
+            registration.close();
+        } else {
+            LOG.debug("{}: destroy - listener was not registered", bundle.getSymbolicName());
+        }
+    }
+}