Exemplo n.º 1
0
 public void AccountTime(
     StatementMetricHandle metricsHandle,
     PerformanceMetrics performanceMetrics,
     int numInputEvents)
 {
     stmtMetricRepository.AccountTimes(metricsHandle, performanceMetrics, numInputEvents);
 }
Exemplo n.º 2
0
 public EPStatementHandle(
     string statementName,
     string deploymentId,
     int statementId,
     string optionalStatementEPL,
     int priority,
     bool preemptive,
     bool canSelfJoin,
     MultiMatchHandler multiMatchHandler,
     bool hasVariables,
     bool hasTableAccess,
     StatementMetricHandle metricsHandle,
     InsertIntoLatchFactory insertIntoFrontLatchFactory,
     InsertIntoLatchFactory insertIntoBackLatchFactory)
 {
     this.statementName = statementName;
     this.deploymentId = deploymentId;
     this.statementId = statementId;
     this.optionalStatementEPL = optionalStatementEPL;
     this.priority = priority;
     this.preemptive = preemptive;
     this.canSelfJoin = canSelfJoin;
     this.multiMatchHandler = multiMatchHandler;
     this.hasVariables = hasVariables;
     this.hasTableAccess = hasTableAccess;
     this.metricsHandle = metricsHandle;
     this.insertIntoFrontLatchFactory = insertIntoFrontLatchFactory;
     this.insertIntoBackLatchFactory = insertIntoBackLatchFactory;
 }
Exemplo n.º 3
0
 public void SetContext(
     EPStatementSPI epStatement,
     EPRuntimeSPI runtime)
 {
     _epStatement = epStatement;
     _runtime = runtime;
     _statementMetricHandle = epStatement.StatementContext.EpStatementHandle.MetricsHandle;
 }
Exemplo n.º 4
0
 public static TableOnViewFactory Make(
     TableMetadata tableMetadata,
     OnTriggerDesc onTriggerDesc,
     EventType filterEventType,
     string filterStreamName,
     StatementContext statementContext,
     StatementMetricHandle metricsHandle,
     bool isDistinct,
     InternalEventRouter internalEventRouter)
 {
     if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_DELETE)
     {
         return(new TableOnDeleteViewFactory(statementContext.StatementResultService, tableMetadata));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_SELECT)
     {
         EventBeanReader eventBeanReader = null;
         if (isDistinct)
         {
             eventBeanReader = tableMetadata.InternalEventType.GetReader();
         }
         var windowDesc = (OnTriggerWindowDesc)onTriggerDesc;
         return(new TableOnSelectViewFactory(
                    tableMetadata, internalEventRouter, statementContext.EpStatementHandle,
                    eventBeanReader, isDistinct, statementContext.StatementResultService,
                    statementContext.InternalEventEngineRouteDest, windowDesc.IsDeleteAndSelect));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_UPDATE)
     {
         var updateDesc   = (OnTriggerWindowUpdateDesc)onTriggerDesc;
         var updateHelper = EventBeanUpdateHelperFactory.Make(
             tableMetadata.TableName, (EventTypeSPI)tableMetadata.InternalEventType, updateDesc.Assignments,
             updateDesc.OptionalAsName, filterEventType, false);
         TableUpdateStrategy updateStrategy = statementContext.TableService.GetTableUpdateStrategy(
             tableMetadata, updateHelper, false);
         var onUpdateViewFactory =
             new TableOnUpdateViewFactory(
                 statementContext.StatementResultService, tableMetadata, updateHelper, updateStrategy);
         statementContext.TableService.AddTableUpdateStrategyReceiver(
             tableMetadata, statementContext.StatementName, onUpdateViewFactory, updateHelper, false);
         return(onUpdateViewFactory);
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_MERGE)
     {
         var onMergeTriggerDesc = (OnTriggerMergeDesc)onTriggerDesc;
         var onMergeHelper      = new TableOnMergeHelper(
             statementContext, onMergeTriggerDesc, filterEventType, filterStreamName, internalEventRouter,
             tableMetadata);
         return(new TableOnMergeViewFactory(
                    tableMetadata, onMergeHelper, statementContext.StatementResultService, metricsHandle,
                    statementContext.MetricReportingService));
     }
     else
     {
         throw new IllegalStateException("Unknown trigger type " + onTriggerDesc.OnTriggerType);
     }
 }
Exemplo n.º 5
0
 public NamedWindowOnMergeViewFactory(EventType namedWindowEventType,
                                      NamedWindowOnMergeHelper namedWindowOnMergeHelper,
                                      StatementResultService statementResultService,
                                      StatementMetricHandle createNamedWindowMetricHandle,
                                      MetricReportingService metricReportingService)
     : base(namedWindowEventType)
 {
     _namedWindowOnMergeHelper      = namedWindowOnMergeHelper;
     _statementResultService        = statementResultService;
     _createNamedWindowMetricHandle = createNamedWindowMetricHandle;
     _metricReportingService        = metricReportingService;
 }
Exemplo n.º 6
0
 public TableOnMergeViewFactory(
     TableMetadata tableMetadata,
     TableOnMergeHelper onMergeHelper,
     StatementResultService statementResultService,
     StatementMetricHandle metricsHandle,
     MetricReportingServiceSPI metricReportingService)
 {
     TableMetadata          = tableMetadata;
     OnMergeHelper          = onMergeHelper;
     StatementResultService = statementResultService;
     MetricsHandle          = metricsHandle;
     MetricReportingService = metricReportingService;
 }
Exemplo n.º 7
0
 public void AccountOutput(
     StatementMetricHandle handle,
     int numIStream,
     int numRStream,
     object epStatement,
     object runtime)
 {
     stmtMetricRepository.AccountOutput(handle, numIStream, numRStream);
     if (!StatementOutputHooks.IsEmpty()) {
         var statement = (EPStatement) epStatement;
         var service = (EPRuntime) runtime;
         foreach (var listener in StatementOutputHooks) {
             listener.Update(numIStream, numRStream, statement, service);
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// For initialization of the service to provide statement context.
 /// </summary>
 /// <param name="epStatement">the statement</param>
 /// <param name="epServiceProvider">the engine instance</param>
 /// <param name="isInsertInto">true if this is insert into</param>
 /// <param name="isPattern">true if this is a pattern statement</param>
 /// <param name="isDistinct">true if using distinct</param>
 /// <param name="isForClause">if set to <c>true</c> [is for clause].</param>
 /// <param name="statementMetricHandle">handle for metrics reporting</param>
 public void SetContext(EPStatementSPI epStatement,
                        EPServiceProviderSPI epServiceProvider,
                        bool isInsertInto,
                        bool isPattern,
                        bool isDistinct,
                        bool isForClause,
                        StatementMetricHandle statementMetricHandle)
 {
     _epStatement           = epStatement;
     _epServiceProvider     = epServiceProvider;
     _isInsertInto          = isInsertInto;
     _isPattern             = isPattern;
     _isDistinct            = isDistinct;
     _isForClause           = isForClause;
     _isMakeSynthetic       = isInsertInto || isPattern || isDistinct || isForClause;
     _statementMetricHandle = statementMetricHandle;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementId">is the statement id uniquely indentifying the handle</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="statementText">The statement text.</param>
        /// <param name="statementType">Type of the statement.</param>
        /// <param name="expressionText">is the expression</param>
        /// <param name="hasVariables">indicator whether the statement uses variables</param>
        /// <param name="metricsHandle">handle for metrics reporting</param>
        /// <param name="priority">priority, zero is default</param>
        /// <param name="preemptive">true for drop after done</param>
        /// <param name="hasTableAccess">if set to <c>true</c> [has table access].</param>
        /// <param name="multiMatchHandler">The multi match handler.</param>
        public EPStatementHandle(string statementId, string statementName, string statementText, StatementType statementType, string expressionText, bool hasVariables, StatementMetricHandle metricsHandle, int priority, bool preemptive, bool hasTableAccess, MultiMatchHandler multiMatchHandler)
        {
            StatementId       = statementId;
            StatementName     = statementName;
            EPL               = statementText;
            StatementType     = statementType;
            HasVariables      = hasVariables;
            Priority          = priority;
            IsPreemptive      = preemptive;
            _metricsHandle    = metricsHandle;
            HasTableAccess    = hasTableAccess;
            MultiMatchHandler = multiMatchHandler;

            unchecked
            {
                _hashCode = (statementName != null ? statementName.GetHashCode() : 0);
                _hashCode = (_hashCode * 397) ^ (statementId != null ? statementId.GetHashCode() : 0);
                _hashCode = (_hashCode * 397) ^ (expressionText != null ? expressionText.GetHashCode() : 0);
            }
        }
Exemplo n.º 10
0
        public NamedWindowProcessor AddProcessor(
            string name,
            string contextName,
            EventType eventType,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            string eplExpression,
            string statementName,
            bool isPrioritized,
            bool isEnableSubqueryIndexShare,
            bool isBatchingDataWindow,
            bool isVirtualDataWindow,
            StatementMetricHandle statementMetricHandle,
            ICollection <string> optionalUniqueKeyProps,
            string eventTypeAsName,
            StatementResourceService statementResourceService)
        {
            if (_processors.ContainsKey(name))
            {
                throw new ViewProcessingException("A named window by name '" + name + "' has already been created");
            }

            var processor = new NamedWindowProcessor(
                name, this, contextName, eventType, statementResultService, revisionProcessor,
                eplExpression, statementName, isPrioritized, isEnableSubqueryIndexShare, _enableQueryPlanLog,
                _metricReportingService, isBatchingDataWindow, isVirtualDataWindow, statementMetricHandle,
                optionalUniqueKeyProps, eventTypeAsName, statementResourceService);

            _processors.Put(name, processor);

            if (!_observers.IsEmpty())
            {
                var theEvent = new NamedWindowLifecycleEvent(name, processor, NamedWindowLifecycleEvent.LifecycleEventType.CREATE);
                foreach (var observer in _observers)
                {
                    observer.Observe(theEvent);
                }
            }

            return(processor);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="namedWindowName">Name of the named window.</param>
        /// <param name="namedWindowService">service for dispatching results</param>
        /// <param name="contextName">Name of the context.</param>
        /// <param name="singleInstanceContext">if set to <c>true</c> [single instance context].</param>
        /// <param name="eventType">the type of event held by the named window</param>
        /// <param name="statementResultService">for coordinating on whether insert and remove stream events should be posted</param>
        /// <param name="revisionProcessor">for revision processing</param>
        /// <param name="eplExpression">epl expression</param>
        /// <param name="statementName">statement name</param>
        /// <param name="isPrioritized">if the engine is running with prioritized execution</param>
        /// <param name="isEnableSubqueryIndexShare">if set to <c>true</c> [is enable subquery index share].</param>
        /// <param name="enableQueryPlanLog">if set to <c>true</c> [enable query plan log].</param>
        /// <param name="metricReportingService">The metric reporting service.</param>
        /// <param name="isBatchingDataWindow">if set to <c>true</c> [is batching data window].</param>
        /// <param name="isVirtualDataWindow">if set to <c>true</c> [is virtual data window].</param>
        /// <param name="statementMetricHandle">The statement metric handle.</param>
        /// <param name="optionalUniqueKeyProps">The optional unique key props.</param>
        /// <param name="eventTypeAsName">Name of the event type as.</param>
        public NamedWindowProcessor(
            string namedWindowName,
            NamedWindowService namedWindowService,
            string contextName,
            EventType eventType,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            string eplExpression,
            string statementName,
            bool isPrioritized,
            bool isEnableSubqueryIndexShare,
            bool enableQueryPlanLog,
            MetricReportingService metricReportingService,
            bool isBatchingDataWindow,
            bool isVirtualDataWindow,
            StatementMetricHandle statementMetricHandle,
            ICollection <string> optionalUniqueKeyProps,
            string eventTypeAsName,
            StatementResourceService statementResourceService)
        {
            _namedWindowName            = namedWindowName;
            _contextName                = contextName;
            _eventType                  = eventType;
            _eplExpression              = eplExpression;
            _statementName              = statementName;
            _isEnableSubqueryIndexShare = isEnableSubqueryIndexShare;
            _isVirtualDataWindow        = isVirtualDataWindow;
            _statementMetricHandle      = statementMetricHandle;
            _optionalUniqueKeyProps     = optionalUniqueKeyProps;
            _eventTypeAsName            = eventTypeAsName;
            _statementResourceService   = statementResourceService;
            _lock = LockManager.CreateLock(GetType());

            _rootView = new NamedWindowRootView(revisionProcessor, enableQueryPlanLog, metricReportingService, eventType, isBatchingDataWindow, isEnableSubqueryIndexShare, optionalUniqueKeyProps);
            _tailView = new NamedWindowTailView(eventType, namedWindowService, statementResultService, revisionProcessor, isPrioritized, isBatchingDataWindow);
        }
Exemplo n.º 12
0
 public static NamedWindowOnExprFactory Make(
     EventType namedWindowEventType,
     string namedWindowName,
     string namedWindowAlias,
     OnTriggerDesc onTriggerDesc,
     EventType filterEventType,
     string filterStreamName,
     bool addToFront,
     InternalEventRouter internalEventRouter,
     EventType outputEventType,
     StatementContext statementContext,
     StatementMetricHandle createNamedWindowMetricsHandle,
     bool isDistinct,
     StreamSelector?optionalStreamSelector,
     string optionalInsertIntoTableName)
 {
     if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_DELETE)
     {
         return(new NamedWindowOnDeleteViewFactory(namedWindowEventType, statementContext.StatementResultService));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_SELECT)
     {
         EventBeanReader eventBeanReader = null;
         if (isDistinct)
         {
             if (outputEventType is EventTypeSPI)
             {
                 eventBeanReader = ((EventTypeSPI)outputEventType).GetReader();
             }
             if (eventBeanReader == null)
             {
                 eventBeanReader = new EventBeanReaderDefaultImpl(outputEventType);
             }
         }
         var windowDesc = (OnTriggerWindowDesc)onTriggerDesc;
         return(new NamedWindowOnSelectViewFactory(
                    namedWindowEventType, internalEventRouter, addToFront,
                    statementContext.EpStatementHandle, eventBeanReader, isDistinct, statementContext.StatementResultService,
                    statementContext.InternalEventEngineRouteDest, windowDesc.IsDeleteAndSelect, optionalStreamSelector,
                    optionalInsertIntoTableName));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_UPDATE)
     {
         var updateDesc   = (OnTriggerWindowUpdateDesc)onTriggerDesc;
         var updateHelper = EventBeanUpdateHelperFactory.Make(
             namedWindowName, (EventTypeSPI)namedWindowEventType, updateDesc.Assignments, namedWindowAlias,
             filterEventType, true);
         return(new NamedWindowOnUpdateViewFactory(
                    namedWindowEventType, statementContext.StatementResultService, updateHelper));
     }
     else if (onTriggerDesc.OnTriggerType == OnTriggerType.ON_MERGE)
     {
         var onMergeTriggerDesc = (OnTriggerMergeDesc)onTriggerDesc;
         var onMergeHelper      = new NamedWindowOnMergeHelper(
             statementContext, onMergeTriggerDesc, filterEventType, filterStreamName, internalEventRouter,
             namedWindowName, (EventTypeSPI)namedWindowEventType);
         return(new NamedWindowOnMergeViewFactory(
                    namedWindowEventType, onMergeHelper, statementContext.StatementResultService,
                    createNamedWindowMetricsHandle, statementContext.MetricReportingService));
     }
     else
     {
         throw new IllegalStateException("Unknown trigger type " + onTriggerDesc.OnTriggerType);
     }
 }
Exemplo n.º 13
0
        public StatementContext MakeContext(
            int statementId,
            string statementName,
            string expression,
            StatementType statementType,
            EPServicesContext engineServices,
            IDictionary <string, object> optAdditionalContext,
            bool isFireAndForget,
            Attribute[] annotations,
            EPIsolationUnitServices isolationUnitServices,
            bool stateless,
            StatementSpecRaw statementSpecRaw,
            IList <ExprSubselectNode> subselectNodes,
            bool writesToTables,
            object statementUserObject)
        {
            // Allocate the statement's schedule bucket which stays constant over it's lifetime.
            // The bucket allows callbacks for the same time to be ordered (within and across statements) and thus deterministic.
            var scheduleBucket = engineServices.SchedulingMgmtService.AllocateBucket();

            // Create a lock for the statement
            IReaderWriterLock defaultStatementAgentInstanceLock;

            // For on-delete statements, use the create-named-window statement lock
            var optCreateWindowDesc = statementSpecRaw.CreateWindowDesc;
            var optOnTriggerDesc    = statementSpecRaw.OnTriggerDesc;

            if ((optOnTriggerDesc != null) && (optOnTriggerDesc is OnTriggerWindowDesc))
            {
                var windowName = ((OnTriggerWindowDesc)optOnTriggerDesc).WindowName;
                if (engineServices.TableService.GetTableMetadata(windowName) == null)
                {
                    defaultStatementAgentInstanceLock = engineServices.NamedWindowMgmtService.GetNamedWindowLock(windowName);
                    if (defaultStatementAgentInstanceLock == null)
                    {
                        throw new EPStatementException("Named window or table '" + windowName + "' has not been declared", expression);
                    }
                }
                else
                {
                    defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock(statementName, annotations, stateless);
                }
            }
            // For creating a named window, save the lock for use with on-delete/on-merge/on-Update etc. statements
            else if (optCreateWindowDesc != null)
            {
                defaultStatementAgentInstanceLock =
                    engineServices.NamedWindowMgmtService.GetNamedWindowLock(optCreateWindowDesc.WindowName);
                if (defaultStatementAgentInstanceLock == null)
                {
                    defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock(
                        statementName, annotations, false);
                    engineServices.NamedWindowMgmtService.AddNamedWindowLock(
                        optCreateWindowDesc.WindowName, defaultStatementAgentInstanceLock, statementName);
                }
            }
            else
            {
                defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock(
                    statementName, annotations, stateless);
            }

            StatementMetricHandle stmtMetric = null;

            if (!isFireAndForget)
            {
                stmtMetric = engineServices.MetricsReportingService.GetStatementHandle(statementId, statementName);
            }

            var annotationData    = AnnotationAnalysisResult.AnalyzeAnnotations(annotations);
            var hasVariables      = statementSpecRaw.HasVariables || (statementSpecRaw.CreateContextDesc != null);
            var hasTableAccess    = StatementContextFactoryUtil.DetermineHasTableAccess(subselectNodes, statementSpecRaw, engineServices);
            var epStatementHandle = new EPStatementHandle(
                statementId, statementName, expression, statementType, expression,
                hasVariables, stmtMetric,
                annotationData.Priority,
                annotationData.IsPremptive,
                hasTableAccess,
                engineServices.MultiMatchHandlerFactory.GetDefaultHandler());

            var patternContextFactory = new PatternContextFactoryDefault();

            var optionalCreateNamedWindowName = statementSpecRaw.CreateWindowDesc != null
                ? statementSpecRaw.CreateWindowDesc.WindowName
                : null;
            var viewResolutionService = new ViewResolutionServiceImpl(
                _viewRegistry, optionalCreateNamedWindowName, _systemVirtualDwViewFactory);
            var patternResolutionService =
                new PatternObjectResolutionServiceImpl(_patternObjectClasses);

            var schedulingService = engineServices.SchedulingService;
            var filterService     = engineServices.FilterService;

            if (isolationUnitServices != null)
            {
                filterService     = isolationUnitServices.FilterService;
                schedulingService = isolationUnitServices.SchedulingService;
            }

            var scheduleAudit = AuditEnum.SCHEDULE.GetAudit(annotations);

            if (scheduleAudit != null)
            {
                schedulingService = new SchedulingServiceAudit(
                    engineServices.EngineURI, statementName, schedulingService);
            }

            StatementAIResourceRegistry statementAgentInstanceRegistry = null;
            ContextDescriptor           contextDescriptor = null;
            var optionalContextName = statementSpecRaw.OptionalContextName;

            if (optionalContextName != null)
            {
                contextDescriptor = engineServices.ContextManagementService.GetContextDescriptor(optionalContextName);

                // allocate a per-instance registry of aggregations and prev/prior/subselect
                if (contextDescriptor != null)
                {
                    statementAgentInstanceRegistry = contextDescriptor.AiResourceRegistryFactory.Invoke();
                }
            }

            var countSubexpressions = engineServices.ConfigSnapshot.EngineDefaults.PatternsConfig.MaxSubexpressions != null;
            PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null;

            if (countSubexpressions)
            {
                var stmtCounter = new PatternSubexpressionPoolStmtHandler();
                patternSubexpressionPoolStmtSvc =
                    new PatternSubexpressionPoolStmtSvc(engineServices.PatternSubexpressionPoolSvc, stmtCounter);
                engineServices.PatternSubexpressionPoolSvc.AddPatternContext(statementName, stmtCounter);
            }

            var countMatchRecogStates = engineServices.ConfigSnapshot.EngineDefaults.MatchRecognizeConfig.MaxStates != null;
            MatchRecognizeStatePoolStmtSvc matchRecognizeStatePoolStmtSvc = null;

            if (countMatchRecogStates && statementSpecRaw.MatchRecognizeSpec != null)
            {
                var stmtCounter = new MatchRecognizeStatePoolStmtHandler();
                matchRecognizeStatePoolStmtSvc = new MatchRecognizeStatePoolStmtSvc(engineServices.MatchRecognizeStatePoolEngineSvc, stmtCounter);
                engineServices.MatchRecognizeStatePoolEngineSvc.AddPatternContext(statementName, stmtCounter);
            }

            AgentInstanceScriptContext defaultAgentInstanceScriptContext = null;

            if (statementSpecRaw.ScriptExpressions != null && !statementSpecRaw.ScriptExpressions.IsEmpty())
            {
                defaultAgentInstanceScriptContext = new AgentInstanceScriptContext();
            }

            // allow a special context controller factory for testing
            var contextControllerFactoryService =
                GetContextControllerFactoryService(annotations);

            // may use resource tracking
            var statementResourceService = new StatementResourceService(optionalContextName != null);
            StatementExtensionSvcContext extensionSvcContext = new ProxyStatementExtensionSvcContext
            {
                ProcStmtResources = () => statementResourceService,
                ProcExtractStatementResourceHolder = resultOfStart => StatementResourceHolderUtil.PopulateHolder(resultOfStart)
            };

            // Create statement context
            return(new StatementContext(
                       _stmtEngineServices,
                       schedulingService,
                       scheduleBucket,
                       epStatementHandle,
                       viewResolutionService,
                       patternResolutionService,
                       extensionSvcContext,
                       new StatementStopServiceImpl(),
                       patternContextFactory,
                       filterService,
                       new StatementResultServiceImpl(
                           statementName,
                           engineServices.StatementLifecycleSvc,
                           engineServices.MetricsReportingService,
                           engineServices.ThreadingService),
                       engineServices.InternalEventEngineRouteDest,
                       annotations,
                       statementAgentInstanceRegistry,
                       defaultStatementAgentInstanceLock,
                       contextDescriptor,
                       patternSubexpressionPoolStmtSvc,
                       matchRecognizeStatePoolStmtSvc,
                       stateless,
                       contextControllerFactoryService,
                       defaultAgentInstanceScriptContext,
                       AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY,
                       engineServices.ScriptingService,
                       writesToTables,
                       statementUserObject,
                       StatementSemiAnonymousTypeRegistryImpl.INSTANCE,
                       annotationData.Priority));
        }