• 开源工作流Fireflow源码分析之事件驱动


         事件驱动在fireflow用的频率很高.比如:StartNodeInstance,TransitionInstance,ActivityInstance,LoopInstance,EndNodeInstance

         1):定义事件监听器接口模型

    package org.fireflow.kernel.event;
    import org.fireflow.kernel.KernelException;
    /**
     *定义事件监听器模型
     *
     */
    public interface INodeInstanceEventListener {
    	/**
    	 * 节点实例监听器
    	 * @param e
    	 * @throws KernelException
    	 */
           public void onNodeInstanceEventFired(NodeInstanceEvent e)throws KernelException;
    }
    

     2):定义事件模型,它继承于EventObject

     

    package org.fireflow.kernel.event;
    import java.util.EventObject;
    import org.fireflow.kernel.IToken;
    /**
     * 事件模型
     * 
     * @author chennieyun
     * 
     */
    @SuppressWarnings("serial")
    public class NodeInstanceEvent extends EventObject {
    	// 事件类型
    	public static final int NODEINSTANCE_TOKEN_ENTERED = 1;
    	public static final int NODEINSTANCE_FIRED = 2;
    	public static final int NODEINSTANCE_COMPLETED = 3;
    	public static final int NODEINSTANCE_LEAVING = 4;
    	// 默认的事件类列
    	int eventType = -1;
    	private IToken token = null;
    
    	private NodeInstanceEvent() {
    		super(null);
    	}
    	// 注册事件源
    	public NodeInstanceEvent(Object source) {
    		super(source);
    	}
    
    	public IToken getToken() {
    		return token;
    	}
    
    	public void setToken(IToken tk) {
    		this.token = tk;
    	}
    
    	public int getEventType() {
    		return eventType;
    	}
    
    	public void setEventType(int eventType) {
    		this.eventType = eventType;
    	}
    }
    

         3:触发事件, 以ActivityInstance为例

              //触发Activity Entered事件
            //定义一个数据源
            NodeInstanceEvent event1 = new NodeInstanceEvent(this);
            //设置当前的令牌
            event1.setToken(tk);
            //设置当前的事件类型
            event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED);
            //触发事件
            fireNodeEvent(event1);
      	/**
    	 * wangmj  20090914 增加统一的触发方法,实现类中根据事件的不同而进行触发
    	 * @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);
    		}
    	}
    

       4:其它说明, StartNodeInstance,TransitionInstance,ActivityInstance,LoopInstance,EndNodeInstance都有一些默认的事件监听器,具体在FireflowContext.xml中定义.

        

       <!-- **************Kernel Manager Begin*************** -->
        <bean id="kernelManager"
              class="org.fireflow.kernel.KernelManager">
            <property name="kernelExtensions">
                <map>
                    <entry key="org.fireflow.kernel.StartNodeInstance">
                        <list>
                            <ref local="startNodeInstanceEventListenser"/>
                        </list>
                    </entry>
                    <entry key="org.fireflow.kernel.ActivityInstance">
                        <list>
                            <ref local="activityInstanceEventListener"/>
                        </list>
                    </entry>
                    <entry key="org.fireflow.kernel.SynchronizerInstance">
                        <list>
                            <ref local="synchronizerInstanceEventListenser"/>
                        </list>
                    </entry>
                    <entry key="org.fireflow.kernel.EndNodeInstance">
                        <list>
                            <ref local="endNodeInstanceEventListenser"/>
                        </list>
                    </entry>
                    <entry key="org.fireflow.kernel.TransitionInstance">
                        <list>
                            <ref local="transitionInstanceEventListenser"/>
                        </list>
                    </entry>
                    <entry key="org.fireflow.kernel.LoopInstance">
                        <list>
                            <ref local="loopInstanceEventListenser"/>
                        </list>
                    </entry>
                </map>
            </property>
        </bean>
    

    Fireflow的官方网站为:

    http://www.fireflow.org/forum.php

  • 相关阅读:
    ora12514
    telnet到虚拟机上的red hat linux失败——解决办法
    linux下监听的配置
    本机win7系统与虚拟机中的linux系统实现通讯
    ORA01078: failure in processing system parameters LRM00109: could not open parameter file '/oradata/oracle/112/dbs/in
    Xmanager无法登录Red Hat Linux——解决方法
    几种常见算法的介绍及复杂度分析(转)
    Linux学习笔记18cal显示日历
    Linux学习笔记14架设Apache http服务器
    Installing Oracle Database 10g on Linux
  • 原文地址:https://www.cnblogs.com/mzhanker/p/2072530.html
Copyright © 2020-2023  润新知