public void StopStatement(ContextControllerStatementDesc statement) { var statementId = statement.Lightweight.StatementContext.StatementId; if (!Statements.ContainsKey(statementId)) { return; } RemoveStatement(statementId); ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextStatementRemoved( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextRuntimeDescriptor.ContextName, statement.Lightweight.StatementContext.DeploymentId, statement.Lightweight.StatementContext.StatementName), ( listener, context) => listener.OnContextStatementRemoved(context)); if (Statements.IsEmpty()) { Realization.StopContext(); ContextPartitionIdService.Clear(); ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextDeactivated( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextRuntimeDescriptor.ContextName), ( listener, context) => listener.OnContextDeactivated(context)); } }
public void DestroyedContext( string runtimeURI, string deploymentIdCreateContext, string contextName) { var deployment = deployments.Get(deploymentIdCreateContext); if (deployment == null) { Log.Warn( "Destroy for context '" + contextName + "' deployment-id '" + deploymentIdCreateContext + "' failed to locate"); return; } deployment.DestroyContext(deploymentIdCreateContext, contextName); if (deployment.ContextCount == 0) { deployments.Remove(deploymentIdCreateContext); } ContextStateEventUtil.DispatchContext( Listeners, () => new ContextStateEventContextDestroyed(runtimeURI, deploymentIdCreateContext, contextName), ( listener, eventContext) => listener.OnContextDestroyed(eventContext)); }
public void AddStatement( ContextControllerStatementDesc statement, bool recovery) { var statementContextOfStatement = statement.Lightweight.StatementContext; Statements.Put(statementContextOfStatement.StatementId, statement); // dispatch event ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextStatementAdded( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextDefinition.ContextName, statementContextOfStatement.DeploymentId, statementContextOfStatement.StatementName), ( listener, context) => listener.OnContextStatementAdded(context)); if (recovery) { if (statement.Lightweight.StatementInformationals.StatementType == StatementType.CREATE_VARIABLE) { Realization.ActivateCreateVariableStatement(statement); } return; } // activate if this is the first statement if (Statements.Count == 1) { Realization.StartContext(); ContextStateEventUtil.DispatchPartition( listenersLazy, () => new ContextStateEventContextActivated( StatementContextCreate.RuntimeURI, ContextRuntimeDescriptor.ContextDeploymentId, ContextDefinition.ContextName), ( listener, context) => listener.OnContextActivated(context)); } else { // activate statement in respect to existing context partitions Realization.StartLateStatement(statement); } }
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)); } }