public virtual void AddActivity(Activity activity) { this.SyncObject.EnterWriteLock(); try { _Activities.Add(activity); } finally { this.SyncObject.ExitWriteLock(); } }
public virtual bool RemoveActivity(Activity activity) { this.SyncObject.EnterWriteLock(); try { return _Activities.Remove(activity); } finally { this.SyncObject.ExitWriteLock(); } }
void ActiveNext(Activity finished) { this.SyncObject.EnterWriteLock(); try { if (finished._State != ActivityStates.Finished) throw new InvalidOperationException("ActiveNext只能从Finished状态出来,而当前状态是" + Enum.GetName(typeof(ActivityStates), finished._State)); foreach (var activity in this._Activities) { var trans = activity as Transaction; if (trans != null) { if (trans.FromActivityId == finished.Id) this.InternalActive(activity); } } } finally { this.SyncObject.ExitWriteLock(); } }
void InternalActive(Activity activity) { if (activity._State == ActivityStates.Inactive || activity._State == ActivityStates.Finished) { activity._State = ActivityStates.Actived; } this._ActivedActivities.Enqueue(activity); }
/// <summary> /// 把某个Activity加入到执行队列里去 /// </summary> /// <param name="finishedActivity"></param> public void Active(Activity activity) { this.SyncObject.EnterWriteLock(); try { InternalActive(activity); } finally { this.SyncObject.ExitWriteLock(); } }
void Active(Activity activity) { this._syncLocker.EnterWriteLock(); try { if (activity._ExecutionState.IsInactive()) activity._ExecutionState = ExecutionStates.Actived; _activedActivities.Enqueue(activity); if (_scheduling != null && _schedulingTask==null) { _schedulingTask = new Task(async ()=> await Scheduling()); _scheduling = true; _schedulingTask.Start(); } } finally { this._syncLocker.ExitWriteLock(); } }
void ActiveNexts(Activity finishedActivity) { }
ActivityStates InteralExecuteActivity(Activity activity,Queue<Activity> suspendedQueue, DateTime execTime) { //这个属性虽然放在activity上面,起读写都受Engine锁的保护 var state = activity._ExecutionState; //谁在线程sleep期间修改了activity的状态 //比如手动调用了ExecuteActivity //就不用执行了。 if (state.IsInactive()) return activity._State; //状态是挂起,但时间还没到,继续挂起,处理下一个活动 if (state == ExecutionStates.Suspended && activity.ResumeTime > execTime) { suspendedQueue.Enqueue(activity); return activity._State; } activity._ExecutionState = ExecutionStates.Running; var result1 = activity.Execute(); var result = new ExecuteResult(); ///挂起状态,并且有明确的恢复时间,重新进入执行队列 if (result.ResumeTime != null) { activity._ExecutionState = ExecutionStates.Suspended; suspendedQueue.Enqueue(activity); } else if (result.State == ActivityStates.Finished) { activity._ExecutionState = ExecutionStates.Completed; } else { activity._ExecutionState = ExecutionStates.Inactive; } return activity._State; }