Shark工作流的实现和WMFC&OMG规范的对比
-----第九部分:分析obe自带例子的执行过程
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
关键字:Shark 工作流 WMFC OMG 规范
Obe工作流的执行过程,下面来说说自带test中的例子的执行过程:
初始化工作流引擎的时候需要一个RepositoryManager 的实例
RepositoryManager 代表工作流执行中需要的资源库,比如:活动的参与者,活动中需要调用的外部工具信息,等等。然后进行工作流引擎的初始化:
WorkflowEngine engine = new WorkflowEngine(repositoryManager);
引擎初始化后用obe的xpdl解析类从用户定义的xpdl流程中实例化Package。
XPDLParser parser = new Dom4JXPDLParser();
FileInputStream in = new FileInputStream(file);
Package pkg = null;
try{
pkg = parser.parse(in);
} catch(Exception e){
log.fatal("Error parsing configuration: " + e.getMessage());
e.printStackTrace();
return;
}
然后把初始化后的package加入到引擎实例中:
engine.addPackage(pkg);
随后就执行了:
try{
log.info("Executing workflow process " + packageId + ":" + processId);
if(executionMode.equalsIgnoreCase("asynch")){
log.info("Executing asynchronously");
engine.executeAsynch(packageId, processId, getParameters());
} else {
log.info("Executing synchronously");
engine.executeSynch(packageId, processId, getParameters());
}
} catch(Exception e){
log.error("Error executing workflow process " + processId + " in package " + packageId);
e.printStackTrace();
}
。
看起来整个执行流程很简单。
上面提到的RepositoryManager是如何初始化的呢?
例子中带的资源库有如下类型:
1、 BasicApplicationRepository
2、 BasicProcedureRepository
3、 BasicParticipantRepository
其中BasicParticipantRepository下面又包括:
1)RoundRobinGroup
2)WorkflowSystem
比如:添加管理和编辑人员信息:
RoundRobinGroup editors = new RoundRobinGroup();
editors.add(new Human("Bob Smith"));
editors.add(new Human("Joe User"));
RoundRobinGroup administrators = new RoundRobinGroup();
administrators.add(new Human("Anthony Eden"));
WorkflowSystem system = new WorkflowSystem();
participantRepository.put("P1", editors);
participantRepository.put("P2", administrators);
participantRepository.put("P3", system);
participantRepository.setDefaultConnector(system);
getParticipantRepositories().add(participantRepository);
BasicApplicationRepository appRepository = new BasicApplicationRepository();
appRepository.put("A1", new DebugApplicationConnector("App 1"));
appRepository.put("A2", new DebugApplicationConnector("App 2"));
appRepository.put("A3", new RuntimeApplicationConnector(TEST_EXE,
ExecutionType.SYNCHRONOUS));
appRepository.put("A4", new DebugApplicationConnector("App 4", 10000));
appRepository.put("A5", new DebugApplicationConnector("App 5"));
getApplicationRepositories().add(appRepository);
下面 我们根据obe提供的例子结合引擎分析 obe引擎的执行过程。
Shark工作流的实现和WMFC&OMG规范的对比
-----第十部分:分析obe自带例子引擎的执行过程
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
关键字:Shark 工作流 WMFC OMG 规范
下面工作流执行的过程参见:-----第五部分:工作流流程的设计
下面是采用obe引擎执行第五部分定义的“辞职申请”的过程的日志。
[INFO]: Loading applications in package pkg
-1...
[INFO]: 0 applications loaded
org.obe.util.Duration [INFO]: Duration(0, null)
[INFO]: Created workflow process [id=wfp-1,name= 人员辞职流程]
[INFO]: Redefinable header not found
[INFO]: Created activity [id=提交辞职申请,name=提交辞职申请]
[INFO]: Loading extended attributes
[INFO]: Created activity [id=部门经理批准,name=部门经理批准]
[INFO]: Loading extended attributes
[INFO]: Created activity [id=总经理批准,name=总经理批准]
[INFO]: Loading extended attributes
[INFO]: Created activity [id= 部门经理复查,name=部门经理复查]
[INFO]: Loading extended attributes
[INFO]: Created activity [id= 财务审查,name=财务审查]
[INFO]: Loading extended attributes
[INFO]: Created activity [id= 人力资源审查,name=人力资源审查]
[INFO]: Loading extended attributes
[INFO]: 6 activities loaded
[INFO]: Loading transitions in process wfp-1...
[DEBUG]: Transition 3cb3f6d1-56c6-11d8-8fe6-8f02bbfa91d7 loop type: null
[INFO]: Loading extended attributes
[INFO]: 6 transitions loaded
[INFO]: Loading extended attributes
org.obe.util.Duration [INFO]: Duration(0, null)
[INFO]: Created workflow process [id=782fc727-56c6-11d8-8fe6-8f02bbfa91d7,name=财务审查]
org.obe.test.OBETest [INFO]: Executing workflow process pkg-1:wfp-1
org.obe.test.OBETest [INFO]: Executing synchronously
org.obe.engine.WorkflowEngine [INFO]: Created date: Wed Feb 04 11:54:55 CST 2004
org.obe.engine.WorkflowProcessInstance [INFO]: Starting process 1
org.obe.engine.WorkflowProcessInstance [INFO]: Start activity: 提交辞职申请
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 提交辞职申请
org.obe.engine.WorkflowProcessInstance [INFO]: Executing incoming transitions fo
r 部门经理批准
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 部门经理批准
org.obe.engine.WorkflowProcessInstance [DEBUG]: Transition loop type: NOLOOP
org.obe.engine.WorkflowProcessInstance [INFO]: Executing outgoing transitions fo
r 部门经理批准
org.obe.engine.WorkflowProcessInstance [DEBUG]: Looping through transition restr
ictions [size=0]
org.obe.engine.WorkflowProcessInstance [DEBUG]: 2 transitions, executing AND spl
it (default)
org.obe.engine.WorkflowProcessInstance [INFO]: findCurrentThreadReference(PID-1)
org.obe.engine.WorkflowProcessInstance [INFO]: Current thread: Thread[PID-1,5,ma
in]
org.obe.engine.WorkflowProcessInstance [INFO]: AND split; execute in new thread
org.obe.engine.WorkflowProcessInstance [INFO]: AND split; execute in new thread
org.obe.engine.WorkflowProcessInstance [INFO]: ThreadReference parent child coun
t: 2
org.obe.engine.WorkflowProcessInstance [INFO]: Workflow completed
org.obe.engine.WorkflowEngine [INFO]: Returning from executeSynch()
org.obe.engine.WorkflowProcessInstance [INFO]: Executing incoming transitions fo
r 财务审查
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 财务审查
org.obe.engine.workitem.SubFlowWorkItem [INFO]: Executing sub flow in synchronou
s mode
org.obe.engine.WorkflowEngine [INFO]: Created date: Wed Feb 04 11:58:47 CST 2004
org.obe.engine.WorkflowProcessInstance [INFO]: Starting process 2
org.obe.engine.WorkflowProcessInstance [INFO]: Executing incoming transitions fo
r 人力资源审查
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 人力资源审查
org.obe.engine.workitem.SubFlowWorkItem [INFO]: Executing sub flow in synchronou
s mode
org.obe.engine.WorkflowEngine [INFO]: Created date: Wed Feb 04 11:59:06 CST 2004
org.obe.engine.WorkflowProcessInstance [INFO]: Starting process 3
org.obe.engine.WorkflowProcessInstance [DEBUG]: Loading workflow relevant data f
rom package
org.obe.engine.WorkflowProcessInstance [DEBUG]: Loading workflow relevant data f
rom parameters
org.obe.engine.util.ContextUtilities [INFO]: Formal parameters size: 0
[DEBUG]:org.formproc.Form - Validating groups
org.obe.engine.WorkflowProcessInstance [INFO]: Returning from workflow process:
no activities
org.obe.engine.WorkflowEngine [INFO]: Returning from executeSynch()
org.obe.engine.WorkflowProcessInstance [DEBUG]: Transition loop type: NOLOOP
org.obe.engine.WorkflowProcessInstance [INFO]: Executing outgoing transitions fo
r 财务审查
org.obe.engine.WorkflowProcessInstance [DEBUG]: Looping through transition restr
ictions [size=0]
org.obe.engine.WorkflowProcessInstance [DEBUG]: Executing single outgoing transi
tion
org.obe.engine.WorkflowProcessInstance [INFO]: Executing incoming transitions fo
r 部门经理复查
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 部门经理复查
org.obe.engine.WorkflowProcessInstance [INFO]: Executing loop: WHILE
org.obe.engine.WorkflowProcessInstance [DEBUG]: Loading workflow relevant data f
rom package
org.obe.engine.WorkflowProcessInstance [DEBUG]: Loading workflow relevant data f
rom parameters
org.obe.engine.util.ContextUtilities [INFO]: Formal parameters size: 0
[DEBUG]:org.formproc.Form - Validating groups
org.obe.engine.WorkflowProcessInstance [INFO]: Returning from workflow process:
no activities
org.obe.engine.WorkflowEngine [INFO]: Returning from executeSynch()
org.obe.engine.WorkflowProcessInstance [DEBUG]: Transition loop type: NOLOOP
org.obe.engine.WorkflowProcessInstance [INFO]: Executing outgoing transitions fo
r 人力资源审查
org.obe.engine.WorkflowProcessInstance [DEBUG]: Looping through transition restr
ictions [size=0]
org.obe.engine.WorkflowProcessInstance [DEBUG]: Executing single outgoing transi
tion
org.obe.engine.WorkflowProcessInstance [INFO]: Executing incoming transitions fo
r 部门经理复查
org.obe.engine.WorkflowProcessInstance [INFO]: Executing activity 部门经理复查
E:/my/workflow/doc/obetest-1.0b2/obetest-1.0b2>pause
请按任意键继续 . . .
从上面的执行可以看出:
org.obe.engine.WorkflowProcessInstance
org.obe.engine.WorkflowEngine
这两个类执行了关键的工作流程部分,是obe具体执行的主体部分。
org.obe.engine.WorkflowProcessInstance 中主要的方法包括:
1、 startProcess
2、 stopProcess
3、 resumeProcess
4、 pauseProcess
等
可见,obe中主要的工作是在WorkflowProcessInstance中执行的。
下文主要分析
org.obe.engine.WorkflowProcessInstance
org.obe.engine.WorkflowEngine
两个类的执行原理。