Esempio n. 1
0
 public PatternActionResult Invoke(long time, PatternContext context)
 {
     context.SaveTime(time);
     return(new PatternActionResult(Time != null
         ? TimeConverter.ConvertFrom(Time, context.TempoMap)
         : context.RestoreTime()));
 }
Esempio n. 2
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

            var newContext = new PatternContext(context.TempoMap, context.Channel);

            return(Pattern.InvokeActions(time, newContext));
        }
Esempio n. 3
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State == PatternActionState.Enabled)
            {
                context.AnchorTime(Anchor, time);
            }

            return(PatternActionResult.DoNothing);
        }
Esempio n. 4
0
 private OnTriggerActivatorDesc ActivatorPattern(
     PatternStreamSpecCompiled patternStreamSpec,
     StatementCompileTimeServices services)
 {
     var triggerEventTypeName = patternStreamSpec.OptionalStreamName;
     var patternType =
         ViewableActivatorPatternForge.MakeRegisterPatternType(@base, 0, patternStreamSpec, services);
     var patternContext = new PatternContext(0, patternStreamSpec.MatchedEventMapMeta, false, -1, false);
     var activator = new ViewableActivatorPatternForge(patternType, patternStreamSpec, patternContext, false);
     return new OnTriggerActivatorDesc(activator, triggerEventTypeName, patternType);
 }
Esempio n. 5
0
 public ViewableActivatorPatternForge(
     EventType eventType,
     PatternStreamSpecCompiled spec,
     PatternContext patternContext,
     bool isCanIterate)
 {
     _eventType = eventType;
     _spec = spec;
     _patternContext = patternContext;
     _isCanIterate = isCanIterate;
 }
Esempio n. 6
0
        public void SetUp()
        {
            _beginState = new MatchedEventMapImpl(new MatchedEventMapMeta(new String[0], false));

            _scheduleService = new SchedulingServiceImpl(new TimeSourceServiceImpl());
            StatementContext stmtContext = SupportStatementContextFactory.MakeContext(_scheduleService);

            _context      = new PatternContext(stmtContext, 1, new MatchedEventMapMeta(new String[0], false), false);
            _agentContext = SupportPatternContextFactory.MakePatternAgentInstanceContext(_scheduleService);

            _evaluator = new SupportObserverEvaluator(_agentContext);

            _observer = new TimerIntervalObserver(1000, _beginState, _evaluator);
        }
Esempio n. 7
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

            var noteLength = LengthConverter.ConvertFrom(Length, time, context.TempoMap);

            var note = new Note(NoteDefinition.NoteNumber, noteLength, time)
            {
                Channel  = context.Channel,
                Velocity = Velocity
            };

            return(new PatternActionResult(time + noteLength, new[] { note }));
        }
        public static PatternAgentInstanceContext MakePatternAgentInstanceContext(SchedulingService scheduleService)
        {
            StatementContext stmtContext;

            if (scheduleService == null)
            {
                stmtContext = SupportStatementContextFactory.MakeContext();
            }
            else
            {
                stmtContext = SupportStatementContextFactory.MakeContext(scheduleService);
            }
            PatternContext context = new PatternContext(stmtContext, 1, new MatchedEventMapMeta(new String[0], false), false);

            return(new PatternAgentInstanceContext(context, SupportStatementContextFactory.MakeAgentInstanceContext(), false));
        }
Esempio n. 9
0
 internal ViewableActivatorPattern(
     PatternContext patternContext,
     EvalRootFactoryNode rootFactoryNode,
     EventType eventType,
     bool hasConsumingFilter,
     bool suppressSameEventMatches,
     bool discardPartialsOnMatch,
     bool isCanIterate)
 {
     _patternContext           = patternContext;
     _rootFactoryNode          = rootFactoryNode;
     _eventType                = eventType;
     _hasConsumingFilter       = hasConsumingFilter;
     _suppressSameEventMatches = suppressSameEventMatches;
     _discardPartialsOnMatch   = discardPartialsOnMatch;
     _isCanIterate             = isCanIterate;
 }
        public void Activate(EventBean optionalTriggeringEvent, MatchedEventMap priorMatches, long timeOffset, bool isRecoveringResilient)
        {
            if (PatternStopCallback != null)
            {
                PatternStopCallback.Stop();
            }

            PatternStreamSpecCompiled patternStreamSpec = _endpointPatternSpec.PatternCompiled;
            StatementContext          stmtContext       = _agentInstanceContext.StatementContext;

            EvalRootFactoryNode rootFactoryNode = _servicesContext.PatternNodeFactory.MakeRootNode(patternStreamSpec.EvalFactoryNode);
            int            streamNum            = _isStartEndpoint ? _contextStatePathKey.SubPath : -1 * _contextStatePathKey.SubPath;
            bool           allowResilient       = _contextStatePathKey.Level == 1;
            PatternContext patternContext       = stmtContext.PatternContextFactory.CreateContext(stmtContext, streamNum, rootFactoryNode, new MatchedEventMapMeta(patternStreamSpec.AllTags, !patternStreamSpec.ArrayEventTypes.IsEmpty()), allowResilient);

            PatternAgentInstanceContext patternAgentInstanceContext = stmtContext.PatternContextFactory.CreatePatternAgentContext(patternContext, _agentInstanceContext, false);
            EvalRootNode rootNode = EvalNodeUtil.MakeRootNodeFromFactory(rootFactoryNode, patternAgentInstanceContext);

            if (priorMatches == null)
            {
                priorMatches = new MatchedEventMapImpl(patternContext.MatchedEventMapMeta);
            }

            // capture any callbacks that may occur right after start
            ConditionPatternMatchCallback callback = new ConditionPatternMatchCallback(this);

            PatternStopCallback   = rootNode.Start(callback.MatchFound, patternContext, priorMatches, isRecoveringResilient);
            callback.ForwardCalls = true;

            if (_agentInstanceContext.StatementContext.StatementExtensionServicesContext != null &&
                _agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources != null)
            {
                _agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources
                .StartContextPattern(PatternStopCallback, _isStartEndpoint, _contextStatePathKey);
            }

            if (callback.IsInvoked)
            {
                MatchFound(Collections.GetEmptyMap <String, Object>());
            }
        }
Esempio n. 11
0
        public ViewableActivator CreatePattern(
            PatternContext patternContext,
            EvalRootFactoryNode rootFactoryNode,
            EventType eventType,
            bool consumingFilters,
            bool suppressSameEventMatches,
            bool discardPartialsOnMatch,
            bool isCanIterateUnbound)
        {
            if (ProcCreatePattern == null)
            {
                throw new NotSupportedException();
            }

            return(ProcCreatePattern.Invoke(
                       patternContext,
                       rootFactoryNode,
                       eventType,
                       consumingFilters,
                       suppressSameEventMatches,
                       discardPartialsOnMatch,
                       isCanIterateUnbound));
        }
Esempio n. 12
0
 static PatternContext[] CreatePatternContext()
 {
     var patternCtx = new PatternContext[NumChannels];
     for (int i = 0; i < patternCtx.Length; i++)
     {
         patternCtx[i] = new PatternContext();
     }
     return patternCtx;
 }
Esempio n. 13
0
        void InitPattern(PatternContext pattern, byte cmd, sbyte expose, uint offset)
        {
            pattern.command = cmd;
            pattern.offset = offset;
            pattern.expose = expose;
            pattern.step = 0;
            pattern.wait = 0;
            pattern.loopCount = 0xFF;

            pattern.savedOffset = 0;
            pattern.savedStep = 0;
        }
 public abstract PatternActionResult Invoke(long time, PatternContext context);
Esempio n. 15
0
 public override PatternActionResult Invoke(long time, PatternContext context)
 {
     context.SaveTime(time);
     return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap)));
 }
 public ViewableActivator CreatePattern(PatternContext patternContext, EvalRootFactoryNode rootFactoryNode, EventType eventType, bool consumingFilters, bool suppressSameEventMatches, bool discardPartialsOnMatch, bool isCanIterateUnbound)
 {
     return(new ViewableActivatorPattern(patternContext, rootFactoryNode, eventType, consumingFilters, suppressSameEventMatches, discardPartialsOnMatch, isCanIterateUnbound));
 }
Esempio n. 17
0
        bool PatternRun(PatternContext pattern)
        {
            for (;;)
            {
                var patternPtrOff = (int)(pattern.offset + 4 * pattern.step - _resource.mdatOffset);
                ++pattern.step;
                byte pattCmd = _resource.mdatAlloc[patternPtrOff];

                if (pattCmd < 0xF0)
                { // Playnote
                    bool doWait = false;
                    byte noteCmd = (byte)(pattCmd + pattern.expose);
                    byte param3 = _resource.mdatAlloc[patternPtrOff + 3];
                    if (pattCmd < 0xC0)
                    {   // Note
                        if (pattCmd >= 0x80)
                        {  // Wait
                            pattern.wait = param3;
                            param3 = 0;
                            doWait = true;
                        }
                        noteCmd &= 0x3F;
                    }   // else Portamento
                    NoteCommand(noteCmd, _resource.mdatAlloc[patternPtrOff + 1], _resource.mdatAlloc[patternPtrOff + 2], param3);
                    if (doWait)
                        return false;

                }
                else
                {    // Patterncommand
                    switch (pattCmd & 0xF)
                    {
                        case 0:     // End Pattern + Next Trackstep
                            pattern.command = 0xFF;
                            --pattern.step;
                            return true;

                        case 1:     // Loop Pattern. Parameters: Loopcount, PatternStep(W)
                            if (pattern.loopCount != 0)
                            {
                                if (pattern.loopCount == 0xFF)
                                    pattern.loopCount = _resource.mdatAlloc[patternPtrOff + 1];
                                pattern.step = _resource.mdatAlloc.ToUInt16BigEndian(patternPtrOff + 2);
                            }
                            --pattern.loopCount;
                            continue;

                        case 2:     // Jump. Parameters: PatternIndex, PatternStep(W)
                            pattern.offset = _resource.patternOffset[_resource.mdatAlloc[patternPtrOff + 1] & (MaxPatternOffsets - 1)];
                            pattern.step = _resource.mdatAlloc.ToUInt16BigEndian(patternPtrOff + 2);
                            continue;

                        case 3:     // Wait. Paramters: ticks to wait
                            pattern.wait = _resource.mdatAlloc[patternPtrOff + 1];
                            return false;

                        case 14:    // Stop custompattern
                            // TODO apparently toggles on/off pattern channel 7
                            Debug.WriteLine("Tfmx: Encountered 'Stop custompattern' command");
                            // same as 4
                            pattern.command = 0xFF;
                            --pattern.step;
                            break;
                    // FT
                        case 4:     // Stop this pattern
                            pattern.command = 0xFF;
                            --pattern.step;
                            // TODO: try figuring out if this was the last Channel?
                            return false;

                        case 5:     // Key Up Signal. Paramters: channel
                            if (!_channelCtx[_resource.mdatAlloc[patternPtrOff + 2] & (NumVoices - 1)].sfxLocked)
                                _channelCtx[_resource.mdatAlloc[patternPtrOff + 2] & (NumVoices - 1)].keyUp = true;
                            continue;

                        case 6:     // Vibrato. Parameters: length, channel, rate
                        case 7:     // Envelope. Parameters: rate, tempo | channel, endVol
                            NoteCommand(pattCmd, _resource.mdatAlloc[patternPtrOff + 1], _resource.mdatAlloc[patternPtrOff + 2], _resource.mdatAlloc[patternPtrOff + 3]);
                            continue;

                        case 8:     // Subroutine. Parameters: pattern, patternstep(W)
                            pattern.savedOffset = pattern.offset;
                            pattern.savedStep = pattern.step;

                            pattern.offset = _resource.patternOffset[_resource.mdatAlloc[patternPtrOff + 1] & (MaxPatternOffsets - 1)];
                            pattern.step = _resource.mdatAlloc.ToUInt16BigEndian(patternPtrOff + 2);
                            continue;

                        case 9:     // Return from Subroutine
                            pattern.offset = pattern.savedOffset;
                            pattern.step = pattern.savedStep;
                            continue;

                        case 10:    // fade. Parameters: tempo, endVol
                            InitFadeCommand(_resource.mdatAlloc[patternPtrOff + 1], (sbyte)_resource.mdatAlloc[patternPtrOff + 3]);
                            continue;

                        case 11:    // play pattern. Parameters: patternCmd, channel, expose
                            InitPattern(_patternCtx[_resource.mdatAlloc[patternPtrOff + 2] & (NumChannels - 1)], 
                                _resource.mdatAlloc[patternPtrOff + 1], 
                                (sbyte)_resource.mdatAlloc[patternPtrOff + 3], 
                                _resource.patternOffset[_resource.mdatAlloc[patternPtrOff + 1] & (MaxPatternOffsets - 1)]);
                            continue;

                        case 12:    // Lock. Parameters: lockFlag, channel, lockTime
                            _channelCtx[_resource.mdatAlloc[patternPtrOff + 2] & (NumVoices - 1)].sfxLocked = (_resource.mdatAlloc[patternPtrOff + 1] != 0);
                            _channelCtx[_resource.mdatAlloc[patternPtrOff + 2] & (NumVoices - 1)].sfxLockTime = _resource.mdatAlloc[patternPtrOff + 3];
                            continue;

                        case 13:    // Cue. Parameters: signalnumber, value(W)
                            if (_playerCtx.signal != null)
                                _playerCtx.signal(_resource.mdatAlloc[patternPtrOff + 1], _resource.mdatAlloc.ToUInt16BigEndian(patternPtrOff + 2));
                            continue;

                        case 15:    // NOP
                            continue;
                    }
                }
            }
        }
Esempio n. 18
0
 public PatternActionResult Invoke(long time, PatternContext context)
 {
     context.AnchorTime(Anchor, time);
     return(PatternActionResult.DoNothing);
 }
Esempio n. 19
0
        public static StmtForgeMethodSelectResult Make(
            IContainer container,
            bool dataflowOperator,
            string @namespace,
            string classPostfix,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var filterSpecCompileds = new List<FilterSpecCompiled>();
            var scheduleHandleCallbackProviders = new List<ScheduleHandleCallbackProvider>();
            var namedWindowConsumers = new List<NamedWindowConsumerStreamSpec>();
            var statementSpec = @base.StatementSpec;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            var streamNames = StatementForgeMethodSelectUtil.DetermineStreamNames(statementSpec.StreamSpecs);
            var numStreams = streamNames.Length;
            if (numStreams == 0) {
                throw new ExprValidationException("The from-clause is required but has not been specified");
            }

            // first we create streams for subselects, if there are any
            SubSelectActivationDesc subSelectActivationDesc = SubSelectHelperActivations.CreateSubSelectActivation(
                filterSpecCompileds, namedWindowConsumers, @base, services);
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation = subSelectActivationDesc.Subselects;
            additionalForgeables.AddAll(subSelectActivationDesc.AdditionalForgeables);

            // verify for joins that required views are present
            StreamJoinAnalysisResultCompileTime joinAnalysisResult = StatementForgeMethodSelectUtil.VerifyJoinViews(statementSpec);

            var streamEventTypes = new EventType[statementSpec.StreamSpecs.Length];
            var eventTypeNames = new string[numStreams];
            var isNamedWindow = new bool[numStreams];
            var viewableActivatorForges = new ViewableActivatorForge[numStreams];
            var viewForges = new IList<ViewFactoryForge>[numStreams];
            var historicalEventViewables = new HistoricalEventViewableForge[numStreams];

            for (var stream = 0; stream < numStreams; stream++) {
                var streamSpec = statementSpec.StreamSpecs[stream];
                var isCanIterateUnbound = streamSpec.ViewSpecs.Length == 0 &&
                                          (services.Configuration.Compiler.ViewResources.IsIterableUnbound ||
                                           AnnotationUtil.HasAnnotation(statementSpec.Annotations, typeof(IterableUnboundAttribute)));

                var args = new ViewFactoryForgeArgs(
                    stream,
                    false,
                    -1,
                    streamSpec.Options,
                    null,
                    @base.StatementRawInfo,
                    services);

                if (dataflowOperator) {
                    var dfResult = HandleDataflowActivation(args, streamSpec);
                    streamEventTypes[stream] = dfResult.StreamEventType;
                    eventTypeNames[stream] = dfResult.EventTypeName;
                    viewableActivatorForges[stream] = dfResult.ViewableActivatorForge;
                    viewForges[stream] = dfResult.ViewForges;
                    additionalForgeables.AddAll(dfResult.AdditionalForgeables);
                }
                else if (streamSpec is FilterStreamSpecCompiled) {
                    var filterStreamSpec = (FilterStreamSpecCompiled) statementSpec.StreamSpecs[stream];
                    var filterSpecCompiled = filterStreamSpec.FilterSpecCompiled;
                    streamEventTypes[stream] = filterSpecCompiled.ResultEventType;
                    eventTypeNames[stream] = filterStreamSpec.FilterSpecCompiled.FilterForEventTypeName;

                    viewableActivatorForges[stream] = new ViewableActivatorFilterForge(
                        filterSpecCompiled,
                        isCanIterateUnbound,
                        stream,
                        false,
                        -1);
                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, streamEventTypes[stream]);
                    viewForges[stream] = viewForgeDesc.Forges;
                    additionalForgeables.AddAll(viewForgeDesc.MultikeyForges);
                    filterSpecCompileds.Add(filterSpecCompiled);
                }
                else if (streamSpec is PatternStreamSpecCompiled) {
                    var patternStreamSpec = (PatternStreamSpecCompiled) streamSpec;
                    var forges = patternStreamSpec.Root.CollectFactories();
                    foreach (var forgeNode in forges) {
                        forgeNode.CollectSelfFilterAndSchedule(filterSpecCompileds, scheduleHandleCallbackProviders);
                    }

                    var patternType = ViewableActivatorPatternForge.MakeRegisterPatternType(
                        @base,
                        stream,
                        patternStreamSpec,
                        services);
                    var patternContext = new PatternContext(0, patternStreamSpec.MatchedEventMapMeta, false, -1, false);
                    viewableActivatorForges[stream] = new ViewableActivatorPatternForge(
                        patternType,
                        patternStreamSpec,
                        patternContext,
                        isCanIterateUnbound);
                    streamEventTypes[stream] = patternType;
                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, patternType);
                    viewForges[stream] = viewForgeDesc.Forges;
                    additionalForgeables.AddAll(viewForgeDesc.MultikeyForges);
                }
                else if (streamSpec is NamedWindowConsumerStreamSpec) {
                    var namedSpec = (NamedWindowConsumerStreamSpec) streamSpec;
                    var namedWindow =
                        services.NamedWindowCompileTimeResolver.Resolve(namedSpec.NamedWindow.EventType.Name);
                    var namedWindowType = namedWindow.EventType;
                    if (namedSpec.OptPropertyEvaluator != null) {
                        namedWindowType = namedSpec.OptPropertyEvaluator.FragmentEventType;
                    }

                    var typesFilterValidation = new StreamTypeServiceImpl(
                        namedWindowType,
                        namedSpec.OptionalStreamName,
                        false);
                    var filterSingle =
                        ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(namedSpec.FilterExpressions);
                    var filterQueryGraph = EPLValidationUtil.ValidateFilterGetQueryGraphSafe(
                        filterSingle,
                        typesFilterValidation,
                        @base.StatementRawInfo,
                        services);

                    namedWindowConsumers.Add(namedSpec);
                    viewableActivatorForges[stream] = new ViewableActivatorNamedWindowForge(
                        namedSpec,
                        namedWindow,
                        filterSingle,
                        filterQueryGraph,
                        true,
                        namedSpec.OptPropertyEvaluator);
                    streamEventTypes[stream] = namedWindowType;
                    viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>();
                    joinAnalysisResult.SetNamedWindowsPerStream(stream, namedWindow);
                    eventTypeNames[stream] = namedSpec.NamedWindow.EventType.Name;
                    isNamedWindow[stream] = true;

                    // Consumers to named windows cannot declare a data window view onto the named window to avoid duplicate remove streams
                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(streamSpec.ViewSpecs, args, namedWindowType);
                    viewForges[stream] = viewForgeDesc.Forges;
                    additionalForgeables.AddAll(viewForgeDesc.MultikeyForges);

                    EPStatementStartMethodHelperValidate.ValidateNoDataWindowOnNamedWindow(viewForges[stream]);
                }
                else if (streamSpec is TableQueryStreamSpec) {
                    ValidateNoViews(streamSpec, "Table data");
                    var tableStreamSpec = (TableQueryStreamSpec) streamSpec;
                    if (numStreams > 1 && tableStreamSpec.FilterExpressions.Count > 0) {
                        throw new ExprValidationException(
                            "Joins with tables do not allow table filter expressions, please add table filters to the where-clause instead");
                    }

                    var table = tableStreamSpec.Table;
                    EPLValidationUtil.ValidateContextName(
                        true,
                        table.TableName,
                        table.OptionalContextName,
                        statementSpec.Raw.OptionalContextName,
                        false);
                    var filter =
                        ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(tableStreamSpec.FilterExpressions);
                    viewableActivatorForges[stream] = new ViewableActivatorTableForge(table, filter);
                    viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>();
                    eventTypeNames[stream] = tableStreamSpec.Table.TableName;
                    streamEventTypes[stream] = tableStreamSpec.Table.InternalEventType;
                    joinAnalysisResult.SetTablesForStream(stream, table);

                    if (tableStreamSpec.Options.IsUnidirectional) {
                        throw new ExprValidationException("Tables cannot be marked as unidirectional");
                    }

                    if (tableStreamSpec.Options.IsRetainIntersection || tableStreamSpec.Options.IsRetainUnion) {
                        throw new ExprValidationException("Tables cannot be marked with retain");
                    }
                }
                else if (streamSpec is DBStatementStreamSpec) {
                    ValidateNoViews(streamSpec, "Historical data");
                    var sqlStreamSpec = (DBStatementStreamSpec) streamSpec;
                    var typeConversionHook = (SQLColumnTypeConversion) ImportUtil.GetAnnotationHook(
                        statementSpec.Annotations,
                        HookType.SQLCOL,
                        typeof(SQLColumnTypeConversion),
                        services.ImportServiceCompileTime);
                    var outputRowConversionHook = (SQLOutputRowConversion) ImportUtil.GetAnnotationHook(
                        statementSpec.Annotations,
                        HookType.SQLROW,
                        typeof(SQLOutputRowConversion),
                        services.ImportServiceCompileTime);
                    var viewable = HistoricalEventViewableDatabaseForgeFactory.CreateDBStatementView(
                        stream,
                        sqlStreamSpec,
                        typeConversionHook,
                        outputRowConversionHook,
                        @base,
                        services,
                        statementSpec.Annotations);
                    streamEventTypes[stream] = viewable.EventType;
                    viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>();
                    viewableActivatorForges[stream] = new ViewableActivatorHistoricalForge(viewable);
                    historicalEventViewables[stream] = viewable;
                }
                else if (streamSpec is MethodStreamSpec) {
                    ValidateNoViews(streamSpec, "Method data");
                    var methodStreamSpec = (MethodStreamSpec) streamSpec;
                    var viewable = HistoricalEventViewableMethodForgeFactory.CreateMethodStatementView(
                        stream,
                        methodStreamSpec,
                        @base,
                        services);
                    historicalEventViewables[stream] = viewable;
                    streamEventTypes[stream] = viewable.EventType;
                    viewForges[stream] = Collections.GetEmptyList<ViewFactoryForge>();
                    viewableActivatorForges[stream] = new ViewableActivatorHistoricalForge(viewable);
                    historicalEventViewables[stream] = viewable;
                }
                else {
                    throw new IllegalStateException("Unrecognized stream " + streamSpec);
                }
                
                // plan serde for iterate-unbound
                if (isCanIterateUnbound) {
                    var serdeForgeables = SerdeEventTypeUtility.Plan(
                        streamEventTypes[stream], @base.StatementRawInfo, services.SerdeEventTypeRegistry, services.SerdeResolver);
                    additionalForgeables.AddAll(serdeForgeables);
                }
            }

            // handle match-recognize pattern
            if (statementSpec.Raw.MatchRecognizeSpec != null) {
                if (numStreams > 1) {
                    throw new ExprValidationException("Joins are not allowed when using match-recognize");
                }

                if (joinAnalysisResult.TablesPerStream[0] != null) {
                    throw new ExprValidationException("Tables cannot be used with match-recognize");
                }

                var isUnbound = viewForges[0].IsEmpty() &&
                                !(statementSpec.StreamSpecs[0] is NamedWindowConsumerStreamSpec);
                var eventType = viewForges[0].IsEmpty()
                    ? streamEventTypes[0]
                    : viewForges[0][(viewForges[0].Count - 1)].EventType;
                
                var plan = RowRecogNFAViewPlanUtil.ValidateAndPlan(services.Container, eventType, isUnbound, @base, services);
                var forge = new RowRecogNFAViewFactoryForge(plan.Forge);
                additionalForgeables.AddAll(plan.AdditionalForgeables);
                scheduleHandleCallbackProviders.Add(forge);
                viewForges[0].Add(forge);
                var serdeForgeables = SerdeEventTypeUtility.Plan(
                    eventType, @base.StatementRawInfo, services.SerdeEventTypeRegistry, services.SerdeResolver);
                additionalForgeables.AddAll(serdeForgeables);
            }

            // Obtain event types from view factory chains
            for (var i = 0; i < viewForges.Length; i++) {
                streamEventTypes[i] = viewForges[i].IsEmpty()
                    ? streamEventTypes[i]
                    : viewForges[i][(viewForges[i].Count - 1)].EventType;
            }

            // add unique-information to join analysis
            joinAnalysisResult.AddUniquenessInfo(viewForges, statementSpec.Annotations);

            // plan sub-selects
            SubSelectHelperForgePlan subselectForgePlan = SubSelectHelperForgePlanner.PlanSubSelect(
                @base, subselectActivation, streamNames, streamEventTypes, eventTypeNames, services);
            var subselectForges = subselectForgePlan.Subselects;
            additionalForgeables.AddAll(subselectForgePlan.AdditionalForgeables);

            DetermineViewSchedules(subselectForges, scheduleHandleCallbackProviders);

            // determine view schedules
            var viewResourceDelegateExpr = new ViewResourceDelegateExpr();
            ViewFactoryForgeUtil.DetermineViewSchedules(viewForges, scheduleHandleCallbackProviders);

            var hasIStreamOnly = StatementForgeMethodSelectUtil.GetHasIStreamOnly(isNamedWindow, viewForges);
            var optionalStreamsIfAny = OuterJoinAnalyzer.OptionalStreamsIfAny(statementSpec.Raw.OuterJoinDescList);
            StreamTypeService typeService = new StreamTypeServiceImpl(
                streamEventTypes,
                streamNames,
                hasIStreamOnly,
                false,
                optionalStreamsIfAny);

            // Validate views that require validation, specifically streams that don't have
            // sub-views such as DB SQL joins
            var historicalViewableDesc = new HistoricalViewableDesc(numStreams);
            for (var stream = 0; stream < historicalEventViewables.Length; stream++) {
                var historicalEventViewable = historicalEventViewables[stream];
                if (historicalEventViewable == null) {
                    continue;
                }

                scheduleHandleCallbackProviders.Add(historicalEventViewable);
                IList<StmtClassForgeableFactory> forgeables = historicalEventViewable.Validate(typeService, @base, services);
                additionalForgeables.AddAll(forgeables);
                historicalViewableDesc.SetHistorical(stream, historicalEventViewable.RequiredStreams);
                if (historicalEventViewable.RequiredStreams.Contains(stream)) {
                    throw new ExprValidationException(
                        "Parameters for historical stream " +
                        stream +
                        " indicate that the stream is subordinate to itself as stream parameters originate in the same stream");
                }
            }

            // Validate where-clause filter tree, outer join clause and output limit expression
            var whereClauseValidated = EPStatementStartMethodHelperValidate.ValidateNodes(
                statementSpec.Raw,
                typeService,
                viewResourceDelegateExpr,
                @base.StatementRawInfo,
                services);
            var whereClauseForge = whereClauseValidated?.Forge;

            // Obtain result set processor
            var resultSetProcessorDesc = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                new ResultSetSpec(statementSpec),
                typeService,
                viewResourceDelegateExpr,
                joinAnalysisResult.UnidirectionalInd,
                true,
                @base.ContextPropertyRegistry,
                false,
                false,
                @base.StatementRawInfo,
                services);
            additionalForgeables.AddAll(resultSetProcessorDesc.AdditionalForgeables);

            // Handle 'prior' function nodes in terms of view requirements
            var viewResourceDelegateDesc =
                ViewResourceVerifyHelper.VerifyPreviousAndPriorRequirements(viewForges, viewResourceDelegateExpr);
            var hasPrior = ViewResourceDelegateDesc.HasPrior(viewResourceDelegateDesc);
            if (hasPrior) {
                for (var stream = 0; stream < numStreams; stream++) {
                    if (!viewResourceDelegateDesc[stream].PriorRequests.IsEmpty()) {
                        viewForges[stream].Add(new PriorEventViewForge(viewForges[stream].IsEmpty(), streamEventTypes[stream]));
                        var serdeForgeables = SerdeEventTypeUtility.Plan(
                            streamEventTypes[stream], @base.StatementRawInfo, services.SerdeEventTypeRegistry, services.SerdeResolver);
                        additionalForgeables.AddAll(serdeForgeables);
                    }
                }
            }

            var outputProcessDesc = OutputProcessViewForgeFactory.Make(
                typeService.EventTypes,
                resultSetProcessorDesc.ResultEventType,
                resultSetProcessorDesc.ResultSetProcessorType,
                statementSpec,
                @base.StatementRawInfo,
                services);
            var outputProcessViewFactoryForge = outputProcessDesc.Forge;
            additionalForgeables.AddAll(outputProcessDesc.AdditionalForgeables);
            outputProcessViewFactoryForge.CollectSchedules(scheduleHandleCallbackProviders);

            JoinSetComposerPrototypeForge joinForge = null;
            if (numStreams > 1) {
                var hasAggregations = !resultSetProcessorDesc.AggregationServiceForgeDesc.Expressions.IsEmpty();
                var desc = JoinSetComposerPrototypeForgeFactory.MakeComposerPrototype(
                    statementSpec,
                    joinAnalysisResult,
                    typeService,
                    historicalViewableDesc,
                    false,
                    hasAggregations,
                    @base.StatementRawInfo,
                    services);
                joinForge = desc.Forge;
                additionalForgeables.AddAll(desc.AdditionalForgeables);
                HandleIndexDependencies(joinForge.OptionalQueryPlan, services);
            }

            // plan table access
            var tableAccessForges =
                ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);
            ValidateTableAccessUse(statementSpec.Raw.IntoTableSpec, statementSpec.Raw.TableExpressions);
            if (joinAnalysisResult.IsUnidirectional && statementSpec.Raw.IntoTableSpec != null) {
                throw new ExprValidationException("Into-table does not allow unidirectional joins");
            }

            var orderByWithoutOutputLimit = statementSpec.Raw.OrderByList != null &&
                                            !statementSpec.Raw.OrderByList.IsEmpty() &&
                                            statementSpec.Raw.OutputLimitSpec == null;

            var statementAIFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(StatementAIFactoryProvider),
                classPostfix);
            var resultSetProcessorProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(ResultSetProcessorFactoryProvider),
                classPostfix);
            var outputProcessViewProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(
                typeof(OutputProcessViewFactoryProvider),
                classPostfix);
            var statementProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            var statementFieldsClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix);
            //var statementFieldsClassName = namespaceScope.FieldsClassNameOptional;

            var forgeX = new StatementAgentInstanceFactorySelectForge(
                typeService.StreamNames,
                viewableActivatorForges,
                resultSetProcessorProviderClassName,
                viewForges,
                viewResourceDelegateDesc,
                whereClauseForge,
                joinForge,
                outputProcessViewProviderClassName,
                subselectForges,
                tableAccessForges,
                orderByWithoutOutputLimit,
                joinAnalysisResult.IsUnidirectional);

            var namespaceScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            var forgeablesX = additionalForgeables
                .Select(additional => additional.Make(namespaceScope, classPostfix))
                .ToList();

            forgeablesX.Add(
                new StmtClassForgeableRSPFactoryProvider(
                    resultSetProcessorProviderClassName,
                    resultSetProcessorDesc,
                    namespaceScope,
                    @base.StatementRawInfo));
            forgeablesX.Add(
                new StmtClassForgeableOPVFactoryProvider(
                    outputProcessViewProviderClassName,
                    outputProcessViewFactoryForge,
                    namespaceScope,
                    numStreams,
                    @base.StatementRawInfo));
            forgeablesX.Add(
                new StmtClassForgeableAIFactoryProviderSelect(statementAIFactoryProviderClassName, namespaceScope, forgeX));
            forgeablesX.Add(
                new StmtClassForgeableStmtFields(statementFieldsClassName, namespaceScope, numStreams));

            if (!dataflowOperator) {
                var informationals = StatementInformationalsUtil.GetInformationals(
                    @base,
                    filterSpecCompileds,
                    scheduleHandleCallbackProviders,
                    namedWindowConsumers,
                    true,
                    resultSetProcessorDesc.SelectSubscriberDescriptor,
                    namespaceScope,
                    services);
                forgeablesX.Add(
                    new StmtClassForgeableStmtProvider(statementAIFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope));
            }

            var forgeableResult = new StmtForgeMethodResult(
                forgeablesX,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                namedWindowConsumers,
                FilterSpecCompiled.MakeExprNodeList(filterSpecCompileds, EmptyList<FilterSpecParamExprNodeForge>.Instance));
            return new StmtForgeMethodSelectResult(forgeableResult, resultSetProcessorDesc.ResultEventType, numStreams);
        }