public void Run() { lock (this) { CheckExecCompleteState(); CheckExecCancelledState(); CheckExecRunningState(); if (_sourceRunnables.Count != 1) { throw new UnsupportedOperationException( "The data flow '" + _dataFlowName + "' has zero or multiple sources and requires the use of the start method instead"); } CallOperatorOpen(); GraphSourceRunnable sourceRunnable = _sourceRunnables[0]; SetState(EPDataFlowState.RUNNING); _runCurrentThread = Thread.CurrentThread; try { sourceRunnable.RunSync(); } catch (ThreadInterruptedException) { CallOperatorClose(); SetState(EPDataFlowState.CANCELLED); throw new EPDataFlowCancellationException( "Data flow '" + _dataFlowName + "' execution was cancelled", _dataFlowName); } catch (Exception t) { CallOperatorClose(); SetState(EPDataFlowState.COMPLETE); throw new EPDataFlowExecutionException( "Exception encountered running data flow '" + _dataFlowName + "': " + t.Message, t, _dataFlowName); } CallOperatorClose(); if (_state != EPDataFlowState.CANCELLED) { SetState(EPDataFlowState.COMPLETE); } } }
public static EPDataFlowInstance Instantiate( IContainer container, int agentInstanceId, DataflowDesc dataflow, EPDataFlowInstantiationOptions options) { var statementContext = dataflow.StatementContext; // allocate agent instance context var @lock = statementContext.StatementAgentInstanceLockFactory.GetStatementLock( statementContext.StatementName, statementContext.Annotations, statementContext.IsStatelessSelect, statementContext.StatementType); var handle = new EPStatementAgentInstanceHandle(statementContext.EpStatementHandle, agentInstanceId, @lock); var auditProvider = statementContext.StatementInformationals.AuditProvider; var instrumentationProvider = statementContext.StatementInformationals.InstrumentationProvider; var agentInstanceContext = new AgentInstanceContext(statementContext, handle, null, null, auditProvider, instrumentationProvider); // assure variables statementContext.VariableManagementService.SetLocalVersion(); // instantiate operators var operators = InstantiateOperators(container, agentInstanceContext, options, dataflow); // determine binding of each channel to input methods (ports) IList<LogicalChannelBinding> operatorChannelBindings = new List<LogicalChannelBinding>(); foreach (var channel in dataflow.LogicalChannels) { var targetClass = operators.Get(channel.ConsumingOpNum).GetType(); var consumingMethod = FindMatchingMethod(channel.ConsumingOpPrettyPrint, targetClass, channel, false); LogicalChannelBindingMethodDesc onSignalMethod = null; if (channel.OutputPort.HasPunctuation) { onSignalMethod = FindMatchingMethod(channel.ConsumingOpPrettyPrint, targetClass, channel, true); } operatorChannelBindings.Add(new LogicalChannelBinding(channel, consumingMethod, onSignalMethod)); } // obtain realization var dataFlowSignalManager = new DataFlowSignalManager(); var statistics = DataflowInstantiatorHelper.Realize( dataflow, operators, operatorChannelBindings, dataFlowSignalManager, options, agentInstanceContext); // For each GraphSource add runnable IList<GraphSourceRunnable> sourceRunnables = new List<GraphSourceRunnable>(); var audit = AuditEnum.DATAFLOW_SOURCE.GetAudit(statementContext.Annotations) != null; foreach (var operatorEntry in operators) { if (!(operatorEntry.Value is DataFlowSourceOperator)) { continue; } var meta = dataflow.OperatorMetadata.Get(operatorEntry.Key); var graphSource = (DataFlowSourceOperator) operatorEntry.Value; var runnable = new GraphSourceRunnable( agentInstanceContext, graphSource, dataflow.DataflowName, options.DataFlowInstanceId, meta.OperatorName, operatorEntry.Key, meta.OperatorPrettyPrint, options.ExceptionHandler, audit); sourceRunnables.Add(runnable); dataFlowSignalManager.AddSignalListener(operatorEntry.Key, runnable); } return new EPDataFlowInstanceImpl( options.DataFlowInstanceUserObject, options.DataFlowInstanceId, statistics, operators, sourceRunnables, dataflow, agentInstanceContext, statistics, options.ParametersURIs); }