public void Visit(int nestingLevel, int pathId, ContextStatePathValueBinding binding, Object payload, ContextController contextController, ContextControllerInstanceHandle instanceHandle) { var key = new ContextStatePathKey(nestingLevel, pathId, instanceHandle.SubPathId); int maxNestingLevel = _nestedFactories.Length; int contextPartitionOrSubPath = instanceHandle.ContextPartitionOrPathId; if (contextController.Factory.FactoryContext.NestingLevel == maxNestingLevel) { var agentInstances = ControllerAgentInstances.Get(contextController); if (agentInstances == null) { agentInstances = new List <LeafDesc>(); ControllerAgentInstances.Put(contextController, agentInstances); } var value = new ContextStatePathValue(contextPartitionOrSubPath, binding.ToByteArray(payload), instanceHandle.Instances.State); agentInstances.Add(new LeafDesc(key, value)); // generate a nice payload text from the paths of keys var entry = _subcontexts.Get(contextController); var keys = ContextManagerNested.GetTreeCompositeKey(_nestedFactories, payload, entry, _subcontexts); var descriptor = new ContextPartitionDescriptor(contextPartitionOrSubPath, new ContextPartitionIdentifierNested(keys), value.State); AgentInstanceInfo.Put(contextPartitionOrSubPath, descriptor); States.Put(key, value); } else { // handle non-leaf Subpaths.Add(contextPartitionOrSubPath); States.Put(key, new ContextStatePathValue(contextPartitionOrSubPath, binding.ToByteArray(payload), ContextPartitionState.STARTED)); } }
public void ContextPartitionNavigate(ContextControllerInstanceHandle existingHandle, ContextController originator, ContextControllerState controllerState, int exportedCPOrPathId, ContextInternalFilterAddendum filterAddendum, AgentInstanceSelector agentInstanceSelector, byte[] payload, bool isRecoveringResilient) { var entry = _agentInstances.Get(existingHandle.ContextPartitionOrPathId); if (entry == null) { return; } if (entry.State == ContextPartitionState.STOPPED) { entry.State = ContextPartitionState.STARTED; entry.AgentInstances.Clear(); foreach (var statement in _statements) { var instance = StartStatement(existingHandle.ContextPartitionOrPathId, statement.Value, originator, entry.InitPartitionKey, entry.InitContextProperties, false); entry.AgentInstances.Add(instance); } var key = new ContextStatePathKey(1, 0, existingHandle.SubPathId); var value = new ContextStatePathValue(existingHandle.ContextPartitionOrPathId, payload, ContextPartitionState.STARTED); _rootContext.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, key, value); } else { IList <AgentInstance> removed = new List <AgentInstance>(2); IList <AgentInstance> added = new List <AgentInstance>(2); foreach (var agentInstance in entry.AgentInstances) { if (!agentInstanceSelector.Select(agentInstance)) { continue; } // remove StatementAgentInstanceUtil.StopAgentInstanceRemoveResources(agentInstance, null, _servicesContext, false, false); removed.Add(agentInstance); // start var statementDesc = _statements.Get(agentInstance.AgentInstanceContext.StatementId); var instance = StartStatement(existingHandle.ContextPartitionOrPathId, statementDesc, originator, entry.InitPartitionKey, entry.InitContextProperties, isRecoveringResilient); added.Add(instance); if (controllerState.PartitionImportCallback != null) { controllerState.PartitionImportCallback.Existing(existingHandle.ContextPartitionOrPathId, exportedCPOrPathId); } } entry.AgentInstances.RemoveAll(removed); entry.AgentInstances.AddAll(added); } }
public LeafDesc(ContextStatePathKey key, ContextStatePathValue value) { Key = key; Value = value; }
public void ContextPartitionNavigate( ContextControllerInstanceHandle existingHandle, ContextController originator, ContextControllerState controllerState, int exportedCPOrPathId, ContextInternalFilterAddendum filterAddendum, AgentInstanceSelector agentInstanceSelector, byte[] payload, bool isRecoveringResilient) { var nestedHandle = (ContextManagerNestedInstanceHandle)existingHandle; // detect non-leaf var nestingLevel = originator.Factory.FactoryContext.NestingLevel; // starts at 1 for root if (nestingLevel < _nestedContextFactories.Length) { nestedHandle.Controller.ImportContextPartitions( controllerState, exportedCPOrPathId, filterAddendum, agentInstanceSelector); return; } var entry = _subcontexts.Get(originator); if (entry == null) { return; } foreach (var cpEntry in entry.AgentInstances.ToArray()) { if (cpEntry.Value.State == ContextPartitionState.STOPPED) { cpEntry.Value.State = ContextPartitionState.STARTED; entry.AgentInstances.Clear(); foreach (var statement in _statements) { var instance = StartStatement( existingHandle.ContextPartitionOrPathId, statement.Value, originator, cpEntry.Value.InitPartitionKey, entry.InitContextProperties, false); cpEntry.Value.AgentInstances.Add(instance); } var key = new ContextStatePathKey( _nestedContextFactories.Length, originator.PathId, existingHandle.SubPathId); var value = new ContextStatePathValue( existingHandle.ContextPartitionOrPathId, payload, ContextPartitionState.STARTED); originator.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, key, value); } else { IList <AgentInstance> removed = new List <AgentInstance>(2); IList <AgentInstance> added = new List <AgentInstance>(2); var current = cpEntry.Value.AgentInstances; foreach (var agentInstance in current) { if (!agentInstanceSelector.Select(agentInstance)) { continue; } // remove StatementAgentInstanceUtil.StopAgentInstanceRemoveResources( agentInstance, null, _servicesContext, false, false); removed.Add(agentInstance); // start var statementDesc = _statements.Get(agentInstance.AgentInstanceContext.StatementId); var instance = StartStatement( cpEntry.Key, statementDesc, originator, cpEntry.Value.InitPartitionKey, entry.InitContextProperties, false); added.Add(instance); if (controllerState.PartitionImportCallback != null) { controllerState.PartitionImportCallback.Existing( existingHandle.ContextPartitionOrPathId, exportedCPOrPathId); } } current.RemoveAll(removed); current.AddAll(added); } } }
public void UpdateContextPath(String contextName, ContextStatePathKey key, ContextStatePathValue value) { // no action required }