基础管理 > 支持协作 > 工作流管理 > 工作流工具 > 工作流模板管理 > 工作流代码示例 > 同步自动机示例 > 同步独立进程
  
同步独立进程
本主题提供了这样一个示例,即“同步”自动机节点暂停进程,直到独立工作流进程中的活动节点达到某一状态为止。
参考工作流
SynchronizationOfIndependentProcesses.xml
SynchronizeIndependentProcess.xml
说明
“同步”自动机节点可以暂停工作流进程的进度,直到独立工作流进程中的活动达到某一状态时为止。下面的代码可以用作这种自动机的表达式。要监听的类是 wt.workflow.work.WfAssignedActivity,要监听的事件是 ACTIVITY_STATE_CHANGED。自动机检查触发此事件的活动及其父进程是否与为自动机提供的活动及进程相同,如果相同,则根据该活动的状态进行路由。要确定该活动的父工作流模板,自动机必须知道该活动及其父工作流模板的名称。这可能是自动机所属进程中的一个变量。
指示
activityName 和 otherProcessName 代表工作流模板中的变量,它们的字符串值代表自动机正在监听的活动和进程的名称。
* 
可能有多个名称相同的进程。要使用此示例,需确保只有一个进程名为 "processName",或者具有此名称的所有进程均为同一工作流模板的实例。
复制下列代码:
//get the activity that emitted the event
wt.workflow.engine.WfActivity activity = ( wt.workflow.engine.WfActivity ) ((wt.events.KeyedEvent) event).getEventTarget();
//Check if this activity is the same as the one we are interested in
if (activity.getName().equals(activityName)) {
//Get the parent process of the activity.
wt.workflow.engine.WfProcess activityParent = activity.getParentProcess();
//Check if the parent process of the activity is the same one we are interested in.
if (( activityParent.getName( )). equals(otherProcessName )) {
//Set result to "completed" if the activity has been executed and to "terminated" if it has been terminated. Else check again.
if ( wt.workflow.engine.WfState.CLOSED_COMPLETED_EXECUTED.equals(activity.getState( ))){
result = "completed";
}
else if ( wt.workflow.engine.WfState.CLOSED_TERMINATED.equals(activity.getState( ))){
result = "terminated";
}
}
}