Example #1
0
 /// <summary>
 /// @see IState#Handle .
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 /// <exception cref="Exception">&nbsp;</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">&nbsp;</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">&nbsp;</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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
        /// <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));
        }
Example #7
0
 /// <summary>
 /// Returns the FlowExecutionStatus stored.
 /// @see IState#Handle
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 /// <exception cref="Exception">&nbsp;</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);
     }
 }
Example #8
0
 /// <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);
 }
Example #9
0
        /// <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;
        }
Example #10
0
 /// <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);
 }
Example #11
0
 /// <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);
 }
Example #12
0
 /// <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));
 }
Example #13
0
 /// <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);
 }
Example #14
0
 /// <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));
 }
Example #15
0
 /// <summary>
 /// @see IState#Handle .
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 /// <exception cref="Exception">&nbsp;</exception>
 public abstract FlowExecutionStatus Handle(IFlowExecutor executor);
Example #16
0
 /// <summary>
 /// @see IState#Handle .
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 public override FlowExecutionStatus Handle(IFlowExecutor executor)
 {
     return _flow.Start(executor).Status;
 }
Example #17
0
 /// <summary>
 /// @see IState#Handle .
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 /// <exception cref="Exception"></exception>
 public abstract FlowExecutionStatus Handle(IFlowExecutor executor);
Example #18
0
 /// <summary>
 /// @see IState#Handle .
 /// </summary>
 /// <param name="executor"></param>
 /// <returns></returns>
 public override FlowExecutionStatus Handle(IFlowExecutor executor)
 {
     return(_flow.Start(executor).Status);
 }
Example #19
0
        /// <summary>
        /// Returns the FlowExecutionStatus stored.
        /// @see IState#Handle
        /// </summary>
        /// <param name="executor"></param>
        /// <returns></returns>
        /// <exception cref="Exception">&nbsp;</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;

            }
        }