private ContextControllerConditionNonHA ActivateTermination( EventBean triggeringEvent, object[] parentPartitionKeys, object partitionKey, IntSeqKey conditionPath, string optionalInitCondAsName) { ContextControllerConditionCallback callback = new ProxyContextControllerConditionCallback( ( conditionPathArg, originEndpoint, optionalTriggeringEvent, optionalTriggeringPattern, optionalTriggeringEventPattern, optionalPatternForInclusiveEval) => { var parentPath = conditionPathArg.RemoveFromEnd(); var getterKey = factory.GetGetterKey(partitionKey); var removed = keyedSvc.KeyRemove(parentPath, getterKey); if (removed == null) { return; } // remember the terminating event, we don't want it to initiate a new partition lastTerminatingEvent = optionalTriggeringEvent != null ? optionalTriggeringEvent : optionalTriggeringEventPattern; realization.ContextPartitionTerminate( conditionPathArg.RemoveFromEnd(), removed.SubpathOrCPId, this, null, false, null); removed.TerminationCondition.Deactivate(); }); var partitionKeys = CollectionUtil.AddValue(parentPartitionKeys, partitionKey); var terminationCondition = ContextControllerConditionFactory.GetEndpoint( conditionPath, partitionKeys, factory.keyedSpec.OptionalTermination, callback, this, false); ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider = null; if (optionalInitCondAsName != null) { endConditionMatchEventProvider = new ProxyContextControllerEndConditionMatchEventProvider { ProcPopulateEndConditionFromTrigger = ( map, triggeringEventArg) => { ContextControllerKeyedUtil.PopulatePriorMatch(optionalInitCondAsName, map, triggeringEventArg); } }; } terminationCondition.Activate(triggeringEvent, endConditionMatchEventProvider); return terminationCondition; }
private static void AddNotYetNavigated( int streamNo, int numStreams, LinkedHashMap <int, int[]> substreamsPerStream, NStreamQueryPlanBuilder.BestChainResult bestChain) { // sum up all substreams (the query plan for each stream: nested iteration or cardinal) ISet <int> streams = new HashSet <int>(); streams.Add(streamNo); RecursiveAdd(streamNo, streamNo, substreamsPerStream, streams, false); // we are done, all have navigated if (streams.Count == numStreams) { return; } var previous = streamNo; foreach (var stream in bestChain.Chain) { if (streams.Contains(stream)) { previous = stream; continue; } // add node as a nested join to the previous stream var substreams = substreamsPerStream.Get(previous); if (substreams == null) { substreams = new int[0]; } var added = CollectionUtil.AddValue(substreams, stream); substreamsPerStream.Put(previous, added); if (!substreamsPerStream.ContainsKey(stream)) { substreamsPerStream.Put(stream, new int[0]); } previous = stream; } }
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); }