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

📄 asynctimerandsubprocessdbtest.java

📁 jbpm demo 是一款非常不错的开源工作流,简单易用,适合扩张开发!
💻 JAVA
字号:
package org.jbpm.scenarios;

import java.util.List;

import org.jbpm.context.exe.ContextInstance;
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.jbpm.graph.node.DecisionHandler;
import org.jbpm.msg.command.CommandExecutorThread;
import org.jbpm.scheduler.impl.SchedulerThread;
import org.jbpm.taskmgmt.exe.TaskInstance;

public class AsyncTimerAndSubProcessDbTest extends AbstractDbTestCase {
  
  public static class ToTimedDecisionHandler implements DecisionHandler {
    private static final long serialVersionUID = 1L;
    public String decide(ExecutionContext executionContext) throws Exception {
      return "default";
    }
  }

  public void testTimerInCombinationWithAsyncNode() throws Throwable {
    ProcessDefinition subDefinition = ProcessDefinition.parseXmlString(
      "<process-definition name='sub'>" +
      "  <start-state name='start'>" +
      "    <transition to='decision'/>" +
      "  </start-state>" +
      "  <decision name='decision'>" +
      "    <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />" +
      "    <transition name='default' to='task' />" +
      "  </decision>" +
      "  <task-node name='task'>" +
      "    <task name='do stuff'>" +
      "      <controller>" +
      "        <variable name='a' access='read' />" +
      "      </controller>" +
      "      <assignment actor-id='victim' />" +
      "    </task>" +
      "    <transition to='end'/>" +
      "  </task-node>" +
      "  <end-state name='end' />" +
      "</process-definition>"
    );
    jbpmContext.deployProcessDefinition(subDefinition);
    newTransaction();
    
    ProcessDefinition superDefinition = ProcessDefinition.parseXmlString(
      "<process-definition name='super'>" +
      "  <start-state name='start'>" +
      "    <transition to='decision'/>" +
      "  </start-state>" +
      "  <decision name='decision'>" +
      "    <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />" +
      "    <transition name='default' to='timed' />" +
      "  </decision>" +
      "  <state name='timed'>" +
      "    <timer name='reminder' " +
      "           duedate='0 seconds' " +
      "           transition='timer fires' />" +
      "    <transition name='timer fires' to='async'/>" +
      "    <transition name='normal continuation' to='end'/>" +
      "  </state>" +
      "  <node name='async' async='true'>" +
      "    <transition to='subprocess'/>" +
      "  </node>" +
      "  <process-state name='subprocess'>" +
      "    <sub-process name='sub' />" +
      "    <variable name='a'/>" +
      "    <variable name='b'/>" +
      "    <transition to='decision' />" +
      "  </process-state>" +
      "  <end-state name='end' />" +
      "</process-definition>"
    );
    jbpmContext.deployProcessDefinition(superDefinition);
    newTransaction();
    
    ProcessInstance superInstance = jbpmContext.newProcessInstanceForUpdate("super");
    ContextInstance superContext = superInstance.getContextInstance();
    superContext.setVariable("a", "value a");
    superContext.setVariable("b", "value b");
    superInstance.signal();
    
    commitAndCloseSession();
    try {
      SchedulerThread schedulerThread = new SchedulerThread(jbpmConfiguration);
      schedulerThread.executeTimers();
    } finally {
      beginSessionTransaction();
    }

    superInstance = jbpmContext.loadProcessInstance(superInstance.getId());
    assertEquals("async", superInstance.getRootToken().getNode().getName());
    
    commitAndCloseSession();
    try {
      CommandExecutorThread commandExecutorThread = new CommandExecutorThread(jbpmConfiguration);
      commandExecutorThread.executeCommand();
    } finally {
      beginSessionTransaction();
    }

    List taskInstances = taskMgmtSession.findTaskInstances("victim");
    assertEquals(1, taskInstances.size());
    TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
    taskInstance.setVariable("a", "value a updated");
    taskInstance.setVariable("b", "value b updated");
    taskInstance.end();
    
    jbpmContext.save(taskInstance);
    long taskInstanceId = taskInstance.getId();
    long tokenId = taskInstance.getToken().getId();
    newTransaction();
    
    taskInstance = jbpmContext.loadTaskInstance(taskInstanceId);
    assertEquals("value a updated", taskInstance.getVariable("a"));
    assertEquals("value b updated", taskInstance.getVariable("b"));
    
    Token token = jbpmContext.loadToken(tokenId);
    ContextInstance subContextInstance = token.getProcessInstance().getContextInstance();
    assertEquals("value a", subContextInstance.getVariable("a"));
    assertEquals("value b updated", subContextInstance.getVariable("b"));
  }
}

⌨️ 快捷键说明

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