Don't use NotificationListener (NodeRegistration)
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / dto / NodeRegistration.java
index e802091b5e2d7fcaa1997dfa5975e1914e649231..61fd4b7f48c3e9a96494e402ae5c6199ad94b925 100644 (file)
  */
 package org.opendaylight.transportpce.networkmodel.dto;
 
-import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.OrgOpenroadmLldpListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev161014.OrgOpenroadmTcaListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.transportpce.common.StringConstants;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener;
+import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener710;
+import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener;
+import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener710;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener710;
+import org.opendaylight.transportpce.networkmodel.listeners.TcaListener;
+import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.TcaListener710;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NodeRegistration {
-
+    private static final Logger LOG = LoggerFactory.getLogger(NodeRegistration.class);
     private final String nodeId;
-    private final ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        accessDeOperationasNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration;
-
-    public NodeRegistration(String nodeId,
-            ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmDeOperationsListener> accessDeOperationasNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration) {
+    private final String nodeVersion;
+    private final NotificationService notificationService;
+    private final DataBroker dataBroker;
+    private final PortMapping portMapping;
+    private final List<Registration> listeners;
+
+    public NodeRegistration(String nodeId, String nodeVersion, NotificationService notificationService,
+            DataBroker dataBroker, PortMapping portMapping) {
         this.nodeId = nodeId;
-        this.accessAlarmNotificationListenerRegistration = accessAlarmNotificationListenerRegistration;
-        this.accessDeOperationasNotificationListenerRegistration = accessDeOperationasNotificationListenerRegistration;
-        this.accessDeviceNotificationListenerRegistration = accessDeviceNotificationListenerRegistration;
-        this.accessLldpNotificationListenerRegistration = accessLldpNotificationListenerRegistration;
-        this.accessTcaNotificationListenerRegistration = accessTcaNotificationListenerRegistration;
+        this.nodeVersion = nodeVersion;
+        this.notificationService = notificationService;
+        this.dataBroker = dataBroker;
+        this.portMapping = portMapping;
+        listeners = new ArrayList<Registration>();
     }
 
-    public String getNodeId() {
-        return nodeId;
+    public void registerListeners() {
+        switch (this.nodeVersion) {
+            case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
+                registerListeners121();
+                break;
+            case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
+                registerListeners221();
+                break;
+            case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
+                registerListeners710();
+                break;
+            default:
+                LOG.debug("Unable to register listeners - unknown device version for {}", this.nodeId);
+                break;
+        }
     }
 
-    public ListenerRegistration<OrgOpenroadmAlarmListener> getAccessAlarmNotificationListenerRegistration() {
-        return accessAlarmNotificationListenerRegistration;
+    public void unregisterListeners() {
+        LOG.info("Unregistering notification listeners for node: {}", this.nodeId);
+        for (Registration listenerRegistration : listeners) {
+            listenerRegistration.close();
+        }
     }
 
-    public ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        getAccessDeOperationasNotificationListenerRegistration() {
-        return accessDeOperationasNotificationListenerRegistration;
-    }
+    private void registerListeners121() {
+        AlarmNotificationListener alarmListener = new AlarmNotificationListener(this.dataBroker);
+        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(alarmListener.getCompositeListener()));
 
-    public ListenerRegistration<OrgOpenroadmDeviceListener> getAccessDeviceNotificationListenerRegistration() {
-        return accessDeviceNotificationListenerRegistration;
-    }
+        DeOperationsListener deOperationsListener = new DeOperationsListener();
+        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deOperationsListener.getCompositeListener()));
+
+        DeviceListener121 deviceListener = new DeviceListener121(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deviceListener.getCompositeListener()));
 
-    public ListenerRegistration<OrgOpenroadmLldpListener> getAccessLldpNotificationListenerRegistration() {
-        return accessLldpNotificationListenerRegistration;
+        TcaListener tcaListener = new TcaListener();
+        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(tcaListener.getCompositeListener()));
     }
 
-    public ListenerRegistration<OrgOpenroadmTcaListener> getAccessTcaNotificationListenerRegistration() {
-        return accessTcaNotificationListenerRegistration;
+    private void registerListeners221() {
+        AlarmNotificationListener221 alarmListener = new AlarmNotificationListener221(dataBroker);
+        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(alarmListener.getCompositeListener()));
+
+        DeOperationsListener221 deOperationsListener = new DeOperationsListener221();
+        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deOperationsListener.getCompositeListener()));
+
+        DeviceListener221 deviceListener = new DeviceListener221(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deviceListener.getCompositeListener()));
+
+        TcaListener221 tcaListener = new TcaListener221();
+        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(tcaListener.getCompositeListener()));
     }
 
+    private void registerListeners710() {
+        AlarmNotificationListener710 alarmListener = new AlarmNotificationListener710(dataBroker);
+        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(alarmListener.getCompositeListener()));
+
+        DeOperationsListener710 deOperationsListener = new DeOperationsListener710();
+        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deOperationsListener.getCompositeListener()));
+
+        DeviceListener710 deviceListener = new DeviceListener710(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(deviceListener.getCompositeListener()));
+
+        TcaListener710 tcaListener = new TcaListener710();
+        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
+        listeners.add(notificationService.registerCompositeListener(tcaListener.getCompositeListener()));
+    }
 }