public OutputConditionTimeForge( ExprTimePeriod timePeriod, bool isStartConditionOnCreation) { this.timePeriod = timePeriod; this.isStartConditionOnCreation = isStartConditionOnCreation; }
public OutputProcessViewConditionForge( OutputStrategyPostProcessForge outputStrategyPostProcessForge, bool isDistinct, MultiKeyClassRef distinctMultiKey, ExprTimePeriod afterTimePeriodExpr, int? afterNumberOfEvents, OutputConditionFactoryForge outputConditionFactoryForge, int streamCount, ResultSetProcessorOutputConditionType conditionType, bool terminable, bool hasAfter, bool unaggregatedUngrouped, SelectClauseStreamSelectorEnum selectClauseStreamSelector, EventType[] eventTypes, EventType resultEventType) { _outputStrategyPostProcessForge = outputStrategyPostProcessForge; _isDistinct = isDistinct; _distinctMultiKey = distinctMultiKey; _afterTimePeriodExpr = afterTimePeriodExpr; _afterNumberOfEvents = afterNumberOfEvents; _outputConditionFactoryForge = outputConditionFactoryForge; _streamCount = streamCount; _conditionType = conditionType; _terminable = terminable; _hasAfter = hasAfter; _unaggregatedUngrouped = unaggregatedUngrouped; _selectClauseStreamSelector = selectClauseStreamSelector; _eventTypes = eventTypes; _resultEventType = resultEventType; }
public long ComputeMilliseconds(MatchedEventMap beginState, PatternAgentInstanceContext context) { if (_parameter is ExprTimePeriod) { ExprTimePeriod timePeriod = (ExprTimePeriod)_parameter; return(timePeriod.NonconstEvaluator().DeltaMillisecondsUseEngineTime( _convertor.Convert(beginState), context.AgentInstanceContext)); } else { var result = _parameter.ExprEvaluator.Evaluate(new EvaluateParams(_convertor.Convert(beginState), true, context.AgentInstanceContext)); if (result == null) { throw new EPException("Null value returned for guard expression"); } if (result.IsFloatingPointNumber()) { return((long)Math.Round(1000d * result.AsDouble())); } else { return(1000 * result.AsLong()); } } }
public ContextSpecConditionTimePeriod( ExprTimePeriod timePeriod, bool immediate) { TimePeriod = timePeriod; IsImmediate = immediate; }
/// <summary> /// Ctor. For batching events by event count. /// </summary> /// <param name="rate">is the fixed output rate, or null if by variable</param> /// <param name="variableForRate">an optional variable name instead of the rate</param> /// <param name="rateType">type of the rate</param> /// <param name="displayLimit">indicates whether to output only the first, only the last, or all events</param> /// <param name="whenExpressionNode">for controlling output by a bool expression</param> /// <param name="thenExpressions">variable assignments, if null if none</param> /// <param name="crontabAtSchedule">crontab parameters</param> /// <param name="timePeriodExpr">the time period, or null if none</param> /// <param name="afterTimePeriodExpr">after-keyword time period</param> /// <param name="afterNumberOfEvents">after-keyword number of events</param> /// <param name="isAndAfterTerminate">if set to <c>true</c> [and after terminate].</param> /// <param name="andAfterTerminateExpr">The and after terminate expr.</param> /// <param name="andAfterTerminateSetExpressions">The and after terminate set expressions.</param> public OutputLimitSpec(double?rate, String variableForRate, OutputLimitRateType rateType, OutputLimitLimitType displayLimit, ExprNode whenExpressionNode, IList <OnTriggerSetAssignment> thenExpressions, IList <ExprNode> crontabAtSchedule, ExprTimePeriod timePeriodExpr, ExprTimePeriod afterTimePeriodExpr, int?afterNumberOfEvents, bool isAndAfterTerminate, ExprNode andAfterTerminateExpr, IList <OnTriggerSetAssignment> andAfterTerminateSetExpressions) { Rate = rate; DisplayLimit = displayLimit; VariableName = variableForRate; RateType = rateType; CrontabAtSchedule = crontabAtSchedule; WhenExpressionNode = whenExpressionNode; ThenExpressions = thenExpressions; TimePeriodExpr = timePeriodExpr; AfterTimePeriodExpr = afterTimePeriodExpr; AfterNumberOfEvents = afterNumberOfEvents; IsAndAfterTerminate = isAndAfterTerminate; AndAfterTerminateExpr = andAfterTerminateExpr; AndAfterTerminateThenExpressions = andAfterTerminateSetExpressions; }
/// <summary> /// Ctor. /// </summary> /// <param name="timePeriodExpr">time period</param> /// <param name="orTerminated">or-terminated indicator</param> public MatchRecognizeInterval( ExprTimePeriod timePeriodExpr, bool orTerminated) { TimePeriodExpr = timePeriodExpr; IsOrTerminated = orTerminated; }
public OutputProcessViewDirectDistinctOrAfterFactory( StatementContext statementContext, OutputStrategyPostProcessFactory postProcessFactory, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, bool distinct, ExprTimePeriod afterTimePeriod, int?afterConditionNumberOfEvents, EventType resultEventType) : base(statementContext, postProcessFactory, resultSetProcessorHelperFactory) { _isDistinct = distinct; AfterTimePeriod = afterTimePeriod; AfterConditionNumberOfEvents = afterConditionNumberOfEvents; if (_isDistinct) { if (resultEventType is EventTypeSPI) { EventTypeSPI eventTypeSPI = (EventTypeSPI)resultEventType; _eventBeanReader = eventTypeSPI.Reader; } if (_eventBeanReader == null) { _eventBeanReader = new EventBeanReaderDefaultImpl(resultEventType); } } }
public IntervalDeltaExprTimePeriodNonConstForge( ExprTimePeriod timePeriod, TimeAbacus timeAbacus) { this.timePeriod = timePeriod; this.timeAbacus = timeAbacus; }
public OutputProcessViewConditionFactory( StatementContext statementContext, OutputStrategyPostProcessFactory postProcessFactory, bool distinct, ExprTimePeriod afterTimePeriod, int?afterConditionNumberOfEvents, EventType resultEventType, OutputConditionFactory outputConditionFactory, int streamCount, ConditionType conditionType, OutputLimitLimitType outputLimitLimitType, bool terminable, bool hasAfter, bool isUnaggregatedUngrouped, SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum) : base(statementContext, postProcessFactory, distinct, afterTimePeriod, afterConditionNumberOfEvents, resultEventType) { _outputConditionFactory = outputConditionFactory; _streamCount = streamCount; _conditionType = conditionType; _outputLimitLimitType = outputLimitLimitType; _terminable = terminable; _hasAfter = hasAfter; _isUnaggregatedUngrouped = isUnaggregatedUngrouped; _selectClauseStreamSelectorEnum = selectClauseStreamSelectorEnum; }
public TimerScheduleSpecComputeFromExprForge( ExprNode dateNode, ExprNode repetitionsNode, ExprTimePeriod periodNode) { this.dateNode = dateNode; this.repetitionsNode = repetitionsNode; this.periodNode = periodNode; }
internal TimerScheduleSpecComputeFromExpr( ExprNode dateNode, ExprNode repetitionsNode, ExprTimePeriod periodNode) { _dateNode = dateNode; _repetitionsNode = repetitionsNode; _periodNode = periodNode; }
public OutputConditionPolledTimeFactory(ExprTimePeriod timePeriod, StatementContext statementContext) { _timePeriod = timePeriod; var numSeconds = timePeriod.EvaluateAsSeconds(null, true, new ExprEvaluatorContextStatement(statementContext, false)); if ((numSeconds < 0.001) && (!timePeriod.HasVariable)) { throw new ArgumentException("Output condition by time requires a interval size of at least 1 msec or a variable"); } }
public OutputProcessViewDirectDistinctOrAfterFactoryForge( OutputStrategyPostProcessForge outputStrategyPostProcessForge, bool isDistinct, MultiKeyClassRef distinctMultiKey, ExprTimePeriod afterTimePeriod, int? afterConditionNumberOfEvents, EventType resultEventType) { _outputStrategyPostProcessForge = outputStrategyPostProcessForge; _isDistinct = isDistinct; DistinctMultiKey = distinctMultiKey; AfterTimePeriod = afterTimePeriod; AfterConditionNumberOfEvents = afterConditionNumberOfEvents; ResultEventType = resultEventType; }
/// <summary> /// Evaluate the pattern expression. /// </summary> /// <param name="objectName">pattern object name</param> /// <param name="beginState">pattern state</param> /// <param name="convertor">to converting from pattern match to event-per-stream</param> /// <param name="exprEvaluatorContext">expression evaluation context</param> /// <param name="timePeriod">time period</param> /// <exception cref="EPException">if the evaluation failed</exception> /// <returns>evaluation result</returns> public static Object EvaluateTimePeriod( string objectName, MatchedEventMap beginState, ExprTimePeriod timePeriod, MatchedEventConvertor convertor, ExprEvaluatorContext exprEvaluatorContext) { EventBean[] eventsPerStream = convertor.Convert(beginState); try { return(timePeriod.EvaluateGetTimePeriod(new EvaluateParams(eventsPerStream, true, exprEvaluatorContext))); } catch (Exception ex) { throw HandleRuntimeEx(ex, objectName); } }
/// <summary> /// Constructor. /// </summary> /// <param name="timePeriod">is the number of minutes or seconds to batch events for, may include variables</param> /// <param name="context">is the view context for time scheduling</param> public OutputConditionPolledTime(ExprTimePeriod timePeriod, AgentInstanceContext context) { if (context == null) { const string message = "OutputConditionTime requires a non-null view context"; throw new ArgumentNullException(message); } _context = context; _timePeriod = timePeriod; double numSeconds = timePeriod.EvaluateAsSeconds(null, true, context); if ((numSeconds < 0.001) && (!timePeriod.HasVariable)) { throw new ArgumentException("Output condition by time requires a interval size of at least 1 msec or a variable"); } }
private static ContextDetailCondition GetContextCondition(EsperEPL2GrammarParser.CreateContextRangePointContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, IDictionary <ITree, EvalFactoryNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec, bool immediate) { if (ctx.crontabLimitParameterSet() != null) { IList <ExprNode> crontab = ASTExprHelper.ExprCollectSubNodes(ctx.crontabLimitParameterSet(), 0, astExprNodeMap); return(new ContextDetailConditionCrontab(crontab, immediate)); } else if (ctx.patternInclusionExpression() != null) { EvalFactoryNode evalNode = ASTExprHelper.PatternGetRemoveTopNode(ctx.patternInclusionExpression(), astPatternNodeMap); bool inclusive = false; if (ctx.i != null) { String ident = ctx.i.Text; if (ident != null && ident.ToLower() != "inclusive") { throw ASTWalkException.From("Expected 'inclusive' keyword after '@', found '" + ident + "' instead"); } inclusive = true; } return(new ContextDetailConditionPattern(evalNode, inclusive, immediate)); } else if (ctx.createContextFilter() != null) { FilterSpecRaw filterSpecRaw = ASTFilterSpecHelper.WalkFilterSpec(ctx.createContextFilter().eventFilterExpression(), propertyEvalSpec, astExprNodeMap); String asName = ctx.createContextFilter().i != null?ctx.createContextFilter().i.Text : null; if (immediate) { throw ASTWalkException.From("Invalid use of 'now' with initiated-by stream, this combination is not supported"); } return(new ContextDetailConditionFilter(filterSpecRaw, asName)); } else if (ctx.AFTER() != null) { ExprTimePeriod timePeriod = (ExprTimePeriod)ASTExprHelper.ExprCollectSubNodes(ctx.timePeriod(), 0, astExprNodeMap)[0]; return(new ContextDetailConditionTimePeriod(timePeriod, immediate)); } else { throw new IllegalStateException("Unrecognized child type"); } }
public long ComputeMilliseconds(MatchedEventMap beginState, PatternAgentInstanceContext context) { if (MillisecondsExpr is ExprTimePeriod) { ExprTimePeriod timePeriod = (ExprTimePeriod)MillisecondsExpr; return(timePeriod.NonconstEvaluator() .DeltaMillisecondsUseEngineTime(Convertor.Convert(beginState), context.AgentInstanceContext)); } else { Object millisecondVal = PatternExpressionUtil.Evaluate( "Timer-within guard", beginState, MillisecondsExpr, Convertor, context.AgentInstanceContext); if (millisecondVal == null) { throw new EPException("Timer-within guard expression returned a null-value"); } return((long)Math.Round(1000d * millisecondVal.AsDouble())); } }
public static ExprTimePeriodEvalDeltaConst ValidateAndEvaluateTimeDelta(String viewName, StatementContext statementContext, ExprNode expression, String expectedMessage, int expressionNumber) { StreamTypeService streamTypeService = new StreamTypeServiceImpl(statementContext.EngineURI, false); ExprTimePeriodEvalDeltaConst timeDelta; if (expression is ExprTimePeriod) { ExprTimePeriod validated = (ExprTimePeriod)ViewFactorySupport.ValidateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber); timeDelta = validated.ConstEvaluator(new ExprEvaluatorContextStatement(statementContext, false)); } else { var result = ViewFactorySupport.ValidateAndEvaluateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber); if (!result.IsNumber()) { throw new ViewParameterException(expectedMessage); } long millisecondsBeforeExpiry; if (TypeHelper.IsFloatingPointNumber(result)) { millisecondsBeforeExpiry = (long)Math.Round(1000d * result.AsDouble()); } else { millisecondsBeforeExpiry = 1000 * result.AsLong(); } timeDelta = new ExprTimePeriodEvalDeltaConstMsec(millisecondsBeforeExpiry); } if (timeDelta.DeltaMillisecondsAdd(0) < 1) { throw new ViewParameterException(viewName + " view requires a size of at least 1 msec"); } return(timeDelta); }
public void SetObserverParameters(IList<ExprNode> parameters, MatchedEventConvertor convertor, ExprValidationContext validationContext) { Convertor = convertor; // obtains name parameters IDictionary<string, ExprNamedParameterNode> namedExpressions; try { namedExpressions = ExprNodeUtility.GetNamedExpressionsHandleDups(parameters); ExprNodeUtility.ValidateNamed(namedExpressions, NAMED_PARAMETERS); } catch (ExprValidationException e) { throw new ObserverParameterException(e.Message, e); } bool allConstantResult; ExprNamedParameterNode isoStringExpr = namedExpressions.Get(ISO_NAME); if (namedExpressions.Count == 1 && isoStringExpr != null) { try { allConstantResult = ExprNodeUtility.ValidateNamedExpectType( isoStringExpr, new Type[] { typeof (string) }); } catch (ExprValidationException ex) { throw new ObserverParameterException(ex.Message, ex); } ScheduleComputer = new TimerScheduleSpecComputeISOString(isoStringExpr.ChildNodes[0]); } else if (isoStringExpr != null) { throw new ObserverParameterException( "The '" + ISO_NAME + "' parameter is exclusive of other parameters"); } else if (namedExpressions.Count == 0) { throw new ObserverParameterException("No parameters provided"); } else { allConstantResult = true; ExprNamedParameterNode dateNamedNode = namedExpressions.Get(DATE_NAME); ExprNamedParameterNode repetitionsNamedNode = namedExpressions.Get(REPETITIONS_NAME); ExprNamedParameterNode periodNamedNode = namedExpressions.Get(PERIOD_NAME); if (dateNamedNode == null && periodNamedNode == null) { throw new ObserverParameterException("Either the date or period parameter is required"); } try { if (dateNamedNode != null) { allConstantResult = ExprNodeUtility.ValidateNamedExpectType( dateNamedNode, new Type[] { typeof (string), typeof (DateTime), typeof (DateTimeOffset), typeof (long?) }); } if (repetitionsNamedNode != null) { allConstantResult &= ExprNodeUtility.ValidateNamedExpectType( repetitionsNamedNode, new Type[] { typeof (int?), typeof (long?) }); } if (periodNamedNode != null) { allConstantResult &= ExprNodeUtility.ValidateNamedExpectType( periodNamedNode, new Type[] { typeof (TimePeriod) }); } } catch (ExprValidationException ex) { throw new ObserverParameterException(ex.Message, ex); } ExprNode dateNode = dateNamedNode == null ? null : dateNamedNode.ChildNodes[0]; ExprNode repetitionsNode = repetitionsNamedNode == null ? null : repetitionsNamedNode.ChildNodes[0]; ExprTimePeriod periodNode = periodNamedNode == null ? null : (ExprTimePeriod) periodNamedNode.ChildNodes[0]; ScheduleComputer = new TimerScheduleSpecComputeFromExpr(dateNode, repetitionsNode, periodNode); } if (allConstantResult) { try { Spec = ScheduleComputer.Compute( convertor, new MatchedEventMapImpl(convertor.MatchedEventMapMeta), null, validationContext.MethodResolutionService.EngineImportService.TimeZone); } catch (ScheduleParameterException ex) { throw new ObserverParameterException(ex.Message, ex); } } }
public void Validate(ExprValidationContext validationContext) { _timePeriodExpr = (ExprTimePeriod)ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGINTERVAL, _timePeriodExpr, validationContext); }
/// <summary> /// Build an output limit spec from the AST node supplied. /// </summary> /// <param name="astExprNodeMap">is the map of current AST tree nodes to their respective expression root node</param> /// <param name="engineURI">the engine uri</param> /// <param name="timeProvider">provides time</param> /// <param name="variableService">provides variable resolution</param> /// <param name="exprEvaluatorContext">context for expression evaluatiom</param> /// <returns>output limit spec</returns> public static OutputLimitSpec BuildOutputLimitSpec( CommonTokenStream tokenStream, EsperEPL2GrammarParser.OutputLimitContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, VariableService variableService, String engineURI, TimeProvider timeProvider, ExprEvaluatorContext exprEvaluatorContext) { OutputLimitLimitType displayLimit = OutputLimitLimitType.DEFAULT; if (ctx.k != null) { switch (ctx.k.Type) { case EsperEPL2GrammarParser.FIRST: displayLimit = OutputLimitLimitType.FIRST; break; case EsperEPL2GrammarParser.LAST: displayLimit = OutputLimitLimitType.LAST; break; case EsperEPL2GrammarParser.SNAPSHOT: displayLimit = OutputLimitLimitType.SNAPSHOT; break; case EsperEPL2GrammarParser.ALL: displayLimit = OutputLimitLimitType.ALL; break; default: throw ASTWalkException.From("Encountered unrecognized token " + ctx.k.Text, tokenStream, ctx); } } // next is a variable, or time period, or number String variableName = null; double? rate = null; ExprNode whenExpression = null; IList <ExprNode> crontabScheduleSpec = null; IList <OnTriggerSetAssignment> thenExpressions = null; ExprTimePeriod timePeriodExpr = null; OutputLimitRateType rateType; ExprNode andAfterTerminateExpr = null; IList <OnTriggerSetAssignment> andAfterTerminateSetExpressions = null; if (ctx.t != null) { rateType = OutputLimitRateType.TERM; if (ctx.expression() != null) { andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0]; } if (ctx.onSetExpr() != null) { andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap); } } else if (ctx.wh != null) { rateType = OutputLimitRateType.WHEN_EXPRESSION; whenExpression = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0]; if (ctx.onSetExpr() != null) { thenExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap); } } else if (ctx.at != null) { rateType = OutputLimitRateType.CRONTAB; crontabScheduleSpec = ASTExprHelper.ExprCollectSubNodes(ctx.crontabLimitParameterSet(), 0, astExprNodeMap); } else { if (ctx.ev != null) { rateType = ctx.e != null ? OutputLimitRateType.EVENTS : OutputLimitRateType.TIME_PERIOD; if (ctx.i != null) { variableName = ctx.i.Text; } else if (ctx.timePeriod() != null) { timePeriodExpr = (ExprTimePeriod)ASTExprHelper.ExprCollectSubNodes(ctx.timePeriod(), 0, astExprNodeMap)[0]; } else { ASTExprHelper.ExprCollectSubNodes(ctx.number(), 0, astExprNodeMap); // remove rate = Double.Parse(ctx.number().GetText()); } } else { rateType = OutputLimitRateType.AFTER; } } // get the AFTER time period ExprTimePeriod afterTimePeriodExpr = null; int? afterNumberOfEvents = null; if (ctx.outputLimitAfter() != null) { if (ctx.outputLimitAfter().timePeriod() != null) { ExprNode expression = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAfter(), 0, astExprNodeMap)[0]; afterTimePeriodExpr = (ExprTimePeriod)expression; } else { Object constant = ASTConstantHelper.Parse(ctx.outputLimitAfter().number()); afterNumberOfEvents = constant.AsInt(); } } bool andAfterTerminate = false; if (ctx.outputLimitAndTerm() != null) { andAfterTerminate = true; if (ctx.outputLimitAndTerm().expression() != null) { andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAndTerm().expression(), 0, astExprNodeMap)[0]; } if (ctx.outputLimitAndTerm().onSetExpr() != null) { andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.outputLimitAndTerm().onSetExpr().onSetAssignmentList(), astExprNodeMap); } } return(new OutputLimitSpec(rate, variableName, rateType, displayLimit, whenExpression, thenExpressions, crontabScheduleSpec, timePeriodExpr, afterTimePeriodExpr, afterNumberOfEvents, andAfterTerminate, andAfterTerminateExpr, andAfterTerminateSetExpressions)); }
public ContextDetailConditionTimePeriod(ExprTimePeriod timePeriod, bool immediate) { ScheduleCallbackId = -1; TimePeriod = timePeriod; IsImmediate = immediate; }
public OutputConditionPolledTimeFactoryForge(ExprTimePeriod timePeriod) { this.timePeriod = timePeriod; }
/// <summary> /// Constructor. /// </summary> /// <param name="timePeriod">is the number of minutes or seconds to batch events for, may include variables</param> /// <param name="isStartConditionOnCreation">if set to <c>true</c> [is start condition on creation].</param> public OutputConditionTimeFactory(ExprTimePeriod timePeriod, bool isStartConditionOnCreation) { _timePeriod = timePeriod; _timePeriodDeltaComputation = timePeriod.NonconstEvaluator(); _isStartConditionOnCreation = isStartConditionOnCreation; }
public OutputConditionFactory MakeOutputConditionTime(ExprTimePeriod timePeriodExpr, bool isStartConditionOnCreation) { return(new OutputConditionTimeFactory(timePeriodExpr, isStartConditionOnCreation)); }