/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"> </exception> public override FlowExecutionStatus Handle(IFlowExecutor executor) { // On starting a new step, possibly upgrade the last execution to make // sure it is abandoned on restart if it failed. executor.AbandonStepExecution(); return(new FlowExecutionStatus(executor.ExecuteStep(Step))); }
public AttributeFlowTemplate(IEventStore eventStore) { commandFactory = new CommandRegister(eventStore); eventRaiserFactory = eventStore.GetEventRaiserFactory(); this.eventStore = eventStore; RegisterCommands(); annFlowExecutor = GetExecutor(); }
/// <summary> /// @see IFlow#Start . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="FlowExecutionException"> </exception> public FlowExecution Start(IFlowExecutor executor) { if (StartState == null) { InitializeTransitions(); } IState state = StartState; string stateName = state.GetName(); return(Resume(stateName, executor)); }
/// <summary> /// @see IFlow#Resume . /// </summary> /// <param name="stateName"></param> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="FlowExecutionException"> </exception> public FlowExecution Resume(string stateName, IFlowExecutor executor) { FlowExecutionStatus status = FlowExecutionStatus.Unkown; IState state; _stateMap.TryGetValue(stateName, out state); if (Logger.IsDebugEnabled) { Logger.Debug("Resuming state={0} with status={1}", stateName, status); } StepExecution stepExecution = null; String currentStateName = stateName; // Terminate if there are no more states while (IsFlowContinued(state, status, stepExecution)) { currentStateName = state.GetName(); try { if (Logger.IsDebugEnabled) { Logger.Debug("Handling state={0}", currentStateName); } status = state.Handle(executor); stepExecution = executor.GetStepExecution(); } catch (FlowExecutionException) { executor.Close(new FlowExecution(currentStateName, status)); throw; } catch (Exception e) { executor.Close(new FlowExecution(currentStateName, status)); throw new FlowExecutionException( string.Format("Ended flow={0} at state={1} with exception", Name, currentStateName), e); } if (Logger.IsDebugEnabled) { Logger.Debug("Completed state={0} with status={1}", currentStateName, status); } state = NextState(currentStateName, status, stepExecution); } FlowExecution result = new FlowExecution(currentStateName, status); executor.Close(result); return(result); }
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> public override FlowExecutionStatus Handle(IFlowExecutor executor) { ICollection<Task<FlowExecution>> tasks = new List<Task<FlowExecution>>(); foreach (IFlow flow in _flows) { IFlow aFlow = flow; Task<FlowExecution> task = new Task<FlowExecution>(() => aFlow.Start(executor)); tasks.Add(task); try { _taskExecutor.Execute(task); } catch (TaskRejectedException) { throw new FlowExecutionException("TaskExecutor rejected task for flow=" + flow.GetName()); } } ICollection<FlowExecution> results = tasks.Select(task => task.Result).ToList(); return DoAggregation(results, executor); }
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> public override FlowExecutionStatus Handle(IFlowExecutor executor) { ICollection <Task <FlowExecution> > tasks = new List <Task <FlowExecution> >(); foreach (IFlow flow in _flows) { IFlow aFlow = flow; Task <FlowExecution> task = new Task <FlowExecution>(() => aFlow.Start(executor)); tasks.Add(task); try { _taskExecutor.Execute(task); } catch (TaskRejectedException) { throw new FlowExecutionException("TaskExecutor rejected task for flow=" + flow.GetName()); } } ICollection <FlowExecution> results = tasks.Select(task => task.Result).ToList(); return(DoAggregation(results, executor)); }
/// <summary> /// Returns the FlowExecutionStatus stored. /// @see IState#Handle /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"> </exception> public override FlowExecutionStatus Handle(IFlowExecutor executor) { lock (executor) { // Special case. If the last step execution could not complete we // are in an unknown state (possibly unrecoverable). StepExecution stepExecution = executor.GetStepExecution(); if (stepExecution != null && executor.GetStepExecution().BatchStatus == BatchStatus.Unknown) { return(FlowExecutionStatus.Unkown); } if (Status.IsStop()) { if (!executor.IsRestart()) { //If there are step executions, then we are not at the // beginning of a restart. if (Abandon) { // Only if instructed to do so, upgrade the status of // last step execution so it is not replayed on a // restart... executor.AbandonStepExecution(); } } else { // If we are a stop state and we got this far then it must // be a restart, so return COMPLETED. return(FlowExecutionStatus.Completed); } } SetExitStatus(executor, Code); return(Status); } }
/// <summary> /// Do Aggregation. /// </summary> /// <param name="results"></param> /// <param name="executor"></param> /// <returns></returns> protected FlowExecutionStatus DoAggregation(ICollection<FlowExecution> results, IFlowExecutor executor) { return _aggregator.Aggregate(results); }
/// <summary> /// @see IFlow#Resume . /// </summary> /// <param name="stateName"></param> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="FlowExecutionException"></exception> public FlowExecution Resume(string stateName, IFlowExecutor executor) { FlowExecutionStatus status = FlowExecutionStatus.Unkown; IState state; _stateMap.TryGetValue(stateName, out state); if (Logger.IsDebugEnabled) { Logger.Debug("Resuming state={0} with status={1}", stateName, status); } StepExecution stepExecution = null; String currentStateName = stateName; // Terminate if there are no more states while (IsFlowContinued(state, status, stepExecution)) { currentStateName = state.GetName(); try { if (Logger.IsDebugEnabled) { Logger.Debug("Handling state={0}", currentStateName); } status = state.Handle(executor); stepExecution = executor.GetStepExecution(); } catch (FlowExecutionException) { executor.Close(new FlowExecution(currentStateName, status)); throw; } catch (Exception e) { executor.Close(new FlowExecution(currentStateName, status)); throw new FlowExecutionException( string.Format("Ended flow={0} at state={1} with exception", Name, currentStateName), e); } if (Logger.IsDebugEnabled) { Logger.Debug("Completed state={0} with status={1}", currentStateName, status); } state = NextState(currentStateName, status, stepExecution); } FlowExecution result = new FlowExecution(currentStateName, status); executor.Close(result); return result; }
/// <summary> /// @see IFlow#Start . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="FlowExecutionException"></exception> public FlowExecution Start(IFlowExecutor executor) { if (StartState == null) { InitializeTransitions(); } IState state = StartState; string stateName = state.GetName(); return Resume(stateName, executor); }
/// <summary> /// Performs any logic to update the exit status for the current flow. /// </summary> /// <param name="executor">FlowExecutor for the current flow</param> /// <param name="code">The exit status to save</param> protected void SetExitStatus(IFlowExecutor executor, string code) { executor.AddExitStatus(code); }
/// <summary> /// Do Aggregation. /// </summary> /// <param name="results"></param> /// <param name="executor"></param> /// <returns></returns> protected FlowExecutionStatus DoAggregation(ICollection <FlowExecution> results, IFlowExecutor executor) { return(_aggregator.Aggregate(results)); }
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public override FlowExecutionStatus Handle(IFlowExecutor executor) { // On starting a new step, possibly upgrade the last execution to make // sure it is abandoned on restart if it failed. executor.AbandonStepExecution(); return new FlowExecutionStatus(executor.ExecuteStep(Step)); }
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"> </exception> public abstract FlowExecutionStatus Handle(IFlowExecutor executor);
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> public override FlowExecutionStatus Handle(IFlowExecutor executor) { return _flow.Start(executor).Status; }
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public abstract FlowExecutionStatus Handle(IFlowExecutor executor);
/// <summary> /// @see IState#Handle . /// </summary> /// <param name="executor"></param> /// <returns></returns> public override FlowExecutionStatus Handle(IFlowExecutor executor) { return(_flow.Start(executor).Status); }
/// <summary> /// Returns the FlowExecutionStatus stored. /// @see IState#Handle /// </summary> /// <param name="executor"></param> /// <returns></returns> /// <exception cref="Exception"> </exception> public override FlowExecutionStatus Handle(IFlowExecutor executor) { lock (executor) { // Special case. If the last step execution could not complete we // are in an unknown state (possibly unrecoverable). StepExecution stepExecution = executor.GetStepExecution(); if (stepExecution != null && executor.GetStepExecution().BatchStatus == BatchStatus.Unknown) { return FlowExecutionStatus.Unkown; } if (Status.IsStop()) { if (!executor.IsRestart()) { //If there are step executions, then we are not at the // beginning of a restart. if (Abandon) { // Only if instructed to do so, upgrade the status of // last step execution so it is not replayed on a // restart... executor.AbandonStepExecution(); } } else { // If we are a stop state and we got this far then it must // be a restart, so return COMPLETED. return FlowExecutionStatus.Completed; } } SetExitStatus(executor, Code); return Status; } }