Merge "Bug 3367 - StatManagerImpl scalable statPolling per stat type on device"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / SalRegistrationManager.java
index 7b48c623faf9e9ff6c4aa3885491268846c2397c..25e29aba26632fdf1c2e0c752f9616de86afd392 100644 (file)
@@ -14,15 +14,15 @@ import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
 import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationQueueWrapper;
-import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionListener;
 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionManager;
 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
@@ -50,14 +50,14 @@ import org.slf4j.LoggerFactory;
  */
 public class SalRegistrationManager implements SessionListener, AutoCloseable {
 
-    private final static Logger LOG = LoggerFactory.getLogger(SalRegistrationManager.class);
-
-    private ProviderContext providerContext;
+    private static final Logger LOG = LoggerFactory.getLogger(SalRegistrationManager.class);
 
     private NotificationProviderService publishService;
 
     private DataBroker dataService;
 
+    private RpcProviderRegistry rpcProviderRegistry;
+
     private SwitchFeaturesUtil swFeaturesUtil;
 
     private ListenerRegistration<SessionListener> sessionListenerRegistration;
@@ -74,16 +74,16 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         this.publishService = publishService;
     }
 
-    public ProviderContext getProviderContext() {
-        return providerContext;
+    public void setDataService(DataBroker dataService) {
+        this.dataService = dataService;
     }
 
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.debug("onSessionInitiated");
-        this.providerContext = session;
-        this.publishService = session.getSALService(NotificationProviderService.class);
-        this.dataService = session.getSALService(DataBroker.class);
-        // We register as listener for Session Manager
+    public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
+        this.rpcProviderRegistry = rpcProviderRegistry;
+    }
+
+    public void init() {
+        LOG.debug("init..");
         sessionListenerRegistration = getSessionManager().registerSessionListener(this);
         getSessionManager().setNotificationProviderService(publishService);
         getSessionManager().setDataBroker(dataService);
@@ -98,10 +98,11 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         NodeRef nodeRef = new NodeRef(identifier);
         NodeId nodeId = nodeIdFromDatapathId(datapathId);
         ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
-        CompositeObjectRegistration<ModelDrivenSwitch> registration = ofSwitch.register(providerContext);
+        CompositeObjectRegistration<ModelDrivenSwitch> registration =
+                ofSwitch.register(rpcProviderRegistry);
         context.setProviderRegistration(registration);
 
-        LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
+        LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId);
 
         NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
                 nodeAdded(ofSwitch, features, nodeRef),
@@ -122,7 +123,7 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
             registration.close();
             context.setProviderRegistration(null);
         }
-        LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId.toString());
+        LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId);
 
         NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
                 nodeRemoved, context.getFeatures().getVersion());
@@ -138,7 +139,7 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
         try {
             builder2.setIpAddress(getIpAddressOf(sw));
         } catch (Exception e) {
-            LOG.warn("IP address of the node {} cannot be obtained: {}", sw.getNodeId(), e.getMessage());
+            LOG.warn("IP address of the node {} cannot be obtained.", sw.getNodeId(), e);
         }
         builder2.setSwitchFeatures(swFeaturesUtil.buildSwitchFeatures(features));
         builder.addAugmentation(FlowCapableNodeUpdated.class, builder2.build());
@@ -148,10 +149,6 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
 
     private static IpAddress getIpAddressOf(ModelDrivenSwitch sw) {
         SessionContext sessionContext = sw.getSessionContext();
-//        if (!sessionContext.isValid()) {
-//            LOG.warn("IP address of the node {} cannot be obtained. Session is not valid.", sw.getNodeId());
-//            return null;
-//        }
         Preconditions.checkNotNull(sessionContext.getPrimaryConductor(),
                 "primary conductor must not be NULL -> " + sw.getNodeId());
         Preconditions.checkNotNull(sessionContext.getPrimaryConductor().getConnectionAdapter(),
@@ -194,7 +191,7 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
 
     public static NodeId nodeIdFromDatapathId(BigInteger datapathId) {
         // FIXME: Convert to textual representation of datapathID
-        String current = datapathId.toString();
+        String current = String.valueOf(datapathId);
         return new NodeId("openflow:" + current);
     }
 
@@ -206,17 +203,10 @@ public class SalRegistrationManager implements SessionListener, AutoCloseable {
     public void close() {
         LOG.debug("close");
         dataService = null;
-        providerContext = null;
+        rpcProviderRegistry = null;
         publishService = null;
         if (sessionListenerRegistration != null) {
             sessionListenerRegistration.close();
         }
     }
-
-    /**
-     * @param providerContext the providerContext to set
-     */
-    public void setProviderContext(ProviderContext providerContext) {
-        this.providerContext = providerContext;
-    }
 }