public RowLimitProcessor(VariableReader numRowsVariableReader, VariableReader offsetVariableReader, int currentRowLimit, int currentOffset) { _numRowsVariableReader = numRowsVariableReader; _offsetVariableReader = offsetVariableReader; _currentRowLimit = currentRowLimit; _currentOffset = currentOffset; }
public OutputConditionPolledCount( OutputConditionPolledCountState state, VariableReader optionalVariableReader) { this.state = state; this.optionalVariableReader = optionalVariableReader; }
public ExprDotEvalVariable(ExprDotNode dotNode, VariableReader variableReader, ExprDotStaticMethodWrap resultWrapLambda, ExprDotEval[] chainEval) { _dotNode = dotNode; _variableReader = variableReader; _resultWrapLambda = resultWrapLambda; _chainEval = chainEval; }
public MethodTargetStrategyVariable( MethodTargetStrategyVariableFactory factory, VariableReader reader) { this.factory = factory; this.reader = reader; }
public MethodPollingViewableMeta( Type methodProviderClass, bool isStaticMethod, IDictionary <string, Object> optionalMapType, IDictionary <string, Object> optionalOaType, Object invocationTarget, MethodPollingExecStrategyEnum strategy, bool isCollection, bool isIterator, VariableReader variableReader, string variableName, EventType eventTypeEventBeanArray, ExprNodeScript scriptExpression) { MethodProviderClass = methodProviderClass; IsStaticMethod = isStaticMethod; OptionalMapType = optionalMapType; OptionalOaType = optionalOaType; InvocationTarget = invocationTarget; Strategy = strategy; IsCollection = isCollection; IsEnumerator = isIterator; VariableReader = variableReader; VariableName = variableName; EventTypeEventBeanArray = eventTypeEventBeanArray; ScriptExpression = scriptExpression; }
public AggSvcGroupByReclaimAgedEvalFunc Make(AgentInstanceContext agentInstanceContext) { VariableReader reader = agentInstanceContext.VariableManagementService.GetReader( variable.DeploymentId, variable.MetaData.VariableName, agentInstanceContext.AgentInstanceId); return new AggSvcGroupByReclaimAgedEvalFuncVariable(reader); }
internal CreateVariableView( StatementAgentInstanceFactoryCreateVariable parent, AgentInstanceContext agentInstanceContext, VariableReader reader) { _parent = parent; _agentInstanceContext = agentInstanceContext; _reader = reader; }
public OutputConditionCount( OutputCallback outputCallback, long eventRate, VariableReader variableReader) : base(outputCallback) { this.eventRate = eventRate; this.variableReader = variableReader; }
public RowLimitProcessor( VariableReader numRowsVariableReader, VariableReader offsetVariableReader, int currentRowLimit, int currentOffset) { this.numRowsVariableReader = numRowsVariableReader; this.offsetVariableReader = offsetVariableReader; CurrentRowLimit = currentRowLimit; CurrentOffset = currentOffset; }
/// <summary>Constructor. </summary> /// <param name="eventRate">is the number of old or new events thatmust arrive in order for the condition to be satisfied </param> /// <param name="variableReader">is for reading the variable value, if a variable was supplied, else null</param> public OutputConditionPolledCount(int eventRate, VariableReader variableReader) { if ((eventRate < 1) && (variableReader == null)) { throw new ArgumentException("Limiting output by event count requires an event count of at least 1 or a variable name"); } _eventRate = eventRate; _variableReader = variableReader; _newEventsCount = eventRate; _oldEventsCount = eventRate; }
public OutputCondition Make(AgentInstanceContext agentInstanceContext, OutputCallback outputCallback) { VariableReader variableReader = null; if (VariableMetaData != null) { variableReader = agentInstanceContext.StatementContext.VariableService.GetReader( VariableMetaData.VariableName, agentInstanceContext.AgentInstanceId); } return(new OutputConditionCount(outputCallback, EventRate, variableReader)); }
public MethodPollingExecStrategyEventBeans( EventAdapterService eventAdapterService, FastMethod method, EventType eventType, Object invocationTarget, MethodPollingExecStrategyEnum strategy, VariableReader variableReader, string variableName, VariableService variableService) : base(eventAdapterService, method, eventType, invocationTarget, strategy, variableReader, variableName, variableService) { }
private IList <EventBean> InvokeInternalVariable(Object[] lookupValues, VariableReader variableReader) { var target = variableReader.Value; if (target == null) { return(null); } if (target is EventBean) { target = ((EventBean)target).Underlying; } return(InvokeInternal(lookupValues, target)); }
public OutputCondition InstantiateOutputCondition( AgentInstanceContext agentInstanceContext, OutputCallback outputCallback) { VariableReader variableReader = null; if (variable != null) { variableReader = agentInstanceContext.StatementContext.VariableManagementService.GetReader( variable.DeploymentId, variable.MetaData.VariableName, agentInstanceContext.AgentInstanceId); } return new OutputConditionCount(outputCallback, eventRate, variableReader); }
private AggSvcGroupByReclaimAgedEvalFuncFactory GetEvaluationFunction(VariableService variableService, String hintValue, String optionalContextName) { VariableMetaData variableMetaData = variableService.GetVariableMetaData(hintValue); if (variableMetaData != null) { if (!variableMetaData.VariableType.IsNumeric()) { throw new ExprValidationException("Variable type of variable '" + variableMetaData.VariableName + "' is not numeric"); } String message = VariableServiceUtil.CheckVariableContextName(optionalContextName, variableMetaData); if (message != null) { throw new ExprValidationException(message); } return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory { ProcMake = agentInstanceContext => { VariableReader reader = variableService.GetReader( variableMetaData.VariableName, agentInstanceContext.AgentInstanceId); return new AggSvcGroupByReclaimAgedEvalFuncVariable(reader); } }); } else { double valueDouble; try { valueDouble = DoubleValue.ParseString(hintValue); } catch (Exception) { throw new ExprValidationException("Failed to parse hint parameter value '" + hintValue + "' as a double-typed seconds value or variable name"); } if (valueDouble <= 0) { throw new ExprValidationException("Hint parameter value '" + hintValue + "' is an invalid value, expecting a double-typed seconds value or variable name"); } return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory { ProcMake = agentInstanceContext => new AggSvcGroupByReclaimAgedEvalFuncConstant(valueDouble) }); } }
protected MethodPollingExecStrategyBase( EventAdapterService eventAdapterService, FastMethod method, EventType eventType, Object invocationTarget, MethodPollingExecStrategyEnum strategy, VariableReader variableReader, String variableName, VariableService variableService) { EventAdapterService = eventAdapterService; Method = method; EventType = eventType; InvocationTarget = invocationTarget; Strategy = strategy; VariableReader = variableReader; VariableName = variableName; VariableService = variableService; }
public RowLimitProcessor Instantiate(AgentInstanceContext agentInstanceContext) { VariableReader numRowsVariableReader = null; if (_numRowsVariableMetaData != null) { numRowsVariableReader = agentInstanceContext.StatementContext.VariableService.GetReader(_numRowsVariableMetaData.VariableName, agentInstanceContext.AgentInstanceId); } VariableReader offsetVariableReader = null; if (_offsetVariableMetaData != null) { offsetVariableReader = agentInstanceContext.StatementContext.VariableService.GetReader(_offsetVariableMetaData.VariableName, agentInstanceContext.AgentInstanceId); } return(new RowLimitProcessor(numRowsVariableReader, offsetVariableReader, _currentRowLimit, _currentOffset)); }
private static MethodMetadataDesc GetCheckMetadataVariable( string methodName, VariableMetaData variableMetaData, VariableReader variableReader, EngineImportService engineImportService, Type metadataClass) { MethodInfo typeGetterMethod = GetRequiredTypeGetterMethodCanNonStatic( methodName, null, variableMetaData.VariableType, engineImportService, metadataClass); if (typeGetterMethod.IsStatic) { return(InvokeMetadataMethod(null, variableMetaData.GetType().Name, typeGetterMethod)); } // if the metadata is not a static method and we don't have an instance this is a problem const string messagePrefix = "Failed to access variable method invocation metadata: "; if (variableReader == null) { throw new ExprValidationException( messagePrefix + "The metadata method is an instance method however the variable is contextual, please declare the metadata method as static or remove the context declaration for the variable"); } object value = variableReader.Value; if (value == null) { throw new ExprValidationException( messagePrefix + "The variable value is null and the metadata method is an instance method"); } if (value is EventBean) { value = ((EventBean)value).Underlying; } return(InvokeMetadataMethod(value, variableMetaData.GetType().Name, typeGetterMethod)); }
public bool RemoveVariable(String name, bool force) { if (!force) { ICollection <String> statements = _statementVariableRef.GetStatementNamesForVar(name); if ((statements != null) && (statements.IsNotEmpty())) { throw new ConfigurationException("Variable '" + name + "' is in use by one or more statements"); } } VariableReader reader = _variableService.GetReader(name, VariableServiceConstants.NOCONTEXT_AGENTINSTANCEID); if (reader == null) { return(false); } _variableService.RemoveVariableIfFound(name); _statementVariableRef.RemoveReferencesVariable(name); _statementVariableRef.RemoveConfiguredVariable(name); return(true); }
public bool RemoveVariable(string name, bool force) { if (!force) { var statements = _statementVariableRef.GetStatementNamesForVar(name); if ((statements != null) && (!statements.IsEmpty())) { throw new ConfigurationException("Variable '" + name + "' is in use by one or more statements"); } } VariableReader reader = _variableService.GetReader(name, EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID); if (reader == null) { return(false); } _variableService.RemoveVariableIfFound(name); _statementVariableRef.RemoveReferencesVariable(name); _statementVariableRef.RemoveConfiguredVariable(name); return(true); }
public override ExprNode Validate(ExprValidationContext validationContext) { // determine if any types are property agnostic; If yes, resolve to variable var hasPropertyAgnosticType = false; var types = validationContext.StreamTypeService.EventTypes; for (var i = 0; i < validationContext.StreamTypeService.EventTypes.Length; i++) { if (types[i] is EventTypeSPI) { hasPropertyAgnosticType |= ((EventTypeSPI)types[i]).Metadata.IsPropertyAgnostic; } } if (!hasPropertyAgnosticType) { // the variable name should not overlap with a property name try { validationContext.StreamTypeService.ResolveByPropertyName(_variableName, false); throw new ExprValidationException("The variable by name '" + _variableName + "' is ambigous to a property of the same name"); } catch (DuplicatePropertyException e) { throw new ExprValidationException("The variable by name '" + _variableName + "' is ambigous to a property of the same name"); } catch (PropertyNotFoundException e) { // expected } } VariableMetaData variableMetadata = validationContext.VariableService.GetVariableMetaData(_variableName); if (variableMetadata == null) { throw new ExprValidationException("Failed to find variable by name '" + _variableName + "'"); } _isPrimitive = variableMetadata.EventType == null; _variableType = variableMetadata.VariableType; if (_optSubPropName != null) { if (variableMetadata.EventType == null) { throw new ExprValidationException("Property '" + _optSubPropName + "' is not valid for variable '" + _variableName + "'"); } _eventTypeGetter = variableMetadata.EventType.GetGetter(_optSubPropName); if (_eventTypeGetter == null) { throw new ExprValidationException("Property '" + _optSubPropName + "' is not valid for variable '" + _variableName + "'"); } _variableType = variableMetadata.EventType.GetPropertyType(_optSubPropName); } _readersPerCp = validationContext.VariableService.GetReadersPerCP(_variableName); if (variableMetadata.ContextPartitionName == null) { _readerNonCP = _readersPerCp.Get(EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID); } return(null); }
public override ExprNode Validate(ExprValidationContext validationContext) { // validate all parameters ExprNodeUtility.Validate(ExprNodeOrigin.DOTNODEPARAMETER, _chainSpec, validationContext); // determine if there are enumeration method expressions in the chain bool hasEnumerationMethod = false; foreach (ExprChainedSpec chain in _chainSpec) { if (chain.Name.IsEnumerationMethod()) { hasEnumerationMethod = true; break; } } // determine if there is an implied binding, replace first chain element with evaluation node if there is if (validationContext.StreamTypeService.HasTableTypes && validationContext.TableService != null && _chainSpec.Count > 1 && _chainSpec[0].IsProperty) { Pair <ExprNode, IList <ExprChainedSpec> > tableNode = validationContext.TableService.GetTableNodeChainable( validationContext.StreamTypeService, _chainSpec, validationContext.EngineImportService); if (tableNode != null) { ExprNode node = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.DOTNODE, tableNode.First, validationContext); if (tableNode.Second.IsEmpty()) { return(node); } _chainSpec.Clear(); _chainSpec.AddAll(tableNode.Second); AddChildNode(node); } } // The root node expression may provide the input value: // Such as "window(*).doIt(...)" or "(select * from Window).doIt()" or "prevwindow(sb).doIt(...)", in which case the expression to act on is a child expression // StreamTypeService streamTypeService = validationContext.StreamTypeService; if (ChildNodes.Length != 0) { // the root expression is the first child node ExprNode rootNode = ChildNodes[0]; ExprEvaluator rootNodeEvaluator = rootNode.ExprEvaluator; // the root expression may also provide a lambda-function input (GetEnumerator<EventBean>) // Determine collection-type and evaluator if any for root node ExprDotEnumerationSource enumSrc = ExprDotNodeUtility.GetEnumerationSource(rootNode, validationContext.StreamTypeService, validationContext.EventAdapterService, validationContext.StatementId, hasEnumerationMethod, validationContext.IsDisablePropertyExpressionEventCollCache); EPType typeInfo; if (enumSrc.ReturnType == null) { typeInfo = EPTypeHelper.SingleValue(rootNodeEvaluator.ReturnType); // not a collection type, treat as scalar } else { typeInfo = enumSrc.ReturnType; } ExprDotNodeRealizedChain evals = ExprDotNodeUtility.GetChainEvaluators(enumSrc.StreamOfProviderIfApplicable, typeInfo, _chainSpec, validationContext, _isDuckTyping, new ExprDotNodeFilterAnalyzerInputExpr()); _exprEvaluator = new ExprDotEvalRootChild(hasEnumerationMethod, this, rootNodeEvaluator, enumSrc.Enumeration, typeInfo, evals.Chain, evals.ChainWithUnpack, false); return(null); } // No root node, and this is a 1-element chain i.e. "something(param,...)". // Plug-in single-row methods are not handled here. // Plug-in aggregation methods are not handled here. if (_chainSpec.Count == 1) { ExprChainedSpec spec = _chainSpec[0]; if (spec.Parameters.IsEmpty()) { throw HandleNotFound(spec.Name); } // single-parameter can resolve to a property Pair <PropertyResolutionDescriptor, string> propertyInfoPair = null; try { propertyInfoPair = ExprIdentNodeUtil.GetTypeFromStream(streamTypeService, spec.Name, streamTypeService.HasPropertyAgnosticType, false); } catch (ExprValidationPropertyException) { // fine } // if not a property then try built-in single-row non-grammar functions if (propertyInfoPair == null && string.Equals(spec.Name, EngineImportServiceConstants.EXT_SINGLEROW_FUNCTION_TRANSPOSE, StringComparison.OrdinalIgnoreCase)) { if (spec.Parameters.Count != 1) { throw new ExprValidationException("The " + EngineImportServiceConstants.EXT_SINGLEROW_FUNCTION_TRANSPOSE + " function requires a single parameter expression"); } _exprEvaluator = new ExprDotEvalTransposeAsStream(_chainSpec[0].Parameters[0].ExprEvaluator); } else if (spec.Parameters.Count != 1) { throw HandleNotFound(spec.Name); } else { if (propertyInfoPair == null) { throw new ExprValidationException("Unknown single-row function, aggregation function or mapped or indexed property named '" + spec.Name + "' could not be resolved"); } _exprEvaluator = GetPropertyPairEvaluator(spec.Parameters[0].ExprEvaluator, propertyInfoPair, validationContext); _streamNumReferenced = propertyInfoPair.First.StreamNum; } return(null); } // handle the case where the first chain spec element is a stream name. ExprValidationException prefixedStreamNumException = null; int prefixedStreamNumber = PrefixedStreamName(_chainSpec, validationContext.StreamTypeService); if (prefixedStreamNumber != -1) { ExprChainedSpec specAfterStreamName = _chainSpec[1]; // Attempt to resolve as property Pair <PropertyResolutionDescriptor, string> propertyInfoPair = null; try { string propName = _chainSpec[0].Name + "." + specAfterStreamName.Name; propertyInfoPair = ExprIdentNodeUtil.GetTypeFromStream(streamTypeService, propName, streamTypeService.HasPropertyAgnosticType, false); } catch (ExprValidationPropertyException) { // fine } if (propertyInfoPair != null) { if (specAfterStreamName.Parameters.Count != 1) { throw HandleNotFound(specAfterStreamName.Name); } _exprEvaluator = GetPropertyPairEvaluator(specAfterStreamName.Parameters[0].ExprEvaluator, propertyInfoPair, validationContext); _streamNumReferenced = propertyInfoPair.First.StreamNum; return(null); } // Attempt to resolve as event-underlying object instance method EventType eventType = validationContext.StreamTypeService.EventTypes[prefixedStreamNumber]; Type type = eventType.UnderlyingType; IList <ExprChainedSpec> remainderChain = new List <ExprChainedSpec>(_chainSpec); remainderChain.RemoveAt(0); ExprValidationException methodEx = null; ExprDotEval[] underlyingMethodChain = null; try { EPType typeInfo = EPTypeHelper.SingleValue(type); underlyingMethodChain = ExprDotNodeUtility.GetChainEvaluators(prefixedStreamNumber, typeInfo, remainderChain, validationContext, false, new ExprDotNodeFilterAnalyzerInputStream(prefixedStreamNumber)).ChainWithUnpack; } catch (ExprValidationException ex) { methodEx = ex; // expected - may not be able to find the methods on the underlying } ExprDotEval[] eventTypeMethodChain = null; ExprValidationException enumDatetimeEx = null; try { EPType typeInfo = EPTypeHelper.SingleEvent(eventType); ExprDotNodeRealizedChain chain = ExprDotNodeUtility.GetChainEvaluators(prefixedStreamNumber, typeInfo, remainderChain, validationContext, false, new ExprDotNodeFilterAnalyzerInputStream(prefixedStreamNumber)); eventTypeMethodChain = chain.ChainWithUnpack; _exprDotNodeFilterAnalyzerDesc = chain.FilterAnalyzerDesc; } catch (ExprValidationException ex) { enumDatetimeEx = ex; // expected - may not be able to find the methods on the underlying } if (underlyingMethodChain != null) { _exprEvaluator = new ExprDotEvalStreamMethod(this, prefixedStreamNumber, underlyingMethodChain); _streamNumReferenced = prefixedStreamNumber; } else if (eventTypeMethodChain != null) { _exprEvaluator = new ExprDotEvalStreamEventBean(this, prefixedStreamNumber, eventTypeMethodChain); _streamNumReferenced = prefixedStreamNumber; } if (_exprEvaluator != null) { return(null); } else { if (ExprDotNodeUtility.IsDatetimeOrEnumMethod(remainderChain[0].Name)) { prefixedStreamNumException = enumDatetimeEx; } else { prefixedStreamNumException = new ExprValidationException("Failed to solve '" + remainderChain[0].Name + "' to either a date-time or enumeration method, an event property or a method on the event underlying object: " + methodEx.Message, methodEx); } } } // There no root node, in this case the classname or property name is provided as part of the chain. // Such as "MyClass.myStaticLib(...)" or "mycollectionproperty.doIt(...)" // IList <ExprChainedSpec> modifiedChain = new List <ExprChainedSpec>(_chainSpec); ExprChainedSpec firstItem = modifiedChain.Delete(0); Pair <PropertyResolutionDescriptor, string> propertyInfoPairX = null; try { propertyInfoPairX = ExprIdentNodeUtil.GetTypeFromStream(streamTypeService, firstItem.Name, streamTypeService.HasPropertyAgnosticType, true); } catch (ExprValidationPropertyException) { // not a property } // If property then treat it as such if (propertyInfoPairX != null) { string propertyName = propertyInfoPairX.First.PropertyName; int streamId = propertyInfoPairX.First.StreamNum; EventType streamType = streamTypeService.EventTypes[streamId]; EPType typeInfo; ExprEvaluatorEnumeration enumerationEval = null; EPType inputType; ExprEvaluator rootNodeEvaluator = null; EventPropertyGetter getter; if (firstItem.Parameters.IsEmpty()) { getter = streamType.GetGetter(propertyInfoPairX.First.PropertyName); ExprDotEnumerationSourceForProps propertyEval = ExprDotNodeUtility.GetPropertyEnumerationSource( propertyInfoPairX.First.PropertyName, streamId, streamType, hasEnumerationMethod, validationContext.IsDisablePropertyExpressionEventCollCache); typeInfo = propertyEval.ReturnType; enumerationEval = propertyEval.Enumeration; inputType = propertyEval.ReturnType; rootNodeEvaluator = new PropertyExprEvaluatorNonLambda(streamId, getter, propertyInfoPairX.First.PropertyType); } else { // property with parameter - mapped or indexed property EventPropertyDescriptor desc = EventTypeUtility.GetNestablePropertyDescriptor(streamTypeService.EventTypes[propertyInfoPairX.First.StreamNum], firstItem.Name); if (firstItem.Parameters.Count > 1) { throw new ExprValidationException("Property '" + firstItem.Name + "' may not be accessed passing 2 or more parameters"); } ExprEvaluator paramEval = firstItem.Parameters[0].ExprEvaluator; typeInfo = EPTypeHelper.SingleValue(desc.PropertyComponentType); inputType = typeInfo; getter = null; if (desc.IsMapped) { if (paramEval.ReturnType != typeof(string)) { throw new ExprValidationException("Parameter expression to mapped property '" + propertyName + "' is expected to return a string-type value but returns " + paramEval.ReturnType.GetTypeNameFullyQualPretty()); } EventPropertyGetterMapped mappedGetter = propertyInfoPairX.First.StreamEventType.GetGetterMapped(propertyInfoPairX.First.PropertyName); if (mappedGetter == null) { throw new ExprValidationException("Mapped property named '" + propertyName + "' failed to obtain getter-object"); } rootNodeEvaluator = new PropertyExprEvaluatorNonLambdaMapped(streamId, mappedGetter, paramEval, desc.PropertyComponentType); } if (desc.IsIndexed) { if (paramEval.ReturnType.GetBoxedType() != typeof(int?)) { throw new ExprValidationException("Parameter expression to mapped property '" + propertyName + "' is expected to return a Integer-type value but returns " + paramEval.ReturnType.GetTypeNameFullyQualPretty()); } EventPropertyGetterIndexed indexedGetter = propertyInfoPairX.First.StreamEventType.GetGetterIndexed(propertyInfoPairX.First.PropertyName); if (indexedGetter == null) { throw new ExprValidationException("Mapped property named '" + propertyName + "' failed to obtain getter-object"); } rootNodeEvaluator = new PropertyExprEvaluatorNonLambdaIndexed(streamId, indexedGetter, paramEval, desc.PropertyComponentType); } } if (typeInfo == null) { throw new ExprValidationException("Property '" + propertyName + "' is not a mapped or indexed property"); } // try to build chain based on the input (non-fragment) ExprDotNodeRealizedChain evals; ExprDotNodeFilterAnalyzerInputProp filterAnalyzerInputProp = new ExprDotNodeFilterAnalyzerInputProp(propertyInfoPairX.First.StreamNum, propertyInfoPairX.First.PropertyName); bool rootIsEventBean = false; try { evals = ExprDotNodeUtility.GetChainEvaluators(streamId, inputType, modifiedChain, validationContext, _isDuckTyping, filterAnalyzerInputProp); } catch (ExprValidationException ex) { // try building the chain based on the fragment event type (i.e. A.after(B) based on A-configured start time where A is a fragment) FragmentEventType fragment = propertyInfoPairX.First.FragmentEventType; if (fragment == null) { throw; } EPType fragmentTypeInfo; if (fragment.IsIndexed) { fragmentTypeInfo = EPTypeHelper.CollectionOfEvents(fragment.FragmentType); } else { fragmentTypeInfo = EPTypeHelper.SingleEvent(fragment.FragmentType); } rootIsEventBean = true; evals = ExprDotNodeUtility.GetChainEvaluators(propertyInfoPairX.First.StreamNum, fragmentTypeInfo, modifiedChain, validationContext, _isDuckTyping, filterAnalyzerInputProp); rootNodeEvaluator = new PropertyExprEvaluatorNonLambdaFragment(streamId, getter, fragment.FragmentType.UnderlyingType); } _exprEvaluator = new ExprDotEvalRootChild(hasEnumerationMethod, this, rootNodeEvaluator, enumerationEval, inputType, evals.Chain, evals.ChainWithUnpack, !rootIsEventBean); _exprDotNodeFilterAnalyzerDesc = evals.FilterAnalyzerDesc; _streamNumReferenced = propertyInfoPairX.First.StreamNum; _rootPropertyName = propertyInfoPairX.First.PropertyName; return(null); } // If variable then resolve as such string contextNameVariable = validationContext.VariableService.IsContextVariable(firstItem.Name); if (contextNameVariable != null) { throw new ExprValidationException("Method invocation on context-specific variable is not supported"); } VariableReader variableReader = validationContext.VariableService.GetReader(firstItem.Name, EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID); if (variableReader != null) { EPType typeInfo; ExprDotStaticMethodWrap wrap; if (variableReader.VariableMetaData.VariableType.IsArray) { typeInfo = EPTypeHelper.CollectionOfSingleValue(variableReader.VariableMetaData.VariableType.GetElementType()); wrap = new ExprDotStaticMethodWrapArrayScalar(variableReader.VariableMetaData.VariableName, variableReader.VariableMetaData.VariableType.GetElementType()); } else if (variableReader.VariableMetaData.EventType != null) { typeInfo = EPTypeHelper.SingleEvent(variableReader.VariableMetaData.EventType); wrap = null; } else { typeInfo = EPTypeHelper.SingleValue(variableReader.VariableMetaData.VariableType); wrap = null; } ExprDotNodeRealizedChain evals = ExprDotNodeUtility.GetChainEvaluators(null, typeInfo, modifiedChain, validationContext, false, new ExprDotNodeFilterAnalyzerInputStatic()); _exprEvaluator = new ExprDotEvalVariable(this, variableReader, wrap, evals.ChainWithUnpack); return(null); } // try resolve as enumeration class with value object enumconstant = TypeHelper.ResolveIdentAsEnumConst(firstItem.Name, validationContext.EngineImportService, false); if (enumconstant != null) { // try resolve method ExprChainedSpec methodSpec = modifiedChain[0]; string enumvalue = firstItem.Name; ExprNodeUtilResolveExceptionHandler handler = new ProxyExprNodeUtilResolveExceptionHandler { ProcHandle = ex => new ExprValidationException("Failed to resolve method '" + methodSpec.Name + "' on enumeration value '" + enumvalue + "': " + ex.Message), }; EventType wildcardType = validationContext.StreamTypeService.EventTypes.Length != 1 ? null : validationContext.StreamTypeService.EventTypes[0]; ExprNodeUtilMethodDesc methodDesc = ExprNodeUtility.ResolveMethodAllowWildcardAndStream( enumconstant.GetType().Name, enumconstant.GetType(), methodSpec.Name, methodSpec.Parameters, validationContext.EngineImportService, validationContext.EventAdapterService, validationContext.StatementId, wildcardType != null, wildcardType, handler, methodSpec.Name, validationContext.TableService); // method resolved, hook up modifiedChain.RemoveAt(0); // we identified this piece ExprDotStaticMethodWrap optionalLambdaWrap = ExprDotStaticMethodWrapFactory.Make(methodDesc.ReflectionMethod, validationContext.EventAdapterService, modifiedChain); EPType typeInfo = optionalLambdaWrap != null ? optionalLambdaWrap.TypeInfo : EPTypeHelper.SingleValue(methodDesc.FastMethod.ReturnType); ExprDotNodeRealizedChain evals = ExprDotNodeUtility.GetChainEvaluators(null, typeInfo, modifiedChain, validationContext, false, new ExprDotNodeFilterAnalyzerInputStatic()); _exprEvaluator = new ExprDotEvalStaticMethod(validationContext.StatementName, firstItem.Name, methodDesc.FastMethod, methodDesc.ChildEvals, false, optionalLambdaWrap, evals.ChainWithUnpack, false, enumconstant); return(null); } // if prefixed by a stream name, we are giving up if (prefixedStreamNumException != null) { throw prefixedStreamNumException; } // If class then resolve as class ExprChainedSpec secondItem = modifiedChain.Delete(0); bool allowWildcard = validationContext.StreamTypeService.EventTypes.Length == 1; EventType streamZeroType = null; if (validationContext.StreamTypeService.EventTypes.Length > 0) { streamZeroType = validationContext.StreamTypeService.EventTypes[0]; } ExprNodeUtilMethodDesc method = ExprNodeUtility.ResolveMethodAllowWildcardAndStream( firstItem.Name, null, secondItem.Name, secondItem.Parameters, validationContext.EngineImportService, validationContext.EventAdapterService, validationContext.StatementId, allowWildcard, streamZeroType, new ExprNodeUtilResolveExceptionHandlerDefault(firstItem.Name + "." + secondItem.Name, false), secondItem.Name, validationContext.TableService); bool isConstantParameters = method.IsAllConstants && _isUDFCache; _isReturnsConstantResult = isConstantParameters && modifiedChain.IsEmpty(); // this may return a pair of null if there is no lambda or the result cannot be wrapped for lambda-function use ExprDotStaticMethodWrap optionalLambdaWrapX = ExprDotStaticMethodWrapFactory.Make(method.ReflectionMethod, validationContext.EventAdapterService, modifiedChain); EPType typeInfoX = optionalLambdaWrapX != null ? optionalLambdaWrapX.TypeInfo : EPTypeHelper.SingleValue(method.ReflectionMethod.ReturnType); ExprDotNodeRealizedChain evalsX = ExprDotNodeUtility.GetChainEvaluators(null, typeInfoX, modifiedChain, validationContext, false, new ExprDotNodeFilterAnalyzerInputStatic()); _exprEvaluator = new ExprDotEvalStaticMethod(validationContext.StatementName, firstItem.Name, method.FastMethod, method.ChildEvals, isConstantParameters, optionalLambdaWrapX, evalsX.ChainWithUnpack, false, null); return(null); }
/// <summary> /// Creates an output condition instance. /// </summary> /// <param name="outputLimitSpec">specifies what kind of condition to create</param> /// <param name="agentInstanceContext">The agent instance context.</param> /// <returns>instance for handling output condition</returns> public static OutputConditionPolled CreateCondition( OutputLimitSpec outputLimitSpec, AgentInstanceContext agentInstanceContext) { if (outputLimitSpec == null) { throw new ArgumentNullException("outputLimitSpec", "Output condition by count requires a non-null callback"); } // Check if a variable is present VariableReader reader = null; if (outputLimitSpec.VariableName != null) { reader = agentInstanceContext.StatementContext.VariableService.GetReader( outputLimitSpec.VariableName, agentInstanceContext.AgentInstanceId); if (reader == null) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' has not been declared"); } } if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB) { return(new OutputConditionPolledCrontab(outputLimitSpec.CrontabAtSchedule, agentInstanceContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION) { return(new OutputConditionPolledExpression( outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, agentInstanceContext)); } else if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS) { if (Log.IsDebugEnabled) { Log.Debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec); } if ((reader != null) && (!TypeHelper.IsNumericNonFP(reader.VariableMetaData.VariableType))) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be type integer, long or short"); } int rate = -1; if (outputLimitSpec.Rate != null) { rate = outputLimitSpec.Rate.AsInt(); } return(new OutputConditionPolledCount(rate, reader)); } else { if ((reader != null) && (!TypeHelper.IsNumeric(reader.VariableMetaData.VariableType))) { throw new ArgumentException( "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type"); } return(new OutputConditionPolledTime(outputLimitSpec.TimePeriodExpr, agentInstanceContext)); } }
public OutputConditionPolledCount(OutputConditionPolledCountFactory factory, OutputConditionPolledCountState state, VariableReader optionalVariableReader) { _factory = factory; _state = state; _optionalVariableReader = optionalVariableReader; }
public MethodPollingExecStrategyOAIterator(EventAdapterService eventAdapterService, MethodInfo method, EventType eventType, object invocationTarget, MethodPollingExecStrategyEnum strategy, VariableReader variableReader, string variableName, VariableService variableService) : base(eventAdapterService, method, eventType, invocationTarget, strategy, variableReader, variableName, variableService) { }
public AggSvcGroupByReclaimAgedEvalFuncVariable(VariableReader variableReader) { _variableReader = variableReader; }
/// <summary> /// Return parsed formula nodes without RPN /// </summary> public List <BaseFormulaNode> ParseWithoutRpn(ReadOnlySpan <char> formula) { var negativeBracketCounters = new BracketCounters(); var nodes = new List <BaseFormulaNode>(); for (int i = 0; i < formula.Length; i++) { var ch = formula[i]; if (ch.IsWhiteSpace()) { continue; } if (FunctionCharReader.TryProceedFunctionChar(nodes, ch)) { continue; } if (BracketReader.TryProceedOpenBracket(nodes, formula, negativeBracketCounters, ref i)) { continue; } if (BracketReader.TryProceedCloseBracket(nodes, formula, negativeBracketCounters, ref i)) { continue; } if (VariableReader.TryProceedBorderedVariable(nodes, formula, ref i)) { continue; } if (NumberReader.TryProceedNumber(nodes, formula, ref i)) { continue; } if (FunctionsReader.TryProceedFunction(nodes, formula, ref i)) { continue; } if (VariableReader.TryProceedSimpleVariable(nodes, formula, ref i)) { continue; } if (WordReader.TryProceedWord(nodes, formula, ref i)) { continue; } if (ListReader.TryProceedList(nodes, formula, ref i)) { continue; } if (OperatorReader.TryProceedOperator(nodes, formula, ref i)) { continue; } } return(nodes); }
/// <summary> /// Creates a method-invocation polling view for use as a stream that calls a method, or pulls results from cache. /// </summary> /// <param name="streamNumber">the stream number</param> /// <param name="methodStreamSpec">defines the class and method to call</param> /// <param name="eventAdapterService">for creating event types and events</param> /// <param name="epStatementAgentInstanceHandle">for time-based callbacks</param> /// <param name="engineImportService">for resolving configurations</param> /// <param name="schedulingService">for scheduling callbacks in expiry-time based caches</param> /// <param name="scheduleBucket">for schedules within the statement</param> /// <param name="exprEvaluatorContext">expression evaluation context</param> /// <param name="variableService">variable service</param> /// <param name="statementContext">statement context</param> /// <param name="contextName">context name</param> /// <param name="dataCacheFactory">factory for cache</param> /// <exception cref="ExprValidationException"> /// if the expressions cannot be validated or the method descriptor /// has incorrect class and method names, or parameter number and types don't match /// </exception> /// <returns>pollable view</returns> public static HistoricalEventViewable CreatePollMethodView( int streamNumber, MethodStreamSpec methodStreamSpec, EventAdapterService eventAdapterService, EPStatementAgentInstanceHandle epStatementAgentInstanceHandle, EngineImportService engineImportService, SchedulingService schedulingService, ScheduleBucket scheduleBucket, ExprEvaluatorContext exprEvaluatorContext, VariableService variableService, string contextName, DataCacheFactory dataCacheFactory, StatementContext statementContext) { VariableMetaData variableMetaData = variableService.GetVariableMetaData(methodStreamSpec.ClassName); MethodPollingExecStrategyEnum strategy; VariableReader variableReader = null; string variableName = null; MethodInfo methodReflection = null; object invocationTarget = null; string eventTypeNameProvidedUDFOrScript = null; // see if this is a script in the from-clause ExprNodeScript scriptExpression = null; if (methodStreamSpec.ClassName == null && methodStreamSpec.MethodName != null) { var scriptsByName = statementContext.ExprDeclaredService.GetScriptsByName(methodStreamSpec.MethodName); if (scriptsByName != null) { scriptExpression = ExprDeclaredHelper.GetExistsScript( statementContext.ConfigSnapshot.EngineDefaults.Scripts.DefaultDialect, methodStreamSpec.MethodName, methodStreamSpec.Expressions, scriptsByName, statementContext.ExprDeclaredService); } } try { if (scriptExpression != null) { eventTypeNameProvidedUDFOrScript = scriptExpression.EventTypeNameAnnotation; strategy = MethodPollingExecStrategyEnum.TARGET_SCRIPT; ExprNodeUtility.ValidateSimpleGetSubtree( ExprNodeOrigin.METHODINVJOIN, scriptExpression, statementContext, null, false); } else if (variableMetaData != null) { variableName = variableMetaData.VariableName; if (variableMetaData.ContextPartitionName != null) { if (contextName == null || !contextName.Equals(variableMetaData.ContextPartitionName)) { throw new ExprValidationException( "Variable by name '" + variableMetaData.VariableName + "' has been declared for context '" + variableMetaData.ContextPartitionName + "' and can only be used within the same context"); } strategy = MethodPollingExecStrategyEnum.TARGET_VAR_CONTEXT; variableReader = null; invocationTarget = null; } else { variableReader = variableService.GetReader( methodStreamSpec.ClassName, EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID); if (variableMetaData.IsConstant) { invocationTarget = variableReader.Value; if (invocationTarget is EventBean) { invocationTarget = ((EventBean)invocationTarget).Underlying; } strategy = MethodPollingExecStrategyEnum.TARGET_CONST; } else { invocationTarget = null; strategy = MethodPollingExecStrategyEnum.TARGET_VAR; } } methodReflection = engineImportService.ResolveNonStaticMethodOverloadChecked( variableMetaData.VariableType, methodStreamSpec.MethodName); } else if (methodStreamSpec.ClassName == null) { // must be either UDF or script Pair <Type, EngineImportSingleRowDesc> udf = null; try { udf = engineImportService.ResolveSingleRow(methodStreamSpec.MethodName); } catch (EngineImportException ex) { throw new ExprValidationException( "Failed to find user-defined function '" + methodStreamSpec.MethodName + "': " + ex.Message, ex); } methodReflection = engineImportService.ResolveMethodOverloadChecked(udf.First, methodStreamSpec.MethodName); invocationTarget = null; variableReader = null; variableName = null; strategy = MethodPollingExecStrategyEnum.TARGET_CONST; eventTypeNameProvidedUDFOrScript = udf.Second.OptionalEventTypeName; } else { methodReflection = engineImportService.ResolveMethodOverloadChecked(methodStreamSpec.ClassName, methodStreamSpec.MethodName); invocationTarget = null; variableReader = null; variableName = null; strategy = MethodPollingExecStrategyEnum.TARGET_CONST; } } catch (ExprValidationException) { throw; } catch (Exception e) { throw new ExprValidationException(e.Message, e); } Type methodProviderClass = null; Type beanClass; IDictionary <string, object> oaType = null; IDictionary <string, object> mapType = null; bool isCollection = false; bool isIterator = false; EventType eventType; EventType eventTypeWhenMethodReturnsEventBeans = null; bool isStaticMethod = false; if (methodReflection != null) { methodProviderClass = methodReflection.DeclaringType; isStaticMethod = variableMetaData == null; // Determine object type returned by method beanClass = methodReflection.ReturnType; if ((beanClass == typeof(void)) || (beanClass.IsBuiltinDataType())) { throw new ExprValidationException( "Invalid return type for static method '" + methodReflection.Name + "' of class '" + methodStreamSpec.ClassName + "', expecting a class"); } if (methodReflection.ReturnType.IsArray && methodReflection.ReturnType.GetElementType() != typeof(EventBean)) { beanClass = methodReflection.ReturnType.GetElementType(); } Type collectionClass = null; Type iteratorClass = null; if (!beanClass.IsGenericDictionary()) { isCollection = beanClass.IsGenericCollection(); if (isCollection) { collectionClass = TypeHelper.GetGenericReturnType(methodReflection, true); beanClass = collectionClass; } isIterator = beanClass.IsGenericEnumerator() && !beanClass.IsGenericDictionary(); if (isIterator) { iteratorClass = TypeHelper.GetGenericReturnType(methodReflection, true); beanClass = iteratorClass; } } // If the method returns a Map, look up the map type string mapTypeName = null; if ((methodReflection.ReturnType.IsGenericStringDictionary()) || (methodReflection.ReturnType.IsArray && methodReflection.ReturnType.GetElementType().IsGenericStringDictionary()) || (isCollection && collectionClass.IsImplementsInterface(typeof(Map))) || (isIterator && iteratorClass.IsImplementsInterface(typeof(Map)))) { MethodMetadataDesc metadata; if (variableMetaData != null) { metadata = GetCheckMetadataVariable( methodStreamSpec.MethodName, variableMetaData, variableReader, engineImportService, typeof(Map)); } else { metadata = GetCheckMetadataNonVariable( methodStreamSpec.MethodName, methodStreamSpec.ClassName, engineImportService, typeof(Map)); } mapTypeName = metadata.TypeName; mapType = (IDictionary <string, object>)metadata.TypeMetadata; } // If the method returns an object[] or object[][], look up the type information string oaTypeName = null; if (methodReflection.ReturnType == typeof(object[]) || methodReflection.ReturnType == typeof(object[][]) || (isCollection && collectionClass == typeof(object[])) || (isIterator && iteratorClass == typeof(object[]))) { MethodMetadataDesc metadata; if (variableMetaData != null) { metadata = GetCheckMetadataVariable( methodStreamSpec.MethodName, variableMetaData, variableReader, engineImportService, typeof(IDictionary <string, object>)); } else { metadata = GetCheckMetadataNonVariable( methodStreamSpec.MethodName, methodStreamSpec.ClassName, engineImportService, typeof(IDictionary <string, object>)); } oaTypeName = metadata.TypeName; oaType = (IDictionary <string, object>)metadata.TypeMetadata; } // Determine event type from class and method name // If the method returns EventBean[], require the event type if ((methodReflection.ReturnType.IsArray && methodReflection.ReturnType.GetElementType() == typeof(EventBean)) || (isCollection && collectionClass == typeof(EventBean)) || (isIterator && iteratorClass == typeof(EventBean))) { string typeName = methodStreamSpec.EventTypeName == null ? eventTypeNameProvidedUDFOrScript : methodStreamSpec.EventTypeName; eventType = EventTypeUtility.RequireEventType( "Method", methodReflection.Name, eventAdapterService, typeName); eventTypeWhenMethodReturnsEventBeans = eventType; } else if (mapType != null) { eventType = eventAdapterService.AddNestableMapType( mapTypeName, mapType, null, false, true, true, false, false); } else if (oaType != null) { eventType = eventAdapterService.AddNestableObjectArrayType( oaTypeName, oaType, null, false, true, true, false, false, false, null); } else { eventType = eventAdapterService.AddBeanType(beanClass.GetDefaultTypeName(), beanClass, false, true, true); } // the @type is only allowed in conjunction with EventBean return types if (methodStreamSpec.EventTypeName != null && eventTypeWhenMethodReturnsEventBeans == null) { throw new ExprValidationException(EventTypeUtility.DisallowedAtTypeMessage()); } } else { string eventTypeName = methodStreamSpec.EventTypeName == null ? scriptExpression.EventTypeNameAnnotation : methodStreamSpec.EventTypeName; eventType = EventTypeUtility.RequireEventType( "Script", scriptExpression.Script.Name, eventAdapterService, eventTypeName); } // get configuration for cache string configName = methodProviderClass != null ? methodProviderClass.FullName : methodStreamSpec.MethodName; ConfigurationMethodRef configCache = engineImportService.GetConfigurationMethodRef(configName); if (configCache == null) { configCache = engineImportService.GetConfigurationMethodRef(configName); } ConfigurationDataCache dataCacheDesc = (configCache != null) ? configCache.DataCacheDesc : null; DataCache dataCache = dataCacheFactory.GetDataCache( dataCacheDesc, statementContext, epStatementAgentInstanceHandle, schedulingService, scheduleBucket, streamNumber); // metadata var meta = new MethodPollingViewableMeta( methodProviderClass, isStaticMethod, mapType, oaType, invocationTarget, strategy, isCollection, isIterator, variableReader, variableName, eventTypeWhenMethodReturnsEventBeans, scriptExpression); return(new MethodPollingViewable(methodStreamSpec, dataCache, eventType, exprEvaluatorContext, meta, statementContext.ThreadLocalManager)); }