Bug-2827: role switch proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / openflow / common / config / impl / rev140326 / ConfigurableOpenFlowProviderModule.java
index 9e7ecbbed197fb11d9684ed77c44eca1082f1b7f..fdd9470ba7b3d69d01a1117df17f70b2232d86b2 100644 (file)
@@ -10,7 +10,8 @@
 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326;
 
 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
-import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Objects;
 
 /**
 *
@@ -18,7 +19,6 @@ import org.osgi.framework.BundleContext;
 public final class ConfigurableOpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.AbstractConfigurableOpenFlowProviderModule {
 
     private OpenflowPluginProvider pluginProvider;
-    private BundleContext bundleContext;
 
     /**
      * @param identifier
@@ -48,20 +48,29 @@ public final class ConfigurableOpenFlowProviderModule extends org.opendaylight.y
     @Override
     public java.lang.AutoCloseable createInstance() {
         pluginProvider =  new OpenflowPluginProvider();
-        pluginProvider.setContext(bundleContext);
         pluginProvider.setBroker(getBindingAwareBrokerDependency());
         pluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
+        pluginProvider.setRole(getRole());
         pluginProvider.initialization();
         return pluginProvider;
     }
 
-    /**
-     * @param bundleContext the bundleContext to set, see {@link OpenflowPluginProvider#setContext(BundleContext)}
-     *
-     * @deprecated we should avoid osgi specific stuff .. once,
-     */
-    @Deprecated
-    public void setBundleContext(BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
+    @Override
+    public boolean canReuseInstance(
+            AbstractConfigurableOpenFlowProviderModule oldModule) {
+        // we can reuse if only the role field changed
+        boolean noChangeExceptRole = true;
+        noChangeExceptRole &= getBindingAwareBrokerDependency().equals(oldModule.getBindingAwareBrokerDependency());
+        noChangeExceptRole &= getOpenflowSwitchConnectionProviderDependency().equals(oldModule.getOpenflowSwitchConnectionProviderDependency());
+        return noChangeExceptRole;
+    }
+
+    @Override
+    public AutoCloseable reuseInstance(AutoCloseable oldInstance) {
+        OpenflowPluginProvider recycled = (OpenflowPluginProvider) super.reuseInstance(oldInstance);
+        // change role if different
+        recycled.fireRoleChange(Objects.firstNonNull(getRole(), getRole()));
+
+        return recycled;
     }
 }