⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleexpressionpool.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions are met: *  * . Redistributions of source code must retain the above copyright notice, this *   list of conditions and the following disclaimer.   *  * . Redistributions in binary form must reproduce the above copyright notice,  *   this list of conditions and the following disclaimer in the documentation  *   and/or other materials provided with the distribution. *  * . Neither the name of the "OpenWFE" nor the names of its contributors may be *   used to endorse or promote products derived from this software without *   specific prior written permission. *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  * POSSIBILITY OF SUCH DAMAGE. * * $Id: SimpleExpressionPool.java,v 1.44 2005/07/17 16:31:49 jmettraux Exp $ *///// SimpleExpressionPool.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.0.04 20.11.2001 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.engine.impl.expool;import openwfe.org.MapUtils;import openwfe.org.Application;import openwfe.org.AbstractService;import openwfe.org.ServiceException;import openwfe.org.OpenWfeException;import openwfe.org.ApplicationContext;import openwfe.org.xml.XmlUtils;import openwfe.org.time.Time;import openwfe.org.engine.Definitions;import openwfe.org.engine.control.auth.ControlPermission;import openwfe.org.engine.expool.PoolException;import openwfe.org.engine.expool.ExpressionPool;import openwfe.org.engine.expool.ExpressionStore;import openwfe.org.engine.history.History;import openwfe.org.engine.workitem.WorkItem;import openwfe.org.engine.workitem.InFlowWorkItem;import openwfe.org.engine.dispatch.DispatchingException;import openwfe.org.engine.expressions.GoneParentId;import openwfe.org.engine.expressions.FlowExpression;import openwfe.org.engine.expressions.ApplyException;import openwfe.org.engine.expressions.ReplyException;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.expressions.ExpressionWithTimer;import openwfe.org.engine.expressions.ExpressionWithTimeOut;import openwfe.org.engine.expressions.CompositeFlowExpression;import openwfe.org.engine.expressions.raw.RawExpression;import openwfe.org.engine.expressions.state.NormalState;import openwfe.org.engine.expressions.state.FrozenState;import openwfe.org.engine.expressions.state.ExpressionState;import openwfe.org.engine.participants.Participant;import openwfe.org.engine.participants.ParticipantMap;/** * The pool of expressions : it stores workflow instances as expression bits. * In fact, it merely orchestrates this, the real storage work is done * by ExpressionStore implementations. * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/07/17 16:31:49 $ * <br>$Id: SimpleExpressionPool.java,v 1.44 2005/07/17 16:31:49 jmettraux Exp $ </font> * * @author jmettraux@openwfe.org */public class SimpleExpressionPool    extends AbstractService    implements ExpressionPool{    private final static org.apache.log4j.Logger log = org.apache.log4j.Logger        .getLogger(SimpleExpressionPool.class.getName());    //    // INNER CLASSES    //    // CONSTANTS    //    // FIELDS    private ExpressionStore store = null;    private java.util.TimerTask timerTask = null;    private java.util.TimerTask purgeTask = null;    //    // CONSTRUCTORS    public void init         (final String serviceName,          final ApplicationContext context,          final java.util.Map serviceParams)    throws         ServiceException    {        super.init(serviceName, context, serviceParams);        //        // determine purge frequency and start purge daemon        String sPurgeFrequency = MapUtils.getAsString            (getParams(), PURGE_FREQUENCY, DEFAULT_PURGE_FREQUENCY);        long purgeFrequency = Time.parseTimeString(sPurgeFrequency);                this.purgeTask = new java.util.TimerTask()        {            public void run ()            {                try                {                    purge();                }                catch (final Throwable t)                {                    log.warn("purgeTask : problem", t);                }            }        };        Application.getTimer().schedule            (this.purgeTask,             10 * 1000,  // start after 10s             purgeFrequency);        log.info("started purge daemon every '"+sPurgeFrequency+"'");        //        // determine whenCheck freq and start whenCheck daemon        String sTimerFrequency = (String)serviceParams.get(TIMER_FREQUENCY);        if (sTimerFrequency == null)            sTimerFrequency = (String)serviceParams.get(WHEN_FREQUENCY);        if (sTimerFrequency == null)            sTimerFrequency = DEFAULT_TIMER_FREQUENCY;        long timerFrequency = Time.parseTimeString(sTimerFrequency);        this.timerTask = new java.util.TimerTask()        {             public void run ()             {                 try                 {                    checkExpressionsWithTimer();                 }                 catch (final Throwable t)                 {                     log.warn("timerTask : problem", t);                 }             }        };        Application.getTimer().schedule            (this.timerTask,             15 * 1000,  // start after 15s             timerFrequency);        log.info("started timer daemon every '"+sTimerFrequency+"'");        //        // display OpenWFE version in logs                log.info("OpenWFE version : "+Definitions.OPENWFE_VERSION);    }    //    // METHODS    public void stop ()        throws ServiceException    {        super.stop();        this.timerTask.cancel();        log.info("TimerDaemon stopped.");        this.purgeTask.cancel();        log.info("PurgeDaemon stopped.");        log.info("Service '"+getName()+"' stopped.");    }    /**     * Usually called by WorkflowInstanceBuilders to add a freshly created     * expression to the pool.     */    public void add (final FlowExpression fe)        throws PoolException    {        fe.setApplicationContext(getContext());        //        // then store it on the disk                getStore().storeExpression(fe);    }    /**     * Stores the flow expression (as it may have changed).     */    public void update (final FlowExpression fe)        throws PoolException    {        getStore().storeExpression(fe);    }    /**     * Retrieves an expression from the pool.     * If the expression cannot be retrieved from the pool, null will be     * returned.     */    public FlowExpression fetch (final FlowExpressionId fei)    {        //log.debug("fetch()");        FlowExpression result = null;        try        {            result = getStore().loadExpression(fei);            //log.debug("fetch() expression got loaded");            //result.setApplicationContext(getContext());                //                 // done by the store        }        catch (PoolException pe)        {            log.info("fetch() Failed to retrieve expression "+fei, pe);            return null;        }        return result;    }    /**     * Returns the Ur-Expression : an expression unique to the engine, its      * only task (as of 1.5.1) is to hold variables global to all workflow     * instances.     */    public FlowExpression fetchUrExpression ()    {        final FlowExpression ur = getStore().loadUrExpression();        ur.setApplicationContext(this.getContext());        return ur;    }    /**     * given an id, returns the root expression of the flow     */    public FlowExpression fetchRootOfFlow (final FlowExpressionId fei)    {        final FlowExpression fe = fetch(fei);        final FlowExpressionId parentId = fe.getParent();        if (parentId == null) return fe;        return fetchRootOfFlow(parentId);    }    protected void log         (final FlowExpressionId fei,          final WorkItem wi,         final String eventCode,          final String message)    {        final History history = Definitions.getHistory(getContext());        log.debug(""+fei+" :: "+eventCode+" :: "+message);        if (history == null) return;        history.log(fei, wi, eventCode, null, message);            // participantName is set to null    }    /**     * Applies an expression.      * This method is usually called by expressions on their subexpressions or     * by a launchListener on a rootExpression of a workflow just instantiated.     */    public void apply         (final FlowExpressionId fei, final InFlowWorkItem wi)    throws         ApplyException    {        final FlowExpression fe = fetch(fei);        if (fe == null)        {            log.warn                ("Failed to find expression  "+fei+"  cannot apply it.");            throw new ApplyException                ("Failed to find expression  "+fei+"  cannot apply it.");        }        log(fei, wi, History.EVT_DEBUG, "applying");        fe.tag(wi);        fe.touchApplyTime();        log.debug("apply() tagged wi to "+wi.getLastExpressionId());        getState(fe).apply(wi);    }    /**     * A shortcut to      * apply (workflowInstanceId, flowExpressionId, inFlowWorkItem)     */    public void apply        (final FlowExpression fe, final InFlowWorkItem wi)    throws         ApplyException    {        this.apply(fe.getId(), wi);    }    /**     * Replies to the parent of the given flow expression, with the given      * workitem.     */    public void replyToParent        (final FlowExpression fe,          final InFlowWorkItem wi)    throws         ReplyException    {        if (fe.getNext() != null)        {            try            {                this.apply(fe.getNext(), wi);            }            catch (final ApplyException ae)            {                throw new ReplyException                    ("Failed to apply next "+fe.getNext(), ae);            }            this.removeExpression(fe);            return;        }        //        // end of a flow        if (fe.getParent() == null)        {            //log.debug("replyToParent() no parent, end of flow at "+fe.getId());            String message = "";            if (fe.getId().isInSubFlow()) message = "sub";            log(fe.getId(), wi, History.EVT_FLOW_END, "");            this.removeExpression(fe);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -