public bool HandleFilterFault( EventBean theEvent, long version) { // We handle context-management filter faults always the same way. // Statement-partition filter faults are specific to the controller. // // Hashed-context without preallocate: every time a new bucket shows up the filter version changes, faulting for those that are not aware of the new bucket // Example: // T0 sends {key='A', id='E1'} // T1 sends {key='A', id='E1'} // T0 receives create-ctx-ai-lock, processes "matchFound", allocates stmt, which adds filter, sets filter version // T1 encounteres newer filter version, invokes filter fault handler, evaluates event against filters, passes event to statement-partition // // To avoid duplicate processing into the statement-partition, filter by comparing statement-partition filter version. var ids = ContextManager.ContextPartitionIdService.Ids; foreach (var stmt in ContextManager.Statements) { var agentInstances = ContextManagerUtil.GetAgentInstancesFiltered( stmt.Value, ids, agentInstance => agentInstance.AgentInstanceContext.FilterVersionAfterAllocation >= version); AgentInstanceUtil.EvaluateEventForStatement(theEvent, null, agentInstances, AgentInstanceContextCreate); } return false; }
public void StartLateStatement(ContextControllerStatementDesc statement) { var ids = ContextManager.ContextPartitionIdService.Ids; foreach (var cpid in ids) { var partitionKeys = ContextManager.ContextPartitionIdService.GetPartitionKeys(cpid); // create context properties bean var contextBean = ContextManagerUtil.BuildContextProperties( cpid, partitionKeys, ContextManager.ContextDefinition, AgentInstanceContextCreate.StatementContext); // create filter proxies Supplier<IDictionary<FilterSpecActivatable, FilterValueSetParam[][]>> generator = () => ContextManagerUtil.ComputeAddendumForStatement( statement, ContextManager.Statements, ContextManager.ContextDefinition.ControllerFactories, partitionKeys, AgentInstanceContextCreate); AgentInstanceFilterProxy proxy = new AgentInstanceFilterProxyImpl(generator); // start AgentInstanceUtil.StartStatement( ContextManager.StatementContextCreate.StatementContextRuntimeServices, cpid, statement, contextBean, proxy); } }
public AgentInstanceFilterProxy ComputeFilterAddendum( ContextControllerStatementDesc statement, object[] contextPartitionKeys) { Func<AgentInstanceContext, IDictionary<FilterSpecActivatable, FilterValueSetParam[][]>> generator = agentInstanceContext => ContextManagerUtil.ComputeAddendumForStatement( statement, ContextDefinition.ControllerFactories, contextPartitionKeys, agentInstanceContext); return new AgentInstanceFilterProxyImpl(generator); }
public AgentInstanceFilterProxy ComputeFilterAddendum( ContextControllerStatementDesc statement, object[] contextPartitionKeys) { Supplier<IDictionary<FilterSpecActivatable, FilterValueSetParam[][]>> generator = () => ContextManagerUtil.ComputeAddendumForStatement( statement, Statements, ContextDefinition.ControllerFactories, contextPartitionKeys, Realization.AgentInstanceContextCreate); return new AgentInstanceFilterProxyImpl(generator); }
private AgentInstance[] GetAgentInstancesForStmt( int statementId, ContextPartitionSelector selector) { var agentInstanceIds = GetAgentInstanceIds(selector); if (agentInstanceIds == null || agentInstanceIds.IsEmpty()) { return new AgentInstance[0]; } foreach (var entry in Statements) { if (entry.Value.Lightweight.StatementContext.StatementId == statementId) { var agentInstances = ContextManagerUtil.GetAgentInstances(entry.Value, agentInstanceIds); return agentInstances.ToArray(); } } return null; }
public ContextAgentInstanceInfo GetContextAgentInstanceInfo( StatementContext statementContextOfStatement, int agentInstanceId) { var partitionKeys = ContextPartitionIdService.GetPartitionKeys(agentInstanceId); if (partitionKeys == null) { return null; } var statement = Statements.Get(statementContextOfStatement.StatementId); var props = ContextManagerUtil.BuildContextProperties( agentInstanceId, partitionKeys, ContextDefinition, StatementContextCreate); var proxy = ComputeFilterAddendum(statement, partitionKeys); return new ContextAgentInstanceInfo(props, proxy); }
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 ActivateCreateVariableStatement(ContextControllerStatementDesc statement) { var ids = ContextManager.ContextPartitionIdService.Ids; ContextManagerUtil.GetAgentInstances(statement, ids); }