public FileSourceCSV( FileSourceFactory factory, DataFlowOpInitializeContext context, AdapterInputSource adapterInputSource, bool hasHeaderLine, bool hasTitleLine, int?numLoops, string[] propertyNames, string dateFormat) { _factory = factory; _adapterInputSource = adapterInputSource; _hasHeaderLine = hasHeaderLine; _hasTitleLine = hasTitleLine; _numLoops = numLoops; _dateFormat = dateFormat; _statementContext = context.AgentInstanceContext.StatementContext; // use event type's full list of properties if (!hasTitleLine) { if (propertyNames != null) { _parseMake = SetupProperties(false, propertyNames, factory.OutputEventType, _statementContext, dateFormat); } else { _parseMake = SetupProperties(false, factory.OutputEventType.PropertyNames, factory.OutputEventType, _statementContext, dateFormat); } } }
private static T TryParameterProvider<T>( string name, DataFlowOpInitializeContext context) { if (context.AdditionalParameters != null && context.AdditionalParameters.ContainsKey(name)) { return (T) context.AdditionalParameters.Get(name); } if (context.ParameterProvider == null) { return default(T); } EPDataFlowOperatorParameterProviderContext ctx = new EPDataFlowOperatorParameterProviderContext(context, name); object value = context.ParameterProvider.Provide(ctx); if (value == null) { return default(T); } var clazz = typeof(T); if (TypeHelper.IsAssignmentCompatible(value.GetType(), clazz)) { return (T) value; } throw new EPException( "Parameter provider provided an unexpected object for parameter '" + name + "' of type '" + value.GetType().Name + "', expected type '" + clazz.Name + "'"); }
/// <summary> /// Resolve an instance from a class-name map. /// </summary> /// <param name="name">parameter name</param> /// <param name="configuration">map with key 'class' for the class name</param> /// <param name="context">initialization context</param> /// <returns>instance</returns> public static T ResolveOptionalInstance<T>( string name, IDictionary<string, object> configuration, DataFlowOpInitializeContext context) where T : class { T resolvedFromProvider = TryParameterProvider<T>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } if (configuration == null) { return null; } string className = (string) configuration.Get("class"); if (className == null) { throw new EPException("Failed to find 'class' parameter for parameter '" + name + "'"); } Type theClass; try { theClass = context.AgentInstanceContext.ImportServiceRuntime.ResolveClass(className, false, ExtensionClassEmpty.INSTANCE); } catch (ImportException e) { throw new EPException("Failed to find class for parameter '" + name + "': " + e.Message, e); } try { return TypeHelper.Instantiate<T>(theClass); } catch (ClassInstantiationException ex) { throw new EPException("Failed to instantiate class for parameter '" + name + "': " + ex.Message, ex); } }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var titleText = DataFlowParameterResolution.ResolveStringOptional("title", Title, context); var layoutText = DataFlowParameterResolution.ResolveStringOptional("layout", Layout, context); var logFlag = DataFlowParameterResolution.ResolveWithDefault<bool>("log", Log, true, context); var linefeedFlag = DataFlowParameterResolution.ResolveWithDefault<bool>("linefeed", Linefeed, true, context); ConsoleOpRenderer renderer; var formatText = DataFlowParameterResolution.ResolveStringOptional("format", Format, context); if (formatText == null) { renderer = new ConsoleOpRendererSummary(); } else { LogSinkOutputFormat formatEnum = EnumHelper.Parse<LogSinkOutputFormat>(formatText); if (formatEnum == LogSinkOutputFormat.summary) { renderer = new ConsoleOpRendererSummary(); } else if (formatEnum == LogSinkOutputFormat.json || formatEnum == LogSinkOutputFormat.xml) { renderer = new ConsoleOpRendererXmlJSon(formatEnum, context.AgentInstanceContext.EPRuntimeRenderEvent); } else { throw new EPException( "Format '" + formatText + "' is not supported, expecting any of " + CompatExtensions.RenderAny( EnumHelper.GetValues<LogSinkOutputFormat>())); } } return new LogSinkOp(this, context.DataFlowInstanceId, renderer, titleText, layoutText, logFlag, linefeedFlag); }
private FileBeginEndProcessor GetBeginEndProcessor(DataFlowOpInitializeContext context, int outputPort) { var portEventType = _factory.OutputPortTypes[outputPort]; var writeables = EventTypeUtility.GetWriteableProperties(portEventType, false); var writeableList = new List <WriteablePropertyDescriptor>(); EventBeanManufacturer manufacturer; if (_propertyNameFile != null) { var writeableFile = EventTypeUtility.FindWritable(_propertyNameFile, writeables); if (writeableFile == null || writeableFile.PropertyType != typeof(string)) { throw new EPException("Failed to find writable String-type property '" + _propertyNameFile + "', is the property read-only?"); } writeableList.Add(writeableFile); } try { manufacturer = EventTypeUtility.GetManufacturer( portEventType, writeableList.ToArray(), context.AgentInstanceContext.ImportServiceRuntime, false, context.AgentInstanceContext.EventTypeAvroHandler) .GetManufacturer(context.AgentInstanceContext.EventBeanTypedEventFactory); } catch (EventBeanManufactureException e) { throw new EPException("Event type '" + portEventType.Name + "' cannot be written to: " + e.Message, e); } return(new FileBeginEndProcessorGeneralPurpose(manufacturer)); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var propOneText = DataFlowParameterResolution.ResolveStringOptional("propOne", propOne, context); var propTwoText = DataFlowParameterResolution.ResolveStringOptional("propTwo", propTwo, context); var propThreeText = DataFlowParameterResolution.ResolveStringOptional("propThree", propThree, context); return new MyOp(this, propOneText, propTwoText, propThreeText); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var fileName = DataFlowParameterResolution.ResolveStringRequired( "file", File, context); var appendFlag = DataFlowParameterResolution.ResolveWithDefault( "append", Append, false, context); return new FileSinkCSV(this, fileName, appendFlag); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var iterationsCount = DataFlowParameterResolution.ResolveNumber("iterations", Iterations, 0, context).AsInt64(); var initialDelaySec = DataFlowParameterResolution.ResolveNumber("initialDelay", InitialDelay, 0, context).AsDouble(); var initialDelayMSec = (long) (initialDelaySec * 1000); var intervalSec = DataFlowParameterResolution.ResolveNumber("interval", Interval, 0, context).AsDouble(); var intervalMSec = (long) (intervalSec * 1000); return new BeaconSourceOp(this, iterationsCount, initialDelayMSec, intervalMSec, context.AdditionalParameters); }
/// <summary> /// Ctor. /// </summary> /// <param name="initializeContext">context</param> /// <param name="parameterName">parameter name</param> public EPDataFlowOperatorParameterProviderContext( DataFlowOpInitializeContext initializeContext, string parameterName) { OperatorName = initializeContext.OperatorName; ParameterName = parameterName; factory = initializeContext.DataFlowOperatorFactory; OperatorNum = initializeContext.OperatorNumber; DataFlowName = initializeContext.DataFlowName; }
/// <summary> /// Resolve a string value by first looking at the parameter value provider and by using the evaluator if one was provided /// or returning null if no value was found. /// </summary> /// <param name="name">parameter name</param> /// <param name="optionalEvaluator">evaluator</param> /// <param name="context">initialization context</param> /// <returns>value</returns> /// <throws>EPException if no value was found</throws> public static string ResolveStringOptional( string name, ExprEvaluator optionalEvaluator, DataFlowOpInitializeContext context) { string resolvedFromProvider = TryParameterProvider<string>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } return (string) optionalEvaluator?.Evaluate(null, true, context.AgentInstanceContext); }
/// <summary> /// Resolve a string value by first looking at the parameter value provider and by using the evaluator if one was provided, /// throwing an exception if no value was provided. /// </summary> /// <param name="name">parameter name</param> /// <param name="optionalEvaluator">evaluator</param> /// <param name="context">initialization context</param> /// <returns>value</returns> /// <throws>EPException if no value was found</throws> public static string ResolveStringRequired( string name, ExprEvaluator optionalEvaluator, DataFlowOpInitializeContext context) { string resolvedFromProvider = TryParameterProvider<string>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } if (optionalEvaluator == null) { throw new EPException("Parameter by name '" + name + "' has no value"); } string value = (string) optionalEvaluator.Evaluate(null, true, context.AgentInstanceContext); if (value == null) { throw new EPException("Parameter by name '" + name + "' has a null value"); } return value; }
/// <summary> /// Resolve all entries in the map by first looking at the parameter value provider and by using the evaluator if one was provided /// or returning the provided value if no evaluator was found. /// </summary> /// <param name="name">parameter name</param> /// <param name="evals">map of properties with either evaluator or constant type</param> /// <param name="context">initialization context</param> /// <returns>value</returns> public static IDictionary<string, object> ResolveMap( string name, IDictionary<string, object> evals, DataFlowOpInitializeContext context) { if (evals == null) { return null; } if (evals.IsEmpty()) { return Collections.GetEmptyMap<string, object>(); } var map = new LinkedHashMap<string, object>(); foreach (KeyValuePair<string, object> entry in evals) { if (entry.Value is ExprEvaluator) { try { map.Put(name, ((ExprEvaluator) entry.Value).Evaluate(null, true, context.AgentInstanceContext)); } catch (EPException) { throw; } catch (Exception ex) { throw new EPException( "Failed to evaluate value for parameter '" + name + "' for entry key '" + entry.Key + "': " + ex.Message, ex); } } else { map.Put(name, entry.Value); } } return map; }
/// <summary> /// Resolve a number value by first looking at the parameter value provider and by using the evaluator if one was provided, /// returning the default value if no value was found and no evaluator was provided. /// </summary> /// <param name="name">parameter name</param> /// <param name="optionalEvaluator">evaluator</param> /// <param name="defaultValue">default</param> /// <param name="context">initialization context</param> /// <returns>value</returns> public static object ResolveNumber( string name, ExprEvaluator optionalEvaluator, object defaultValue, DataFlowOpInitializeContext context) { object resolvedFromProvider = TryParameterProvider<object>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } if (optionalEvaluator == null) { return defaultValue; } object value = (object) optionalEvaluator.Evaluate(null, true, context.AgentInstanceContext); if (value == null) { throw new EPException("Parameter '" + name + "' is null and is expected to have a value"); } return value; }
/// <summary> /// Resolve a typed value by first looking at the parameter value provider and by using the evaluator if one was provided /// or returning the provided default value if no value was found. /// </summary> /// <param name="name">parameter name</param> /// <param name="optionalEvaluator">evaluator</param> /// <param name="context">initialization context</param> /// <param name="defaultValue">default value</param> /// <returns>value</returns> public static T ResolveWithDefault<T>( string name, ExprEvaluator optionalEvaluator, T defaultValue, DataFlowOpInitializeContext context) { T resolvedFromProvider = TryParameterProvider<T>(name, context); if (resolvedFromProvider != null) { return resolvedFromProvider; } if (optionalEvaluator == null) { return defaultValue; } T result = (T) optionalEvaluator.Evaluate(null, true, context.AgentInstanceContext); if (result == null) { return defaultValue; } var clazz = typeof(T); if (clazz.GetBoxedType() == result.GetType().GetBoxedType()) { return result; } if (TypeHelper.IsSubclassOrImplementsInterface(result.GetType(), clazz)) { return result; } //if (TypeHelper.IsSubclassOrImplementsInterface(result.GetType().GetBoxedType(), typeof(object))) { if (result.GetType().GetBoxedType().IsNumeric()) { return (T) SimpleNumberCoercerFactory.GetCoercer(result.GetType(), clazz.GetBoxedType()) .CoerceBoxed(result); } return (T) result; }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MyFactorialOp(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var container = context.Container; var adapterInputSourceValue = DataFlowParameterResolution.ResolveOptionalInstance <AdapterInputSource>( "adapterInputSource", AdapterInputSource, context); var fileName = DataFlowParameterResolution.ResolveWithDefault <string>( "file", File, null, context); if (adapterInputSourceValue == null) { if (fileName != null) { adapterInputSourceValue = new AdapterInputSource(container, new FileInfo(fileName)); } else { throw new EPException("Failed to find required parameter, either the file or the adapterInputSource parameter is required"); } } var formatValue = DataFlowParameterResolution.ResolveStringOptional("format", Format, context); switch (formatValue) { case null: case "csv": { var hasHeaderLineFlag = DataFlowParameterResolution.ResolveWithDefault <bool?>( "hasHeaderLine", HasHeaderLine, false, context); var hasTitleLineFlag = DataFlowParameterResolution.ResolveWithDefault <bool?>( "hasTitleLine", HasTitleLine, false, context); var numLoopsValue = DataFlowParameterResolution.ResolveWithDefault <int?>( "numLoops", NumLoops, null, context); var dateFormatValue = DataFlowParameterResolution.ResolveStringOptional( "dateFormat", DateFormat, context); return(new FileSourceCSV( this, context, adapterInputSourceValue, hasHeaderLineFlag ?? false, hasTitleLineFlag ?? false, numLoopsValue, PropertyNames, dateFormatValue)); } case "line": { var propertyNameLineValue = DataFlowParameterResolution.ResolveStringOptional("propertyNameLine", PropertyNameLine, context); var propertyNameFileValue = DataFlowParameterResolution.ResolveStringOptional("propertyNameFile", PropertyNameFile, context); return(new FileSourceLineUnformatted(this, context, adapterInputSourceValue, fileName, propertyNameLineValue, propertyNameFileValue)); } default: throw new ArgumentException("Unrecognized file format '" + formatValue + "'"); } }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new DefaultSupportSourceOp(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new SupportGenericOutputOpWPort(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { throw new System.NotImplementedException(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new DefaultSupportCaptureOpStatic<T>(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { var collectorInstance = DataFlowParameterResolution.ResolveOptionalInstance<EPDataFlowEventBeanCollector>( "collector", Collector, context); return new EventBusSourceOp(this, context.AgentInstanceContext, collectorInstance); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new SelectOp(this, context.AgentInstanceContext); }
public FileSourceLineUnformatted( FileSourceFactory factory, DataFlowOpInitializeContext context, AdapterInputSource inputSource, string filenameOrUri, string propertyNameLine, string propertyNameFile) { _factory = factory; _inputSource = inputSource; _filenameOrUri = filenameOrUri; _propertyNameLine = propertyNameLine; _propertyNameFile = propertyNameFile; var outputEventType = factory.OutputEventType; var statementContext = context.AgentInstanceContext.StatementContext; if ((outputEventType.PropertyNames.Length != 1 || outputEventType.PropertyDescriptors[0].PropertyType != typeof(string)) && propertyNameLine == null) { throw new ArgumentException( "Expecting an output event type that has a single property that is of type string, or alternatively specify the 'propertyNameLine' parameter"); } if (outputEventType is ObjectArrayEventType && outputEventType.PropertyDescriptors.Count == 1) { _lineProcessor = new LineProcessorObjectArray(); } else { var propertyNameLineToUse = propertyNameLine; if (propertyNameLineToUse == null) { propertyNameLineToUse = outputEventType.PropertyDescriptors[0].PropertyName; } if (!outputEventType.IsProperty(propertyNameLineToUse)) { throw new EPException("Failed to find property name '" + propertyNameLineToUse + "' in type '" + outputEventType.Name + "'"); } Type propertyType; try { propertyType = outputEventType.GetPropertyType(propertyNameLineToUse); } catch (PropertyAccessException ex) { throw new EPException("Invalid property name '" + propertyNameLineToUse + "': " + ex.Message, ex); } if (propertyType != typeof(string)) { throw new EPException("Invalid property type for property '" + propertyNameLineToUse + "', expected a property of type String"); } var writeables = EventTypeUtility.GetWriteableProperties(outputEventType, false); IList <WriteablePropertyDescriptor> writeableList = new List <WriteablePropertyDescriptor>(); var writeableLine = EventTypeUtility.FindWritable(propertyNameLineToUse, writeables); if (writeableLine == null) { throw new EPException("Failed to find writable property property '" + propertyNameLineToUse + "', is the property read-only?"); } writeableList.Add(writeableLine); if (propertyNameFile != null) { var writeableFile = EventTypeUtility.FindWritable(propertyNameFile, writeables); if (writeableFile == null || writeableFile.PropertyType != typeof(string)) { throw new EPException("Failed to find writable String-type property '" + propertyNameFile + "', is the property read-only?"); } writeableList.Add(writeableFile); } EventBeanManufacturer manufacturer; try { var writables = writeableList.ToArray(); manufacturer = EventTypeUtility .GetManufacturer(outputEventType, writables, statementContext.ImportServiceRuntime, false, statementContext.EventTypeAvroHandler) .GetManufacturer(statementContext.EventBeanTypedEventFactory); } catch (EventBeanManufactureException e) { throw new EPException("Event type '" + outputEventType.Name + "' cannot be written to: " + e.Message, e); } _lineProcessor = new LineProcessorGeneralPurpose(manufacturer); } if (factory.OutputPortTypes.Length == 2) { _eofProcessor = GetBeginEndProcessor(context, 1); } else if (factory.OutputPortTypes.Length == 3) { _bofProcessor = GetBeginEndProcessor(context, 1); _eofProcessor = GetBeginEndProcessor(context, 2); } else if (factory.OutputPortTypes.Length > 3) { throw new EPException("Operator only allows up to 3 output ports"); } }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MyCustomOp(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MySBInputOp(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MyTokenizerCounter(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MySupportBeanOutputOp(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MyWordCountAggregator(); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { throw new UnsupportedOperationException("Operator can only be injected as part of options"); }
public DataFlowOperator Operator(DataFlowOpInitializeContext context) { return new MyLineFeedSource(EnumerationHelper.Empty<string>()); }