Package org.fireflow.kernel.event

Examples of org.fireflow.kernel.event.NodeInstanceEvent


      IJoinPoint joinPoint = null;
        synchronized (this) {
            tk.setNodeId(this.getSynchronizer().getId());
            log.debug("The weight of the Entering TransitionInstance is " + tk.getValue());
            // 触发TokenEntered事件
            NodeInstanceEvent event1 = new NodeInstanceEvent(this);
            event1.setToken(tk);
            event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED);
            fireNodeEvent(event1);

            //汇聚检查
            joinPoint = ((ProcessInstance) tk.getProcessInstance()).createJoinPoint(this, tk);// JoinPoint由谁生成比较好?
            int value = joinPoint.getValue();

            log.debug("The volume of " + this.toString() + " is " + volume);
            log.debug("The value of " + this.toString() + " is " + value);
            if (value > volume) {
                KernelException exception = new KernelException(tk.getProcessInstance(),
                        this.getSynchronizer(),
                        "Error:The token count of the synchronizer-instance can NOT be  greater than  it's volumn  ");
                throw exception;
            }
            if (value < volume) {// 如果Value小于容量则继续等待其他弧的汇聚。
                return;
            }
        }

        IProcessInstance processInstance = tk.getProcessInstance();
        NodeInstanceEvent event2 = new NodeInstanceEvent(this);
        event2.setToken(tk);
        event2.setEventType(NodeInstanceEvent.NODEINSTANCE_FIRED);
        fireNodeEvent(event2);
       
        //在此事件监听器中,删除原有的token
        NodeInstanceEvent event4 = new NodeInstanceEvent(this);
        event4.setToken(tk);
        event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING);
        fireNodeEvent(event4);
       
        //首先必须检查是否有满足条件的循环
        boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。

        if (joinPoint.getAlive()) {
            IToken tokenForLoop = null;

                tokenForLoop = new Token(); // 产生新的token
                tokenForLoop.setAlive(joinPoint.getAlive());
                tokenForLoop.setProcessInstance(processInstance);
                tokenForLoop.setStepNumber(joinPoint.getStepNumber()-1);
                tokenForLoop.setFromActivityId(joinPoint.getFromActivityId());

            for (int i = 0; i < this.leavingLoopInstances.size(); i++) {
             
                ILoopInstance loopInstance = this.leavingLoopInstances.get(i);

                doLoop = loopInstance.take(tokenForLoop);
                if (doLoop) {
                    break;
                }
            }
        }

        if (!doLoop){
            NodeInstanceEvent event3 = new NodeInstanceEvent(this);
            event3.setToken(tk);
            event3.setEventType(NodeInstanceEvent.NODEINSTANCE_COMPLETED);
            fireNodeEvent(event3);
        }
       
//        NodeInstanceEvent event4 = new NodeInstanceEvent(this);
//        event4.setToken(tk);
View Full Code Here


        log.debug("The weight of the Entering TransitionInstance is " + tk.getValue());
        IToken token = tk;
        token.setNodeId(this.getActivity().getId());

        //触发TokenEntered事件
        NodeInstanceEvent event1 = new NodeInstanceEvent(this);
        event1.setToken(tk);
        event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED);//token 来了
        fireNodeEvent(event1);
        if (token.isAlive()) {//如果token是活动的,那么就保存token,并创建taskinstance
            NodeInstanceEvent event = new NodeInstanceEvent(this);
            event.setToken(token);
            event.setEventType(NodeInstanceEvent.NODEINSTANCE_FIRED);//token 被触发,创建taskinstance,等待
            fireNodeEvent(event);
        } else {//如果token是dead状态,那么就直接结束当前节点。
            this.complete(token, null);
        }
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.fireflow.kernel.IActivityInstance#complete(org.fireflow.kernel.IToken, org.fireflow.kernel.IActivityInstance)
     */
    public void complete(IToken token, IActivityInstance targetActivityInstance) throws KernelException {
        NodeInstanceEvent event2 = new NodeInstanceEvent(this);
        event2.setToken(token);
        event2.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING); //token leaving
        fireNodeEvent(event2);


        token.setFromActivityId(this.getActivity().getId());

        if (targetActivityInstance != null) {
            token.setStepNumber(token.getStepNumber() + 1);
            targetActivityInstance.fire(token);
        } else {
            //按照定义,activity有且只有一个输出弧,所以此处只进行一次循环。
            for (int i = 0; leavingTransitionInstances != null && i < leavingTransitionInstances.size(); i++) {
                ITransitionInstance transInst = leavingTransitionInstances.get(i);
                transInst.take(token);
            }
        }

        if (token.isAlive()) {
            NodeInstanceEvent event = new NodeInstanceEvent(this);
            event.setToken(token);
            event.setEventType(NodeInstanceEvent.NODEINSTANCE_COMPLETED); //token completed
            fireNodeEvent(event);
        }
    }
View Full Code Here

        IJoinPoint joinPoint = null;
        synchronized (this) { //流程同步器需要处理并发的情况,而activity的节点不需要处理并发情况?同步器节点,可能被同时触发,activity节点不会被同时触发?
            tk.setNodeId(this.getSynchronizer().getId());
            log.debug("The weight of the Entering TransitionInstance is " + tk.getValue());
            // 触发TokenEntered事件
            NodeInstanceEvent event1 = new NodeInstanceEvent(this);
            event1.setToken(tk);
            event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED);//token 进入
            fireNodeEvent(event1);

            //汇聚检查

            joinPoint = ((ProcessInstance) tk.getProcessInstance()).createJoinPoint(this, tk);// JoinPoint由谁生成比较好?
            int value = joinPoint.getValue();
            log.debug("The volume of " + this.toString() + " is " + volume);
            log.debug("The value of " + this.toString() + " is " + value);
            if (value > volume) {//如果value大于同步器容量,那说明出错了
                KernelException exception = new KernelException(tk.getProcessInstance(),
                        this.getSynchronizer(),
                        "Error:The token count of the synchronizer-instance can NOT be  greater than  it's volumn  ");
                throw exception;
            }
            if (value < volume) {// 如果Value小于容量则继续等待其他弧的汇聚。 (哪些状态为dead的token到此结束,不再向下传递)
                return
            }
        }
        //如果汇聚点的容量和同步器节点的容量相同
        IProcessInstance processInstance = tk.getProcessInstance();
        // Synchronize的fire条件应该只与joinPoint的value有关(value==volume),与alive无关
        NodeInstanceEvent event2 = new NodeInstanceEvent(this);
        event2.setToken(tk);
        event2.setEventType(NodeInstanceEvent.NODEINSTANCE_FIRED);
        fireNodeEvent(event2);

        //在此事件监听器中,删除原有的token
        NodeInstanceEvent event4 = new NodeInstanceEvent(this);
        event4.setToken(tk);
        event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING);
        fireNodeEvent(event4);

        //首先必须检查是否有满足条件的循环,loop比transition有更高的优先级,
        //(只能够有一个loop的条件为true,流程定义的时候需要注意)
        boolean doLoop = false;//表示是否有满足条件的循环,false表示没有,true表示有。
        if (joinPoint.getAlive()) {
            IToken tokenForLoop = new Token(); // 产生新的token
            tokenForLoop.setAlive(joinPoint.getAlive());
            tokenForLoop.setProcessInstance(processInstance);
            tokenForLoop.setStepNumber(joinPoint.getStepNumber()-1);
            tokenForLoop.setFromActivityId(joinPoint.getFromActivityId());

            for (int i = 0; i < this.leavingLoopInstances.size(); i++) {
                ILoopInstance loopInstance = this.leavingLoopInstances.get(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.size(); i++) {
                    ITransitionInstance transInst = leavingTransitionInstances.get(i);
                    String condition = transInst.getTransition().getCondition();
                    if (condition != null && condition.equals(ConditionConstant.DEFAULT)) {
                        defaultTransInst = transInst;
                        continue;
                    }

                    Token token = new Token(); // 产生新的token
                    token.setAlive(joinPoint.getAlive());
                    token.setProcessInstance(processInstance);
                    token.setStepNumber(joinPoint.getStepNumber());
                    token.setFromActivityId(joinPoint.getFromActivityId());
                    boolean alive = transInst.take(token);
                    if (alive) {
                        activiateDefaultCondition = false;
                    }

                }
                if (defaultTransInst != null) {
                    Token token = new Token();
                    token.setAlive(activiateDefaultCondition && joinPoint.getAlive());
                    token.setProcessInstance(processInstance);
                    token.setStepNumber(joinPoint.getStepNumber());
                    token.setFromActivityId(joinPoint.getFromActivityId())
                    defaultTransInst.take(token);
                }
           
        }

        NodeInstanceEvent event3 = new NodeInstanceEvent(this);
        event3.setToken(tk);
        event3.setEventType(NodeInstanceEvent.NODEINSTANCE_COMPLETED); //触发同步器节点的监听事件,删除所有和同步器节点相关的token
        fireNodeEvent(event3);
    }
View Full Code Here

        tk.setNodeId(this.getSynchronizer().getId());//到开始节点(同步器)

        IProcessInstance processInstance = tk.getProcessInstance();//从token中获得流程实例对象

        //触发token_entered事件
        NodeInstanceEvent event1 = new NodeInstanceEvent(this);
        event1.setToken(tk);
        event1.setEventType(NodeInstanceEvent.NODEINSTANCE_TOKEN_ENTERED); //token进入
        fireNodeEvent(event1);

        //触发fired事件
        NodeInstanceEvent event2 = new NodeInstanceEvent(this);
        event2.setToken(tk);
        event2.setEventType(NodeInstanceEvent.NODEINSTANCE_FIRED);//token 触发
        fireNodeEvent(event2);

        //触发leaving事件
        NodeInstanceEvent event4 = new NodeInstanceEvent(this);
        event4.setToken(tk);
        event4.setEventType(NodeInstanceEvent.NODEINSTANCE_LEAVING); //token 离开
        fireNodeEvent(event4);


        boolean activateDefaultCondition = true;//激活默认弧线的标志
        ITransitionInstance defaultTransInst = null;
        //找到所有开始节点的输出弧
        for (int i = 0; leavingTransitionInstances != null && i < leavingTransitionInstances.size(); i++) {
            ITransitionInstance transInst = leavingTransitionInstances.get(i); //开始节点的边的类型只能是transition
            String condition = transInst.getTransition().getCondition();
            //如果弧线的条件!=null 并且 =“default” ,那么弧线实例就是default的弧线了。
            if (condition != null && condition.equals(ConditionConstant.DEFAULT)) {
                defaultTransInst = transInst;//记录default转移线,其他条件都未false,才执行它
                continue;
            }

            Token token = new Token(); // 产生新的token
            token.setAlive(true);
            token.setProcessInstance(processInstance);
            token.setFromActivityId(tk.getFromActivityId());
            token.setStepNumber(tk.getStepNumber()+1); //步骤号+1
           
           
            boolean alive = transInst.take(token);//触发弧线的token
            if (alive) {
                activateDefaultCondition = false;
            }

        }
        if (defaultTransInst != null) {//如果defaultTransInst!=null ,走的是default值的弧线
            Token token = new Token();
            token.setAlive(activateDefaultCondition);//设置token为dead
            token.setProcessInstance(processInstance);
            token.setFromActivityId(token.getFromActivityId());
            token.setStepNumber(tk.getStepNumber()+1);
            defaultTransInst.take(token);
        }


        //触发completed事件
        NodeInstanceEvent event3 = new NodeInstanceEvent(this);
        event3.setToken(tk);
        event3.setEventType(NodeInstanceEvent.NODEINSTANCE_COMPLETED);
        fireNodeEvent(event3);
    }
View Full Code Here

TOP

Related Classes of org.fireflow.kernel.event.NodeInstanceEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.