public void ContextPartitionRecursiveVisit( IntSeqKey controllerPath, int subpathOrAgentInstanceId, ContextController originator, ContextPartitionVisitor visitor, ContextPartitionSelector[] selectorPerLevel) { if (controllerPath.Length != originator.Factory.FactoryEnv.NestingLevel - 1) { throw new IllegalStateException("Unrecognized controller path"); } var nestingLevel = originator.Factory.FactoryEnv.NestingLevel; // starts at 1 for root if (nestingLevel < ContextControllers.Length) { var childController = ContextControllers[nestingLevel]; var subPath = controllerPath.AddToEnd(subpathOrAgentInstanceId); childController.VisitSelectedPartitions( subPath, selectorPerLevel[nestingLevel], visitor, selectorPerLevel); return; } visitor.Add(subpathOrAgentInstanceId, originator.Factory.FactoryEnv.NestingLevel); }
public void HashAddPartition( IntSeqKey controllerPath, int value, int subpathIdOrCPId) { _optionalHashes.Put(controllerPath.AddToEnd(value), subpathIdOrCPId); }
public int HashGetSubpathOrCPId( IntSeqKey controllerPath, int hash) { if (_optionalHashes == null) { var mgmtInfo = _mgmt.Get(controllerPath); return mgmtInfo.SubpathOrCPIdsPreallocate[hash]; } if (_optionalHashes.TryGetValue(controllerPath.AddToEnd(hash), out var found)) { return found; } return -1; }
public void TransferRecursive( IntSeqKey controllerPath, int subpathOrAgentInstanceId, ContextController originator, AgentInstanceTransferServices xfer) { if (controllerPath.Length != originator.Factory.FactoryEnv.NestingLevel - 1) { throw new IllegalStateException("Unrecognized controller path"); } var nestingLevel = originator.Factory.FactoryEnv.NestingLevel; // starts at 1 for root if (nestingLevel >= ContextControllers.Length) { return; } var childController = ContextControllers[nestingLevel]; var subPath = controllerPath.AddToEnd(subpathOrAgentInstanceId); childController.Transfer(subPath, nestingLevel < ContextControllers.Length - 1, xfer); }
internal IList<AgentInstance> InstantiateAndActivateEndCondition( IntSeqKey controllerPath, EventBean optionalTriggeringEvent, IDictionary<string, object> optionalTriggeringPattern, IDictionary<string, object> optionalPatternForInclusiveEval, ContextControllerConditionNonHA startCondition) { var subpathId = initTermSvc.MgmtUpdIncSubpath(controllerPath); var endConditionPath = controllerPath.AddToEnd(subpathId); var partitionKeys = initTermSvc.MgmtGetParentPartitionKeys(controllerPath); var endCondition = ContextControllerConditionFactory.GetEndpoint( endConditionPath, partitionKeys, factory.initTermSpec.EndCondition, this, this, false); endCondition.Activate(optionalTriggeringEvent, this); var partitionKey = ContextControllerInitTermUtil.BuildPartitionKey( optionalTriggeringEvent, optionalTriggeringPattern, endCondition, this); var result = realization.ContextPartitionInstantiate( controllerPath, subpathId, this, optionalTriggeringEvent, optionalPatternForInclusiveEval, partitionKeys, partitionKey); var subpathIdOrCPId = result.SubpathOrCPId; initTermSvc.EndCreate(endConditionPath, subpathIdOrCPId, endCondition, partitionKey); return result.AgentInstances; }
public bool HashHasSeenPartition( IntSeqKey controllerPath, int value) { return _optionalHashes.ContainsKey(controllerPath.AddToEnd(value)); }
public void MatchFound( ContextControllerDetailKeyedItem item, EventBean theEvent, IntSeqKey controllerPath, string optionalInitCondAsName) { if (controllerPath.Length != Factory.FactoryEnv.NestingLevel - 1) { throw new IllegalStateException("Unrecognized controller path"); } var getterKey = item.Getter.Get(theEvent); var exists = keyedSvc.KeyHasSeen(controllerPath, getterKey); if (exists || theEvent == LastTerminatingEvent) { // if all-matches is more than one, the termination has also fired return; } LastTerminatingEvent = null; var partitionKey = getterKey; if (KeyedFactory.KeyedSpec.HasAsName) { partitionKey = new ContextControllerKeyedPartitionKeyWInit( getterKey, optionalInitCondAsName, optionalInitCondAsName == null ? null : theEvent); } var parentPartitionKeys = keyedSvc.MgmtGetPartitionKeys(controllerPath); // get next subpath id var subpathId = keyedSvc.MgmtGetIncSubpath(controllerPath); // instantiate var result = realization.ContextPartitionInstantiate( controllerPath, subpathId, this, theEvent, null, parentPartitionKeys, partitionKey); var subpathIdOrCPId = result.SubpathOrCPId; // handle termination filter ContextControllerConditionNonHA terminationCondition = null; if (KeyedFactory.KeyedSpec.OptionalTermination != null) { var conditionPath = controllerPath.AddToEnd(subpathIdOrCPId); terminationCondition = ActivateTermination( theEvent, parentPartitionKeys, partitionKey, conditionPath, optionalInitCondAsName); foreach (var agentInstance in result.AgentInstances) { agentInstance.AgentInstanceContext.EpStatementAgentInstanceHandle.FilterFaultHandler = ContextControllerWTerminationFilterFaultHandler.INSTANCE; } } keyedSvc.KeyAdd(controllerPath, getterKey, subpathIdOrCPId, terminationCondition); // update the filter version for this handle var filterVersionAfterStart = realization.AgentInstanceContextCreate.FilterService.FiltersVersion; realization.AgentInstanceContextCreate.EpStatementAgentInstanceHandle.StatementFilterVersion .StmtFilterVersion = filterVersionAfterStart; }
public ContextPartitionInstantiationResult ContextPartitionInstantiate( IntSeqKey controllerPathId, int subpathId, ContextController originator, EventBean optionalTriggeringEvent, IDictionary<string, object> optionalPatternForInclusiveEval, object[] parentPartitionKeys, object partitionKey) { // detect non-leaf var controllerEnv = originator.Factory.FactoryEnv; if (controllerPathId.Length != controllerEnv.NestingLevel - 1) { throw new IllegalStateException("Unexpected controller path"); } if (parentPartitionKeys.Length != controllerEnv.NestingLevel - 1) { throw new IllegalStateException("Unexpected partition key size"); } var nestingLevel = controllerEnv.NestingLevel; // starts at 1 for root if (nestingLevel < ContextControllers.Length) { // next sub-sontext var nextContext = ContextControllers[nestingLevel]; // add a partition key var nestedPartitionKeys = AddPartitionKey(nestingLevel, parentPartitionKeys, partitionKey); // now post-initialize, this may actually call back var childPath = controllerPathId.AddToEnd(subpathId); nextContext.Activate( childPath, nestedPartitionKeys, optionalTriggeringEvent, optionalPatternForInclusiveEval); return new ContextPartitionInstantiationResult(subpathId, Collections.GetEmptyList<AgentInstance>()); } // assign context id var allPartitionKeys = CollectionUtil.AddValue(parentPartitionKeys, partitionKey); var assignedContextId = ContextManager.ContextPartitionIdService.AllocateId(allPartitionKeys); // build built-in context properties var contextBean = ContextManagerUtil.BuildContextProperties( assignedContextId, allPartitionKeys, ContextManager.ContextDefinition, AgentInstanceContextCreate.StatementContext); // handle leaf creation IList<AgentInstance> startedInstances = new List<AgentInstance>(2); foreach (var statementEntry in ContextManager.Statements) { var statementDesc = statementEntry.Value; Supplier<IDictionary<FilterSpecActivatable, FilterValueSetParam[][]>> generator = () => ContextManagerUtil.ComputeAddendumForStatement( statementDesc, ContextManager.Statements, ContextManager.ContextDefinition.ControllerFactories, allPartitionKeys, AgentInstanceContextCreate); AgentInstanceFilterProxy proxy = new AgentInstanceFilterProxyImpl(generator); var agentInstance = AgentInstanceUtil.StartStatement( ContextManager.StatementContextCreate.StatementContextRuntimeServices, assignedContextId, statementDesc, contextBean, proxy); startedInstances.Add(agentInstance); } // for all new contexts: evaluate this event for this statement if (optionalTriggeringEvent != null || optionalPatternForInclusiveEval != null) { // comment-in: log.info("Thread " + Thread.currentThread().getId() + " event " + optionalTriggeringEvent.getUnderlying() + " evaluateEventForStatement assignedContextId=" + assignedContextId); AgentInstanceUtil.EvaluateEventForStatement( optionalTriggeringEvent, optionalPatternForInclusiveEval, startedInstances, AgentInstanceContextCreate); } if (ContextManager.ListenersMayNull != null) { var identifier = ContextManager.GetContextPartitionIdentifier(allPartitionKeys); ContextStateEventUtil.DispatchPartition( ContextManager.ListenersMayNull, () => new ContextStateEventContextPartitionAllocated( AgentInstanceContextCreate.RuntimeURI, ContextManager.ContextRuntimeDescriptor.ContextDeploymentId, ContextManager.ContextDefinition.ContextName, assignedContextId, identifier), ( listener, context) => listener.OnContextPartitionAllocated(context)); } return new ContextPartitionInstantiationResult(assignedContextId, startedInstances); }
public void ContextPartitionTerminate( IntSeqKey controllerPath, int subpathIdOrCPId, ContextController originator, IDictionary<string, object> terminationProperties, bool leaveLocksAcquired, IList<AgentInstance> agentInstancesLocksHeld) { if (controllerPath.Length != originator.Factory.FactoryEnv.NestingLevel - 1) { throw new IllegalStateException("Unrecognized controller path"); } // detect non-leaf var controllerEnv = originator.Factory.FactoryEnv; var nestingLevel = controllerEnv.NestingLevel; // starts at 1 for root if (nestingLevel < ContextControllers.Length) { var childController = ContextControllers[nestingLevel]; var path = controllerPath.AddToEnd(subpathIdOrCPId); childController.Deactivate(path, true); return; } var agentInstanceId = subpathIdOrCPId; // stop - in reverse order of statements, to allow termination to use tables+named-windows var contextControllers = ContextControllers; var contextControllerStatementDescList = new List<ContextControllerStatementDesc>(ContextManager.Statements.Values); contextControllerStatementDescList.Reverse(); foreach (var statementDesc in contextControllerStatementDescList) { AgentInstanceUtil.ContextPartitionTerminate( agentInstanceId, statementDesc, contextControllers, terminationProperties, leaveLocksAcquired, agentInstancesLocksHeld); } // remove all context partition statement resources foreach (var statementEntry in ContextManager.Statements) { var statementDesc = statementEntry.Value; var svc = statementDesc.Lightweight.StatementContext.StatementCPCacheService.StatementResourceService; var holder = svc.DeallocatePartitioned(agentInstanceId); } // remove id ContextManager.ContextPartitionIdService.RemoveId(agentInstanceId); if (ContextManager.ListenersMayNull != null) { ContextStateEventUtil.DispatchPartition( ContextManager.ListenersMayNull, () => new ContextStateEventContextPartitionDeallocated( AgentInstanceContextCreate.RuntimeURI, ContextManager.ContextRuntimeDescriptor.ContextDeploymentId, ContextManager.ContextDefinition.ContextName, agentInstanceId), ( listener, context) => listener.OnContextPartitionDeallocated(context)); } }