Bump upstreams
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / LearningSwitchManagerSimpleImpl.java
index b0195e6ab6e4ff68a5f443437cbb65ce124d7b09..26c582bbc65706e46e646aefb2f4e56deb8954c7 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,16 +7,17 @@
  */
 package org.opendaylight.openflowplugin.learningswitch;
 
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
+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;
@@ -24,7 +25,7 @@ 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.
@@ -32,53 +33,56 @@ import org.slf4j.LoggerFactory;
  * corresponding MACs)</li>
  * </ul>
  */
-public class LearningSwitchManagerSimpleImpl implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
-
+public class LearningSwitchManagerSimpleImpl
+        implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
     private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerSimpleImpl.class);
-    private NotificationService notificationService;
+
+    private NotificationService notificationService = null;
     private PacketProcessingService packetProcessingService;
-    private DataBroker data;
-    private Registration packetInRegistration;
-    private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
+    private DataBroker data = null;
+    private Registration packetInRegistration = null;
+    private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration = null;
 
     /**
+     * Sets the NotificationService.
+     *
      * @param notificationService the notificationService to set
      */
     @Override
-    public void setNotificationService(NotificationService notificationService) {
+    public void setNotificationService(final NotificationService notificationService) {
         this.notificationService = notificationService;
     }
 
     /**
+     * Sets the PacketProcessingService.
+     *
      * @param packetProcessingService the packetProcessingService to set
      */
     @Override
     public void setPacketProcessingService(
-            PacketProcessingService packetProcessingService) {
+            final PacketProcessingService packetProcessingService) {
         this.packetProcessingService = packetProcessingService;
     }
 
     /**
-     * @param data the data to set
+     * Sets the DataBroker.
      */
     @Override
-    public void setDataBroker(DataBroker data) {
-        this.data = data;
+    public void setDataBroker(final 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);
@@ -86,30 +90,24 @@ public class LearningSwitchManagerSimpleImpl implements DataTreeChangeListenerRe
                 .child(Node.class)
                 .augmentation(FlowCapableNode.class)
                 .child(Table.class);
-        final DataTreeIdentifier<Table> dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
+        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.warn("closing packetInRegistration failed: {}", e.getMessage());
-            LOG.debug("closing packetInRegistration failed..", e);
-        }
-        try {
-            dataTreeChangeListenerRegistration.close();
-        } catch (Exception e) {
-            LOG.warn("failed to close dataTreeChangeListenerRegistration: {}", e.getMessage());
-            LOG.debug("failed to close dataTreeChangeListenerRegistration..", e);
-        }
+
+        packetInRegistration.close();
+
+        dataTreeChangeListenerRegistration.close();
+
         LOG.debug("stop() <--");
     }