/// <summary>结束活动</summary> /// <param name="token"></param> /// <param name="targetActivityInstance"></param> public void complete(IToken token, IActivityInstance targetActivityInstance) { NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token = token; event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING;//token leaving this.fireNodeEvent(event2); token.FromActivityId = this.Activity.Id; if (targetActivityInstance != null) { token.StepNumber = token.StepNumber + 1; targetActivityInstance.fire(token); } else { //按照定义,activity有且只有一个输出弧,所以此处只进行一次循环。 for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++) { ITransitionInstance transInst = LeavingTransitionInstances[i]; transInst.take(token); } } if (token.IsAlive) { NodeInstanceEvent neevent = new NodeInstanceEvent(this); neevent.Token = token; neevent.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED;//token completed this.fireNodeEvent(neevent); } }
public override void fire(IToken tk) { //log.debug("The weight of the Entering TransitionInstance is " + tk.getValue()); IToken token = tk; token.NodeId = this.Activity.Id; //触发TokenEntered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.Token = tk; event1.EventType = NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED;//token 来了 this.fireNodeEvent(event1); if (token.IsAlive)//如果token是活动的,那么就保存token,并创建taskinstance { NodeInstanceEvent neevent = new NodeInstanceEvent(this); neevent.Token = token; neevent.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED;//token 被触发,创建taskinstance,等待 this.fireNodeEvent(neevent); } else//如果token是dead状态,那么就直接结束当前节点。 { this.complete(token, null); } }
public IJoinPoint synchronized(IToken tk) { IJoinPoint joinPoint = null; tk.NodeId = this.Synchronizer.Id; //log.debug("The weight of the Entering TransitionInstance is " + tk.getValue()); // 触发TokenEntered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.Token = tk; event1.EventType = NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED;//token 进入 this.fireNodeEvent(event1); //汇聚检查 joinPoint = ((ProcessInstance)tk.ProcessInstance).createJoinPoint(this, tk);// JoinPoint由谁生成比较好? int value = (int)joinPoint.Value; if (value > this.Volume)//如果value大于同步器容量,那说明出错了 { KernelException exception = new KernelException(tk.ProcessInstance, this.Synchronizer, "Error:The token count of the synchronizer-instance can NOT be greater than it's volumn "); throw exception; } if (value < this.Volume) {// 如果Value小于容量则继续等待其他弧的汇聚。 (哪些状态为dead的token到此结束,不再向下传递) return(null); } return(joinPoint); }
public override void fire(IToken tk) { IJoinPoint joinPoint = synchronized(tk); if (joinPoint == null) { return; } IProcessInstance processInstance = tk.ProcessInstance; NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token = tk; event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED; this.fireNodeEvent(event2); //在此事件监听器中,删除原有的token NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token = tk; event4.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING; this.fireNodeEvent(event4); //首先必须检查是否有满足条件的循环 Boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。 if (joinPoint.Alive) { IToken tokenForLoop = null; tokenForLoop = new Token(); // 产生新的token tokenForLoop.IsAlive = joinPoint.Alive; tokenForLoop.ProcessInstance = processInstance; tokenForLoop.StepNumber = joinPoint.StepNumber - 1; tokenForLoop.FromActivityId = joinPoint.FromActivityId; for (int i = 0; i < this.LeavingLoopInstances.Count; i++) { ILoopInstance loopInstance = this.LeavingLoopInstances[i]; doLoop = loopInstance.take(tokenForLoop); if (doLoop) { break; } } } if (!doLoop) { NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token = tk; event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); } // NodeInstanceEvent event4 = new NodeInstanceEvent(this); // event4.setToken(tk); // event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING); // this.fireNodeEvent(event4); }
/// <summary> /// 20090914 增加统一的触发方法,实现类中根据事件的不同而进行触发 /// </summary> /// <param name="neevent"></param> public virtual void fireNodeEvent(NodeInstanceEvent neevent) { for (int i = 0; i < this.EventListeners.Count; i++) { INodeInstanceEventListener listener = this.EventListeners[i]; listener.onNodeInstanceEventFired(neevent); } }
/// <summary>节点实例监听器</summary> public virtual void onNodeInstanceEventFired(NodeInstanceEvent e) { //同步器节点的监听器触发条件,是在离开这个节点的时候 if (e.EventType == NodeInstanceEventEnum.NODEINSTANCE_LEAVING) { ISynchronizerInstance syncInst = (ISynchronizerInstance)e.getSource(); IPersistenceService persistenceService = this.RuntimeContext.PersistenceService; //删除同步器节点的token persistenceService.DeleteTokensForNode(e.Token.ProcessInstanceId, syncInst.Synchronizer.Id); } }
/// <summary>节点实例监听器</summary> public void onNodeInstanceEventFired(NodeInstanceEvent e) { // TODO Auto-generated method stub if (e.EventType == NodeInstanceEventEnum.NODEINSTANCE_FIRED) { //保存token,并创建taskinstance IPersistenceService persistenceService = this.RuntimeContext.PersistenceService; //TODO wmj2003 这里是插入还是更新token persistenceService.SaveOrUpdateToken(e.Token); //触发activity节点,就要创建新的task this.RuntimeContext.TaskInstanceManager.createTaskInstances(e.Token, (IActivityInstance)e.getSource()); } else if (e.EventType == NodeInstanceEventEnum.NODEINSTANCE_COMPLETED) { // RuntimeContext.getInstance() // .TaskInstanceManager // .archiveTaskInstances((IActivityInstance)e.getSource()); } }
/// <summary>节点实例监听器</summary> public override void onNodeInstanceEventFired(NodeInstanceEvent e) { //同步器节点的监听器触发条件,是在离开这个节点的时候 if (e.EventType == NodeInstanceEventEnum.NODEINSTANCE_LEAVING) { ISynchronizerInstance syncInst = (ISynchronizerInstance)e.getSource(); IPersistenceService persistenceService = this.RuntimeContext.PersistenceService; //删除同步器节点的token persistenceService.DeleteTokensForNode(e.Token.ProcessInstanceId, syncInst.Synchronizer.Id); } //如果节点实例结束,就触发 if (e.EventType == NodeInstanceEventEnum.NODEINSTANCE_COMPLETED) { // 执行ProcessInstance的complete操作 IToken tk = e.Token; ProcessInstance currentProcessInstance = (ProcessInstance)tk.ProcessInstance; currentProcessInstance.complete(); } }
public override void fire(IToken tk) { //TODO 此处性能需要改善一下,20090312 IJoinPoint joinPoint = synchronized(tk); if (joinPoint == null) { return; } //如果汇聚点的容量和同步器节点的容量相同 IProcessInstance processInstance = tk.ProcessInstance; // Synchronize的fire条件应该只与joinPoint的value有关(value==volume),与alive无关 NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token = tk; event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED; this.fireNodeEvent(event2); //在此事件监听器中,删除原有的token NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token = tk; event4.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING; this.fireNodeEvent(event4); //首先必须检查是否有满足条件的循环,loop比transition有更高的优先级, //(只能够有一个loop的条件为true,流程定义的时候需要注意) Boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。 if (joinPoint.Alive) { IToken tokenForLoop = null; tokenForLoop = new Token(); // 产生新的token tokenForLoop.IsAlive = joinPoint.Alive; tokenForLoop.ProcessInstance = processInstance; tokenForLoop.StepNumber = joinPoint.StepNumber - 1; tokenForLoop.FromActivityId = joinPoint.FromActivityId; for (int i = 0; i < this.LeavingLoopInstances.Count; i++) { ILoopInstance loopInstance = this.LeavingLoopInstances[i]; doLoop = loopInstance.take(tokenForLoop); if (doLoop) { break; } } } if (!doLoop) {//如果没有循环,则执行transitionInstance //非顺序流转的需要生成新的token, Boolean activiateDefaultCondition = true; ITransitionInstance defaultTransInst = null; for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++) { ITransitionInstance transInst = LeavingTransitionInstances[i]; String condition = transInst.Transition.Condition; if (condition != null && condition.Equals(ConditionConstant.DEFAULT)) { defaultTransInst = transInst; continue; } Token token = new Token(); // 产生新的token token.IsAlive = joinPoint.Alive; token.ProcessInstance = processInstance; token.StepNumber = joinPoint.StepNumber; token.FromActivityId = joinPoint.FromActivityId; Boolean alive = transInst.take(token); if (alive) { activiateDefaultCondition = false; } } if (defaultTransInst != null) { Token token = new Token(); token.IsAlive = activiateDefaultCondition && joinPoint.Alive; token.ProcessInstance = processInstance; token.StepNumber = joinPoint.StepNumber; token.FromActivityId = joinPoint.FromActivityId; defaultTransInst.take(token); } } NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token = tk; event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); }
public override void onNodeInstanceEventFired(NodeInstanceEvent e) { //开始节点,不需要做任何处理! // System.out.println("==Inside StartNode Extension...."); }
/// <summary> /// 开始节点触发 /// </summary> /// <param name="tk"></param> public override void fire(IToken tk) { if (!tk.IsAlive)//如果token是false,那么直接返回 { return;// } if (tk.Value != this.Volume) { KernelException exception = new KernelException(tk.ProcessInstance, this.startNode, "Error:Illegal StartNodeInstance,the tokenValue MUST be equal to the volume "); throw exception; } tk.NodeId = this.Synchronizer.Id;//到开始节点(同步器) IProcessInstance processInstance = tk.ProcessInstance;//从token中获得流程实例对象 //触发token_entered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.Token=tk; event1.EventType=NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED;//token进入 this.fireNodeEvent(event1); //触发fired事件 NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token=tk; event2.EventType=NodeInstanceEventEnum.NODEINSTANCE_FIRED;//token 触发 this.fireNodeEvent(event2); //触发leaving事件 NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token=tk; event4.EventType=NodeInstanceEventEnum.NODEINSTANCE_LEAVING;//token 离开 this.fireNodeEvent(event4); Boolean activiateDefaultCondition = true;//激活默认弧线的标志 ITransitionInstance defaultTransInst = null; //找到所有开始节点的输出弧 for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++) { ITransitionInstance transInst = LeavingTransitionInstances[i];//开始节点的边的类型只能是transition String condition = transInst.Transition.Condition; //如果弧线的条件!=null 并且 =“default” ,那么弧线实例就是default的弧线了。 if (condition != null && condition.Equals(ConditionConstant.DEFAULT)) { defaultTransInst = transInst;//记录default转移线,其他条件都未false,才执行它 continue; } Token token = new Token(); // 产生新的token token.IsAlive = true; token.ProcessInstance = processInstance; token.FromActivityId = tk.FromActivityId; token.StepNumber = tk.StepNumber + 1;//步骤号+1 Boolean alive = transInst.take(token);//触发弧线的token if (alive) { activiateDefaultCondition = false; } } if (defaultTransInst != null)//如果defaultTransInst!=null ,走的是default值的弧线 { Token token = new Token(); token.IsAlive = activiateDefaultCondition;//设置token为dead token.ProcessInstance = processInstance; token.FromActivityId = token.FromActivityId; token.StepNumber = tk.StepNumber + 1; defaultTransInst.take(token); } //触发completed事件 NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token=tk; event3.EventType=NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); }
public override void fire(IToken tk) { //TODO 此处性能需要改善一下,20090312 IJoinPoint joinPoint = synchronized(tk); if (joinPoint == null) return; //如果汇聚点的容量和同步器节点的容量相同 IProcessInstance processInstance = tk.ProcessInstance; // Synchronize的fire条件应该只与joinPoint的value有关(value==volume),与alive无关 NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token=tk; event2.EventType=NodeInstanceEventEnum.NODEINSTANCE_FIRED; this.fireNodeEvent(event2); //在此事件监听器中,删除原有的token NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token=tk; event4.EventType=NodeInstanceEventEnum.NODEINSTANCE_LEAVING; this.fireNodeEvent(event4); //首先必须检查是否有满足条件的循环,loop比transition有更高的优先级, //(只能够有一个loop的条件为true,流程定义的时候需要注意) Boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。 if (joinPoint.Alive) { IToken tokenForLoop = null; tokenForLoop = new Token(); // 产生新的token tokenForLoop.IsAlive=joinPoint.Alive; tokenForLoop.ProcessInstance=processInstance; tokenForLoop.StepNumber=joinPoint.StepNumber - 1; tokenForLoop.FromActivityId=joinPoint.FromActivityId; for (int i = 0; i < this.LeavingLoopInstances.Count; i++) { ILoopInstance loopInstance = this.LeavingLoopInstances[i]; doLoop = loopInstance.take(tokenForLoop); if (doLoop) { break; } } } if (!doLoop) {//如果没有循环,则执行transitionInstance //非顺序流转的需要生成新的token, Boolean activiateDefaultCondition = true; ITransitionInstance defaultTransInst = null; for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++) { ITransitionInstance transInst = LeavingTransitionInstances[i]; String condition = transInst.Transition.Condition; if (condition != null && condition.Equals(ConditionConstant.DEFAULT)) { defaultTransInst = transInst; continue; } Token token = new Token(); // 产生新的token token.IsAlive=joinPoint.Alive; token.ProcessInstance=processInstance; token.StepNumber=joinPoint.StepNumber; token.FromActivityId=joinPoint.FromActivityId; Boolean alive = transInst.take(token); if (alive) { activiateDefaultCondition = false; } } if (defaultTransInst != null) { Token token = new Token(); token.IsAlive=activiateDefaultCondition && joinPoint.Alive; token.ProcessInstance=processInstance; token.StepNumber=joinPoint.StepNumber; token.FromActivityId=joinPoint.FromActivityId; defaultTransInst.take(token); } } NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token=tk; event3.EventType=NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); }
/// <summary> /// 开始节点触发 /// </summary> /// <param name="tk"></param> public override void fire(IToken tk) { if (!tk.IsAlive) //如果token是false,那么直接返回 { return; // } if (tk.Value != this.Volume) { KernelException exception = new KernelException(tk.ProcessInstance, this.startNode, "Error:Illegal StartNodeInstance,the tokenValue MUST be equal to the volume "); throw exception; } tk.NodeId = this.Synchronizer.Id; //到开始节点(同步器) IProcessInstance processInstance = tk.ProcessInstance; //从token中获得流程实例对象 //触发token_entered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.Token = tk; event1.EventType = NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED;//token进入 this.fireNodeEvent(event1); //触发fired事件 NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token = tk; event2.EventType = NodeInstanceEventEnum.NODEINSTANCE_FIRED;//token 触发 this.fireNodeEvent(event2); //触发leaving事件 NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token = tk; event4.EventType = NodeInstanceEventEnum.NODEINSTANCE_LEAVING;//token 离开 this.fireNodeEvent(event4); Boolean activiateDefaultCondition = true;//激活默认弧线的标志 ITransitionInstance defaultTransInst = null; //找到所有开始节点的输出弧 for (int i = 0; LeavingTransitionInstances != null && i < LeavingTransitionInstances.Count; i++) { ITransitionInstance transInst = LeavingTransitionInstances[i];//开始节点的边的类型只能是transition String condition = transInst.Transition.Condition; //如果弧线的条件!=null 并且 =“default” ,那么弧线实例就是default的弧线了。 if (condition != null && condition.Equals(ConditionConstant.DEFAULT)) { defaultTransInst = transInst;//记录default转移线,其他条件都未false,才执行它 continue; } Token token = new Token(); // 产生新的token token.IsAlive = true; token.ProcessInstance = processInstance; token.FromActivityId = tk.FromActivityId; token.StepNumber = tk.StepNumber + 1; //步骤号+1 Boolean alive = transInst.take(token); //触发弧线的token if (alive) { activiateDefaultCondition = false; } } if (defaultTransInst != null)//如果defaultTransInst!=null ,走的是default值的弧线 { Token token = new Token(); token.IsAlive = activiateDefaultCondition;//设置token为dead token.ProcessInstance = processInstance; token.FromActivityId = token.FromActivityId; token.StepNumber = tk.StepNumber + 1; defaultTransInst.take(token); } //触发completed事件 NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token = tk; event3.EventType = NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); }
public override void fire(IToken tk) { IJoinPoint joinPoint = synchronized(tk); if (joinPoint == null) return; IProcessInstance processInstance = tk.ProcessInstance; NodeInstanceEvent event2 = new NodeInstanceEvent(this); event2.Token=tk; event2.EventType=NodeInstanceEventEnum.NODEINSTANCE_FIRED; this.fireNodeEvent(event2); //在此事件监听器中,删除原有的token NodeInstanceEvent event4 = new NodeInstanceEvent(this); event4.Token=tk; event4.EventType=NodeInstanceEventEnum.NODEINSTANCE_LEAVING; this.fireNodeEvent(event4); //首先必须检查是否有满足条件的循环 Boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。 if (joinPoint.Alive) { IToken tokenForLoop = null; tokenForLoop = new Token(); // 产生新的token tokenForLoop.IsAlive=joinPoint.Alive; tokenForLoop.ProcessInstance=processInstance; tokenForLoop.StepNumber=joinPoint.StepNumber - 1; tokenForLoop.FromActivityId=joinPoint.FromActivityId; for (int i = 0; i < this.LeavingLoopInstances.Count; i++) { ILoopInstance loopInstance = this.LeavingLoopInstances[i]; doLoop = loopInstance.take(tokenForLoop); if (doLoop) { break; } } } if (!doLoop) { NodeInstanceEvent event3 = new NodeInstanceEvent(this); event3.Token=tk; event3.EventType=NodeInstanceEventEnum.NODEINSTANCE_COMPLETED; this.fireNodeEvent(event3); } // NodeInstanceEvent event4 = new NodeInstanceEvent(this); // event4.setToken(tk); // event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING); // this.fireNodeEvent(event4); }
public IJoinPoint synchronized(IToken tk) { IJoinPoint joinPoint = null; tk.NodeId=this.Synchronizer.Id; //log.debug("The weight of the Entering TransitionInstance is " + tk.getValue()); // 触发TokenEntered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.Token=tk; event1.EventType=NodeInstanceEventEnum.NODEINSTANCE_TOKEN_ENTERED; this.fireNodeEvent(event1); //汇聚检查 joinPoint = ((ProcessInstance)tk.ProcessInstance).createJoinPoint(this, tk);// JoinPoint由谁生成比较好? int value = (int)joinPoint.Value; //log.debug("The volume of " + this.toString() + " is " + volume); //log.debug("The value of " + this.toString() + " is " + value); if (value > this.Volume) { KernelException exception = new KernelException(tk.ProcessInstance, this.Synchronizer, "Error:The token count of the synchronizer-instance can NOT be greater than it's volumn "); throw exception; } if (value < this.Volume) {// 如果Value小于容量则继续等待其他弧的汇聚。 return null; } return joinPoint; }