public void ExecutePreload() { if (_nwActivator.NamedWindowContextName != null && !_nwActivator.NamedWindowContextName.Equals(_agentInstanceContext.StatementContext.ContextName)) { return; } ICollection <EventBean> snapshot = _consumer.ConsumerCallback.Snapshot(_nwActivator.FilterQueryGraph, _agentInstanceContext.Annotations); EventBean[] events; if (_consumer.Filter == null) { events = CollectionUtil.ToArrayEvents(snapshot); } else { IList <EventBean> eventsInWindow = new List <EventBean>(snapshot.Count); ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable(snapshot.GetEnumerator(), _consumer.Filter, _agentInstanceContext, eventsInWindow); events = eventsInWindow.ToArray(); } if (events.Length == 0) { return; } _consumer.Update(events, null); if (_joinPreloadMethod != null && !_joinPreloadMethod.IsPreloading) { _agentInstanceContext.EpStatementAgentInstanceHandle.OptionalDispatchable?.Execute(); } }
protected internal static ICollection<EventBean> Filtered( ICollection<EventBean> snapshot, ExprEvaluator filterExpressions, AgentInstanceContext agentInstanceContext) { ArrayDeque<EventBean> deque = new ArrayDeque<EventBean>(Math.Min(snapshot.Count, 16)); ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( snapshot.GetEnumerator(), filterExpressions, agentInstanceContext, deque); return deque; }
private ICollection<EventBean> SnapshotAndApplyFilter( QueryGraph queryGraph, Attribute[] annotations, ExprEvaluator filterExpr, AgentInstanceContext agentInstanceContext) { var indexedResult = SnapshotNullWhenNoIndex(queryGraph, annotations, null, null); if (indexedResult != null) { if (indexedResult.IsEmpty() || filterExpr == null) { return indexedResult; } var dequeX = new ArrayDeque<EventBean>(Math.Min(indexedResult.Count, 16)); ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( indexedResult.GetEnumerator(), filterExpr, agentInstanceContext, dequeX); return dequeX; } // fall back to window operator if snapshot doesn't resolve successfully var sourceCollection = instance.EventCollection; using (IEnumerator<EventBean> enumerator = sourceCollection.GetEnumerator()) { if (!enumerator.MoveNext()) { return new EmptyList<EventBean>(); } var deque = new ArrayDeque<EventBean>(sourceCollection.Count); if (filterExpr != null) { ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( sourceCollection.GetEnumerator(), filterExpr, agentInstanceContext, deque); } else { do { deque.Add(enumerator.Current); } while (enumerator.MoveNext()); } return deque; } }
public ICollection<EventBean> SnapshotNoLockWithFilter( QueryGraph filterQueryGraph, Attribute[] annotations, ExprEvaluator filterExpr, ExprEvaluatorContext exprEvaluatorContext) { var indexedResult = _rootViewInstance.Snapshot(filterQueryGraph, annotations); if (indexedResult != null) { if (indexedResult.IsEmpty()) { return indexedResult; } if (filterExpr == null) { return indexedResult; } var deque = new ArrayDeque<EventBean>(Math.Min(indexedResult.Count, 16)); ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable( indexedResult.GetEnumerator(), filterExpr, exprEvaluatorContext, deque); return deque; } // fall back to window operator if snapshot doesn't resolve successfully using (var enumerator = parent.GetEnumerator()) { var list = new ArrayDeque<EventBean>(); if (filterExpr != null) { ExprNodeUtilityEvaluate.ApplyFilterExpressionIterable(enumerator, filterExpr, AgentInstanceContext, list); } else { while (enumerator.MoveNext()) { list.Add(enumerator.Current); } } return list; } }
public static ReformatFormatForgeDesc ValidateGetFormatterType( EPType inputType, string methodName, ExprNode exprNode) { if (!(inputType is ClassEPType)) { throw new ExprValidationException( GetMessage(methodName) + " requires a datetime input value but received " + inputType); } if (!exprNode.Forge.ForgeConstantType.IsConstant) { throw new ExprValidationException(GetMessage(methodName) + " requires a constant-value format"); } var formatForge = exprNode.Forge; var formatType = formatForge.EvaluationType; if (formatType == null) { throw new ExprValidationException(GetMessage(methodName) + " invalid null format object"); } object format = null; if (formatForge.ForgeConstantType.IsCompileTimeConstant) { format = ExprNodeUtilityEvaluate.EvaluateValidationTimeNoStreams( exprNode.Forge.ExprEvaluator, null, "date format"); if (format == null) { throw new ExprValidationException(GetMessage(methodName) + " invalid null format object"); } } // handle legacy date var input = (ClassEPType) inputType; if (input.Clazz.GetBoxedType() == typeof(long?) || TypeHelper.IsSubclassOrImplementsInterface(input.Clazz, typeof(DateTime)) || TypeHelper.IsSubclassOrImplementsInterface(input.Clazz, typeof(DateTimeOffset)) || TypeHelper.IsSubclassOrImplementsInterface(input.Clazz, typeof(DateTimeEx))) { if (TypeHelper.IsSubclassOrImplementsInterface(formatType, typeof(DateFormat))) { return new ReformatFormatForgeDesc(typeof(DateFormat)); } if (TypeHelper.IsSubclassOrImplementsInterface(formatType, typeof(string))) { if (format != null) { try { new SimpleDateFormat((string) format); } catch (Exception ex) { throw new ExprValidationException( GetMessage(methodName) + " invalid format string (SimpleDateFormat): " + ex.Message, ex); } } return new ReformatFormatForgeDesc(typeof(string)); } throw GetFailedExpected(methodName, typeof(DateFormat), formatType); } if (TypeHelper.IsSubclassOrImplementsInterface(formatType, typeof(DateTimeFormat))) { return new ReformatFormatForgeDesc(typeof(DateTimeFormat)); } if (TypeHelper.IsSubclassOrImplementsInterface(formatType, typeof(string))) { if (format != null) { try { DateTimeFormat.For((string) format); } catch (Exception ex) { throw new ExprValidationException( GetMessage(methodName) + " invalid format string (DateTimeFormatter): " + ex.Message, ex); } } return new ReformatFormatForgeDesc(typeof(string)); } throw GetFailedExpected(methodName, typeof(DateTimeFormat), formatType); }