ActivityInstance.java
/* Activity触发事件 * @see org.fireflow.kernel.INodeInstance#fire(org.fireflow.kernel.IToken) */ public void fire(IToken tk) throws KernelException { //打印权重. log.debug("The weight of the Entering TransitionInstance is " + tk.getValue()); IToken token = tk; //设置当前的节点实例ID token.setNodeId(this.getActivity().getId()); //触发Activity Entered事件 NodeInstanceEvent event1 = new NodeInstanceEvent(this); event1.setToken(tk); event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED); fireNodeEvent(event1); //如果token是活动的 //注:关于token的状态(alive or dead),是由TranstionInstance决定的,详见<<开源工作流Fireflow源码分析之运行流程二>> if (token.isAlive()) { //触发Activity Fired事件 NodeInstanceEvent event = new NodeInstanceEvent(this); event.setToken(token); event.setEventType(NodeInstanceEvent.NODEINSTANCE_FIRED); //详见下面介绍 fireNodeEvent(event); } else { //如果token是dead状态,那么就直接结束当前节点。 //详见<<开源工作流Fireflow源码分析之ActivityInstance completed一.doc>> this.complete(token, null); } }
AbstractNodeInstance.java
/** * 触发ActivityInstance各种事件,实现类中根据事件的不同而进行触发 * @param event * @throws KernelException */ public void fireNodeEvent(NodeInstanceEvent event) throws KernelException{ //遍历当前节点的事件监听器,依次进行触发 for (int i=0;i<this.eventListeners.size();i++){ INodeInstanceEventListener listener = this.eventListeners.get(i); listener.onNodeInstanceEventFired(event); } }
ActivityInstance默认的事件监听器为ActivityInstanceExtension
/* ActivityInstance事件触发 * @see org.fireflow.kernel.event.INodeInstanceEventListener#onNodeInstanceEventFired(org.fireflow.kernel.event.NodeInstanceEvent) */ public void onNodeInstanceEventFired(NodeInstanceEvent e) throws KernelException { //如果事件为fired if (e.getEventType() == NodeInstanceEvent.NODEINSTANCE_FIRED) { //取到spring中定义的持久化类 IPersistenceService persistenceService = rtCtx.getPersistenceService(); //保存token,并创建taskinstance persistenceService.saveOrUpdateToken(e.getToken()); //取到task管理器,创建activity Task. //详见<<开源工作流Fireflow源码分析之ActivityInstance Created Task>>
rtCtx.getTaskInstanceManager().createTaskInstances(e.getToken(), (IActivityInstance) e.getSource()); } else if (e.getEventType() == NodeInstanceEvent.NODEINSTANCE_COMPLETED) { //如果事件为completed,作者未处理 } }