public override FilterValueSetParam[][] PopulateFilterAddendum( FilterSpecActivatable filterSpec, bool forStatement, int nestingLevel, object partitionKey, ContextControllerStatementDesc optionalStatementDesc, IDictionary<int, ContextControllerStatementDesc> statements, AgentInstanceContext agentInstanceContextStatement) { if (!forStatement) { if (!EventTypeUtility.IsTypeOrSubTypeOf( filterSpec.FilterForEventType, CategorySpec.FilterSpecActivatable.FilterForEventType)) { return null; } } var categoryNum = partitionKey.AsInt32(); var item = CategorySpec.Items[categoryNum]; FilterValueSetParam[][] filters = item.FilterPlan.EvaluateValueSet( null, agentInstanceContextStatement, agentInstanceContextStatement.StatementContextFilterEvalEnv); if (filters == null) { throw new EPException( "Category context '" + ContextName + "' for category '" + item.Name + "' has evaluated to a condition that cannot become true"); } return filters; }
public abstract FilterValueSetParam[][] PopulateFilterAddendum( FilterSpecActivatable filterSpec, bool forStatement, int nestingLevel, object partitionKey, ContextControllerStatementDesc optionalStatementDesc, AgentInstanceContext agentInstanceContextStatement);
public static void ContextPartitionTerminate( int agentInstanceId, ContextControllerStatementDesc statementDesc, IDictionary<string, object> terminationProperties, bool leaveLocksAcquired, IList<AgentInstance> agentInstancesLocksHeld) { var statementContext = statementDesc.Lightweight.StatementContext; var holder = statementContext.StatementCPCacheService.MakeOrGetEntryCanNull(agentInstanceId, statementContext); if (terminationProperties != null) { var mappedEventBean = (MappedEventBean) holder.AgentInstanceContext.ContextProperties; mappedEventBean.Properties.PutAll(terminationProperties); } // we are not removing statement resources from memory as they may still be used for the same event Stop( holder.AgentInstanceStopCallback, holder.AgentInstanceContext, holder.FinalView, false, leaveLocksAcquired); if (leaveLocksAcquired) { agentInstancesLocksHeld.Add( new AgentInstance(holder.AgentInstanceStopCallback, holder.AgentInstanceContext, holder.FinalView)); } }
public static AgentInstance StartStatement( StatementContextRuntimeServices services, int assignedContextId, ContextControllerStatementDesc statementDesc, MappedEventBean contextBean, AgentInstanceFilterProxy proxy) { var result = AgentInstanceUtil.Start( services, statementDesc, assignedContextId, contextBean, proxy, false); return new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView); }
public override FilterValueSetParam[][] PopulateFilterAddendum( FilterSpecActivatable filterSpec, bool forStatement, int nestingLevel, object partitionKey, ContextControllerStatementDesc optionalStatementDesc, AgentInstanceContext agentInstanceContextStatement) { if (!forStatement) { if (!EventTypeUtility.IsTypeOrSubTypeOf( filterSpec.FilterForEventType, CategorySpec.FilterSpecActivatable.FilterForEventType)) { return null; } } int categoryNum = partitionKey.AsInt32(); ContextControllerDetailCategoryItem item = CategorySpec.Items[categoryNum]; return FilterSpecActivatable.EvaluateValueSet( item.CompiledFilterParam, null, agentInstanceContextStatement); }
private static EPStatementSPI DeployStatement( bool recovery, StatementLightweight lightweight, EPRuntimeSPI epRuntime) { // statement-create: safe operation for registering things var statementAgentInstanceFactory = lightweight.StatementContext.StatementAIFactoryProvider.Factory; statementAgentInstanceFactory.StatementCreate(lightweight.StatementContext); // add statement var stmt = MakeStatement( lightweight.StatementContext.UpdateDispatchView, lightweight.StatementContext, (StatementResultServiceImpl)lightweight.StatementResultService, epRuntime); // add statement to globals epRuntime.ServicesContext.StatementLifecycleService.AddStatement(stmt); // it is now available for lookup Viewable finalView; StatementDestroyCallback statementDestroyCallback; ICollection <StatementAgentInstancePreload> preloads = null; var contextName = lightweight.StatementInformationals.OptionalContextName; if (contextName == null) { var result = StartStatementNoContext(lightweight, recovery, epRuntime.ServicesContext); finalView = result.FinalView; preloads = result.PreloadList; var createContextStmt = result is StatementAgentInstanceFactoryCreateContextResult; statementDestroyCallback = new ProxyStatementDestroyCallback() { ProcDestroy = ( destroyServices, statementContext) => { // All statements other that create-context: get the agent-instance-context and stop // Create-context statements already got destroyed when the last statement associated to context was removed. if (!createContextStmt) { var holder = statementContext.StatementCPCacheService.MakeOrGetEntryCanNull(-1, statementContext); holder.AgentInstanceStopCallback.Stop(new AgentInstanceStopServices(holder.AgentInstanceContext)); } // Invoke statement-destroy statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext); }, }; // assign StatementAIFactoryAssignments assignments = new StatementAIFactoryAssignmentsImpl( result.OptionalAggegationService, result.PriorStrategies, result.PreviousGetterStrategies, result.SubselectStrategies, result.TableAccessStrategies, result.RowRecogPreviousStrategy); lightweight.StatementContext.StatementAIFactoryProvider.Assign(assignments); } else { var contextModuleName = lightweight.StatementInformationals.OptionalContextModuleName; var statementAIResourceRegistry = lightweight.StatementContext.StatementAIResourceRegistry; var contextVisibility = lightweight.StatementInformationals.OptionalContextVisibility; var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId( contextModuleName, contextVisibility, contextName, lightweight.StatementContext.DeploymentId, lightweight.StatementContext.PathContextRegistry); var contextMergeView = lightweight.StatementInformationals.StatementType.IsOnTriggerInfra() ? new ContextMergeViewForwarding(null) : new ContextMergeView(null); finalView = contextMergeView; var statement = new ContextControllerStatementDesc(lightweight, contextMergeView); // assignments before add-statement, since add-statement creates context partitions which may preload lightweight.StatementContext.StatementAIFactoryProvider.Assign(new StatementAIFactoryAssignmentContext(statementAIResourceRegistry)); // add statement epRuntime.ServicesContext.ContextManagementService.AddStatement(contextDeploymentId, contextName, statement, recovery); statementDestroyCallback = new ProxyStatementDestroyCallback() { ProcDestroy = ( destroyServices, statementContext) => { var ctx = statement.Lightweight.StatementContext; epRuntime.ServicesContext.ContextManagementService.StoppedStatement( contextDeploymentId, contextName, ctx.StatementId, ctx.StatementName, ctx.DeploymentId); statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext); }, }; } // make dispatch view finalView.Child = lightweight.StatementContext.UpdateDispatchView; // assign parent view stmt.StatementContext.DestroyCallback = statementDestroyCallback; stmt.ParentView = finalView; // execute preloads if (preloads != null) { foreach (var preload in preloads) { preload.ExecutePreload(); } } return(stmt); }
public static FilterValueSetParam[][] GetAddendumFilters( object getterKey, FilterSpecActivatable filtersSpec, ContextControllerDetailKeyed keyedSpec, bool includePartition, ContextControllerStatementDesc optionalStatementDesc, AgentInstanceContext agentInstanceContext) { // determine whether create-named-window var isCreateWindow = optionalStatementDesc != null && optionalStatementDesc.Lightweight.StatementContext.StatementInformationals .StatementType == StatementType.CREATE_WINDOW; ContextControllerDetailKeyedItem foundPartition = null; if (!isCreateWindow) { foreach (var partitionItem in keyedSpec.Items) { var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf( filtersSpec.FilterForEventType, partitionItem.FilterSpecActivatable.FilterForEventType); if (typeOrSubtype) { foundPartition = partitionItem; break; } } } else { var factory = (StatementAgentInstanceFactoryCreateNW) optionalStatementDesc.Lightweight.StatementContext .StatementAIFactoryProvider .Factory; var declaredAsName = factory.AsEventTypeName; foreach (var partitionItem in keyedSpec.Items) { if (partitionItem.FilterSpecActivatable.FilterForEventType.Name.Equals(declaredAsName)) { foundPartition = partitionItem; break; } } } if (foundPartition == null) { return null; } var lookupables = foundPartition.Lookupables; var addendumFilters = new FilterValueSetParam[lookupables.Length]; if (lookupables.Length == 1) { addendumFilters[0] = GetFilterMayEqualOrNull(lookupables[0], getterKey); } else { var keys = getterKey is HashableMultiKey ? ((HashableMultiKey) getterKey).Keys : (object[]) getterKey; for (var i = 0; i < lookupables.Length; i++) { addendumFilters[i] = GetFilterMayEqualOrNull(lookupables[i], keys[i]); } } var addendum = new FilterValueSetParam[1][]; addendum[0] = addendumFilters; var partitionFilters = foundPartition.FilterSpecActivatable.GetValueSet( null, null, agentInstanceContext, agentInstanceContext.StatementContextFilterEvalEnv); if (partitionFilters != null && includePartition) { addendum = FilterAddendumUtil.AddAddendum(partitionFilters, addendum[0]); } return addendum; }
public static StatementAgentInstanceFactoryResult Start( StatementContextRuntimeServices services, ContextControllerStatementDesc statement, int agentInstanceId, MappedEventBean contextProperties, AgentInstanceFilterProxy agentInstanceFilterProxy, bool isRecoveringResilient) { var statementContext = statement.Lightweight.StatementContext; // create handle that comtains lock for use in scheduling and filter callbacks var @lock = statementContext.StatementAIFactoryProvider.Factory.ObtainAgentInstanceLock( statementContext, agentInstanceId); var agentInstanceHandle = new EPStatementAgentInstanceHandle(statementContext.EpStatementHandle, agentInstanceId, @lock); var auditProvider = statementContext.StatementInformationals.AuditProvider; var instrumentationProvider = statementContext.StatementInformationals.InstrumentationProvider; var agentInstanceContext = new AgentInstanceContext( statementContext, agentInstanceHandle, agentInstanceFilterProxy, contextProperties, auditProvider, instrumentationProvider); if (agentInstanceId != -1) { agentInstanceContext.AuditProvider.ContextPartition(true, agentInstanceContext); } var statementAgentInstanceLock = agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock; agentInstanceContext.InstrumentationProvider.QContextPartitionAllocate(agentInstanceContext); using (statementAgentInstanceLock.AcquireWriteLock()) { try { // start var startResult = statement.Lightweight.StatementProvider.StatementAIFactoryProvider.Factory.NewContext( agentInstanceContext, isRecoveringResilient); // hook up with listeners+subscribers startResult.FinalView.Child = statement.ContextMergeView; // hook output to merge view // assign agents for expression-node based strategies var aiResourceRegistry = statementContext.StatementAIResourceRegistry; AIRegistryUtil.AssignFutures( aiResourceRegistry, agentInstanceId, startResult.OptionalAggegationService, startResult.PriorStrategies, startResult.PreviousGetterStrategies, startResult.SubselectStrategies, startResult.TableAccessStrategies, startResult.RowRecogPreviousStrategy); // execute preloads, if any if (startResult.PreloadList != null) { foreach (var preload in startResult.PreloadList) { preload.ExecutePreload(); } } // handle any pattern-match-event that was produced during startup, relevant for "timer:interval(0)" in conjunction with contexts startResult.PostContextMergeRunnable?.Invoke(); var holder = services.StatementResourceHolderBuilder.Build(agentInstanceContext, startResult); statementContext.StatementCPCacheService.StatementResourceService.SetPartitioned( agentInstanceId, holder); // instantiated return startResult; } finally { if (agentInstanceContext.StatementContext.EpStatementHandle.HasTableAccess) { agentInstanceContext.TableExprEvaluatorContext.ReleaseAcquiredLocks(); } agentInstanceContext.InstrumentationProvider.AContextPartitionAllocate(); } } }