Revert "WIP: Bump upstreams"
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / LearningSwitchManagerSimpleImpl.java
index 78169fe8d03e2ff160fb81e3fdaab8e371812c10..d624643a45057ae9007f80c7202960bf5e37e88f 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -7,45 +7,45 @@
  */
 package org.opendaylight.openflowplugin.learningswitch;
 
-import org.opendaylight.controller.sal.binding.api.NotificationService;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens to packetIn notification and 
+ * Listens to packetIn notification.
  * <ul>
  * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
- * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port. 
- * If target MAC address is already bound then a flow is created (for direct communication between 
+ * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
+ * If target MAC address is already bound then a flow is created (for direct communication between
  * corresponding MACs)</li>
  * </ul>
  */
-public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegistrationHolder,
-        LearningSwitchManager {
-    
-    protected static final Logger LOG = LoggerFactory
-            .getLogger(LearningSwitchManagerSimpleImpl.class);
+public class LearningSwitchManagerSimpleImpl
+        implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
 
+    private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerSimpleImpl.class);
     private NotificationService notificationService;
     private PacketProcessingService packetProcessingService;
-    private DataBrokerService data;
-
+    private DataBroker data;
     private Registration packetInRegistration;
+    private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
 
-    private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration; 
-    
     /**
+     * Sets the NotificationService.
+     *
      * @param notificationService the notificationService to set
      */
     @Override
@@ -54,6 +54,8 @@ public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegist
     }
 
     /**
+     * Sets the PacketProcessingService.
+     *
      * @param packetProcessingService the packetProcessingService to set
      */
     @Override
@@ -61,63 +63,56 @@ public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegist
             PacketProcessingService packetProcessingService) {
         this.packetProcessingService = packetProcessingService;
     }
-    
+
     /**
-     * @param data the data to set
+     * Sets the DataBroker.
      */
     @Override
-    public void setDataBroker(DataBrokerService data) {
-        this.data = data;
+    public void setDataBroker(DataBroker broker) {
+        data = broker;
     }
 
     /**
-     * starting learning switch
+     * Starts learning switch.
      */
     @Override
     public void start() {
         LOG.debug("start() -->");
         FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
 
-        LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl();
-        learningSwitchHandler.setRegistrationPublisher(this);
-        learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
-        learningSwitchHandler.setPacketProcessingService(packetProcessingService);
-        packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
-        
+        LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl(dataStoreAccessor,
+                packetProcessingService, this);
+        packetInRegistration = notificationService.registerListener(PacketReceived.class, learningSwitchHandler);
+
         WakeupOnNode wakeupListener = new WakeupOnNode();
         wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
-        dataChangeListenerRegistration = data.registerDataChangeListener(
-                InstanceIdentifier.builder(Nodes.class)
-                    .child(Node.class)
-                    .augmentation(FlowCapableNode.class)
-                    .child(Table.class).toInstance(),
-                wakeupListener);
+        final InstanceIdentifier<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
+                .child(Node.class)
+                .augmentation(FlowCapableNode.class)
+                .child(Table.class);
+        final DataTreeIdentifier<Table> dataTreeIdentifier =
+                DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
+        dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
         LOG.debug("start() <--");
     }
-    
+
     /**
-     * stopping learning switch 
+     * Stops the learning switch.
      */
     @Override
     public void stop() {
         LOG.debug("stop() -->");
         //TODO: remove flow (created in #start())
-        try {
-            packetInRegistration.close();
-        } catch (Exception e) {
-            LOG.error(e.getMessage(), e);
-        }
-        try {
-            dataChangeListenerRegistration.close();
-        } catch (Exception e) {
-            LOG.error(e.getMessage(), e);
-        }
+
+        packetInRegistration.close();
+
+        dataTreeChangeListenerRegistration.close();
+
         LOG.debug("stop() <--");
     }
-    
-   
+
     @Override
-    public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
-        return dataChangeListenerRegistration;
+    public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
+        return dataTreeChangeListenerRegistration;
     }
 }