同步父子进程
本主题提供了这样一个示例,即“同步”自动机节点监听生成了父工作流进程的事件的活动状态的更改。
参考工作流
SynchronizationOnParentChildProcess.xml
SynchronizeChildProcess.xml
说明
下列表达式供监听由已分配活动节点激发的 ACTIVITY_STATE_CHANGED 事件的自动机使用。该表达式审查激发事件的活动是否属于产生自动机的父进程的进程。如果是,则根据该活动的状态激发相应的路由事件。
指示
本例中的自动机监听 ACTIVITY_STATE_CHANGED 事件,它监听的 Windchill 类是 wt.workflow.work.WfAssignedActivity。
本示例假定该自动机属于第一层级进程,即不存在于嵌套子进程中。自动机必须了解嵌套子进程的结构才能访问工作流模板中最外面的进程。
复制下列代码:
//Get the Activity that triggered the State_change event.
wt.workflow.engine.WfActivity activity = (( wt.workflow.engine.WfActivity ) (((wt.events.KeyedEvent)event).getEventTarget()));
//get the process that the Activity belongs to
wt.workflow.engine.WfProcess activityParentProcess = activity.getParentProcess();
//Get the Parent of that sub process
wt.fc.ObjectReference activityParentRef = activity.getParentProcessRef( );
//Get the parent process for the Synch Robot
wt.workflow.engine.WfProcess mySubProcess = ( wt.workflow.engine.WfProcess ) self.getObject( );
/Get the parent process that spawns this sub process
wt.workflow.engine.WfActivity myRequestorActivity = (( wt.workflow.engine.WfActivity ) mySubProcess.getRequester( ));
wt.workflow.engine.WfProcess myParentProcess = myRequestorActivity.getParentProcess( );
//Check if the parent of the activity and the parent process of the subprocess that the Synch robot belongs to are the same.
if ( wt.fc.PersistenceHelper.isEquivalent(activityParentProcess , myParentProcess )){
//If the state of the Activity in the ParentProcess is executed, set result to "completed" and ifterminated, set result to "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";
}
}
这对您有帮助吗?