Mastershipchange service implementation.
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / lifecycle / ContextChainImpl.java
index 1a4b0ff908f25c35a30b2e61542e97f2079b67f4..6a17898ea5675a492b025b66477715b570a4c036 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMaster
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainState;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainStateListener;
+import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
@@ -216,6 +217,7 @@ public class ContextChainImpl implements ContextChain {
             case RPC_REGISTRATION:
                 LOG.debug("Device {}, RPC registration OK.", deviceInfo);
                 this.rpcRegistration.set(true);
+                break;
             case INITIAL_FLOW_REGISTRY_FILL:
                 // Flow registry fill is not mandatory to work as a master
                 LOG.debug("Device {}, initial registry filling OK.", deviceInfo);
@@ -244,6 +246,23 @@ public class ContextChainImpl implements ContextChain {
         return ContextState.TERMINATION.equals(state);
     }
 
+    @Override
+    public boolean isPrepared() {
+        return this.initialGathering.get() &&
+                this.masterStateOnDevice.get() &&
+                this.rpcRegistration.get();
+    }
+
+    @Override
+    public boolean continueInitializationAfterReconciliation() {
+        return isMastered(ContextChainMastershipState.INITIAL_SUBMIT) && contexts.stream()
+                .filter(StatisticsContext.class::isInstance)
+                .map(StatisticsContext.class::cast)
+                .findAny()
+                .map(StatisticsContext::initialSubmitAfterReconciliation)
+                .orElse(false);
+    }
+
     @Override
     public boolean addAuxiliaryConnection(@Nonnull ConnectionContext connectionContext) {
         return (connectionContext.getFeatures().getAuxiliaryId() != 0)