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 d518391baf761737ae82f6261bbef6f33883dcc9..fbc87643b57460967695d5eee5baccd98911b2f1 100644 (file)
@@ -9,8 +9,12 @@
 */
 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326;
 
+import javax.management.ObjectName;
+
 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
 
+import com.google.common.base.MoreObjects;
+
 /**
 *
 */
@@ -48,7 +52,31 @@ public final class ConfigurableOpenFlowProviderModule extends org.opendaylight.y
         pluginProvider =  new OpenflowPluginProvider();
         pluginProvider.setBroker(getBindingAwareBrokerDependency());
         pluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
+        pluginProvider.setRole(getRole());
         pluginProvider.initialization();
         return pluginProvider;
     }
+
+    @Override
+    public boolean canReuseInstance(
+            AbstractConfigurableOpenFlowProviderModule oldModule) {
+        // we can reuse if only the role field changed
+        boolean noChangeExceptRole = true;
+        noChangeExceptRole &= dependencyResolver.canReuseDependency(
+                getBindingAwareBroker(), bindingAwareBrokerJmxAttribute);
+        for (ObjectName ofSwitchProvider : getOpenflowSwitchConnectionProvider()) {
+            noChangeExceptRole &= dependencyResolver.canReuseDependency(
+                    ofSwitchProvider, openflowSwitchConnectionProviderJmxAttribute); 
+        }
+        return noChangeExceptRole;
+    }
+
+    @Override
+    public AutoCloseable reuseInstance(AutoCloseable oldInstance) {
+        OpenflowPluginProvider recycled = (OpenflowPluginProvider) super.reuseInstance(oldInstance);
+        // change role if different
+        recycled.fireRoleChange(MoreObjects.firstNonNull(getRole(), getRole()));
+
+        return recycled;
+    }
 }