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

📄 participantexpression.java

📁 一个工作流设计及定义的系统,可以直接与数据库结合进行系统工作流程的定义及应用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // log        this.historyLog            (wi,              History.EVT_DISPATCH,              participantName,              this.getClass().getName());    }    /**     * Initiates the dispatching mechanism.     */    protected void regularDispatch (final InFlowWorkItem wi)    {        String pName = null;        try        {            final Participant p = lookupParticipant(wi);            pName = getParticipantName(wi);            dispatch(p, pName, wi);            return;        }        catch (final Throwable t)        {            log.debug                ("regularDispatch() failed to dispatch to '"+                 pName+"'", t);            log.warn                ("regularDispatch() failed to dispatch to '"+                 pName+"'\n"+t);        }        elseDispatch(wi);    }    /**     * Is called by regularDispatch() in case of failure. Freezes the      * expression if it itself fails.     */    protected void elseDispatch (final InFlowWorkItem wi)    {        final String sElseList = lookupAttribute(ELSE_REF, wi);        if (sElseList != null)        {            String[] ss = sElseList.split(",");            for (int i=0; i<ss.length; i++)            {                final String pName = ss[i].trim();                if (pName.equals("")) continue;                    //                    // eliminating blanks "a, ,c"                final Participant p = getParticipantMap().get(pName);                if (p == null)                 {                    log.debug                        ("elseDispatch() unknown participant '"+pName+                         "', continuing.");                    continue;                }                try                {                    dispatch(p, pName, wi);                }                catch (final Throwable t)                {                    //log.debug                    //    ("elseDispatch() failed to dispatch to '"+                    //     pName+"'", t);                    log.warn                        ("elseDispatch() failed to dispatch to '"+                         pName+"' "+t+", continuing...");                }                // success (as it seems...)                //log.debug("elseDispatch() delivered to '"+pName+"'");                return;            }        }        log.debug("elseDispatch() freezing self : "+getId());        FrozenState frozenState = new FrozenState();        frozenState.setAppliedItem(wi);        this.setState(frozenState);        this.storeItself();    }    /**     * This method is called by the expression pool with the workitem coming     * back from the participant.     * If the participant expression has a filter attached to it, it will be     * enforced.     */    public void reply (InFlowWorkItem wi)        throws ReplyException    {        //        // ensure that the workitem has been modified        // in a way authorized by the filter        //        if (this.filter != null)            wi = this.filter.enforce(this.appliedWorkitem, wi);        //        // add a history item to the history                addHistoryItem(wi);        //        // unset description field                if (this.description != null)        {            if (this.oldDescriptionValue != null)            {                wi.getAttributes()                    .put(DESCRIPTION_FIELD_NAME, this.oldDescriptionValue);            }            else            {                wi.getAttributes()                    .remove(DESCRIPTION_FIELD_NAME);            }        }        //        // unset timedOut variable (if any)        getExpressionPool()            .setVariableInParent(this, Definitions.V_TIMED_OUT, null);        //        // then reply        super.reply(wi);    }    /**     * Adds a 'participant' history item to the workitem.     */    protected void addHistoryItem (final InFlowWorkItem wi)    {        if (wi.getHistory() == null)             wi.setHistory(new java.util.ArrayList(1));        final HistoryItem hi = new HistoryItem(getId());        try        {            hi.setAuthor("participant::"+getParticipantName(wi));        }        catch (ApplyException ae)        {            hi.setAuthor("participant::unknown");        }        try        {            java.net.InetAddress add = java.net.InetAddress.getLocalHost();            hi.setHost(add.getHostName()+" / "+add.getHostAddress());        }        catch (java.net.UnknownHostException uhe)        {            hi.setHost(""+uhe);        }        hi.setText(HISTORY_TEXT);        wi.getHistory().add(hi);        //log.debug("addHistoryItem() did it");    }    /**     * sends a cancel item to the participant     */    public InFlowWorkItem cancel ()        throws ApplyException    {        super.cancel();        //        // A 'null' value is used when looking up a participant, usually        // the participant is already known and thus doesn't need a workitem        // for determination.        //        log.debug("cancel() --> "+getId());        final Participant participant =             lookupParticipant(this.appliedWorkitem);        final CancelItem ci = new CancelItem            (getId(), getParticipantName(this.appliedWorkitem));        try        {            participant.dispatch(ci);            log.debug("cancel() cancelItem dispatched");        }        catch (DispatchingException de)        {            throw new ApplyException                ("Failed to notify participant '"+                 getParticipantName(this.appliedWorkitem)+                 "' with cancel item", de);        }        return this.appliedWorkitem;    }    /*     * cloning the filter is not necessary so this method override     * is not necessary anymore.     *    public Object clone ()    {        final ParticipantExpression clone =             (ParticipantExpression)super.clone();        clone.setFilter(getFilter());        return clone;    }     */    //    // METHODS from ExpressionWithTimeOut    /**     * This method should return false if the purge daemon should not     * consider the implemented and instantiated Expression during its run.     */    public boolean isTimeOutActivated ()    {        if (getApplyTime() == null  ||             (this.getState() instanceof FrozenState))        {            return false;        }        return (determineTimeOut() != -1);    }    /**     * This method is called by the ExpressionStore when it notices that the     * ParticipantExpression expired.     */    public void timeOutReply ()        throws ReplyException    {        //        // tagging the workitem with timeout history...                String participantName = "unknown";        try        {            participantName = getParticipantName(this.appliedWorkitem);        }        catch (ApplyException ae)        {            // leave to 'unknown'        }                this.appliedWorkitem.addHistoryItem            (participantName, "participant timed out");                //        // log timeout in history        historyLog            (this.appliedWorkitem, EVT_TIMED_OUT, participantName, "");        //log.debug("this.dispatchedWorkItem = "+this.dispatchedWorkItem);        log.debug("setting '"+Definitions.V_TIMED_OUT+"' to 'true'");        //resolveParent().setVariable         //    (Definitions.V_TIMED_OUT, Boolean.TRUE);        getExpressionPool().setVariableInParent            (this, Definitions.V_TIMED_OUT, Boolean.TRUE);        log.debug("timeOutReply() cancelling self...");        try        {            this.cancel();        }        catch (ApplyException ae)        {            log.debug                ("Failed to send cancel message", ae);            throw new ReplyException                ("Failed to send cancel message", ae);        }        //        // resume flow                log.debug("timeOutReply() resuming flow");        super.reply(this.appliedWorkitem);    }    private long determineTimeOut (final String sTimeOut)    {        if (sTimeOut.equals("no") || sTimeOut.equals("-1")) return -1;        return Time.parseTimeString(sTimeOut);    }    /**     * by implementing this method, expressions define how their     * timeout is determined.     * For example, the priority of the timeout setting for a     * Participant expression is :<br>     * <ol>     *   <li>expression</li>     *   <li>participant</li>     *   <li>applicationContext</li>     * </ol>     * So this behaviour is implemented in ParticipantExpression's      * determineTimeOut method.     */    public long determineTimeOut ()    {        long timeOut = -2;        /*        //        // determine time out at engine level                timeOut = this.applicationContext            .getTime(ExpressionPool.DEFAULT_EXPRESSION_TIMEOUT);        */                //        // determine time out at participant level                Participant participant = null;        try        {            participant = this.lookupParticipant(this.appliedWorkitem);        }        catch (ApplyException ae)        {            log.info                ("Couldn't determine participant for timeout computation", ae);        }        if (participant != null)        {            final String sTimeOut =                 (String)participant.getParams().get(TIMEOUT);            if (sTimeOut != null) timeOut = determineTimeOut(sTimeOut);        }        //        // determine time out at expression level (highest priority)        final String sTimeOut = this.getAttributeValue(TIMEOUT);        if (sTimeOut != null) timeOut = determineTimeOut(sTimeOut);        //        // return        if (timeOut < -1)            timeOut = ExpressionPool.DEFAULT_EXPRESSION_TIMEOUT_VALUE;        // NB : returning a timeout of "-1" means timeout is deactivated         //      for the participant                return timeOut;    }}

⌨️ 快捷键说明

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