在osworkflow中,Trigger Function是通过Quartz来实现的,我们看看
LocalWorkflowJob.java的实现代码:
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//JobDataMap是在schedule开始前放入的
JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
//entryId是工作流实例号
long id = data.getLong("entryId");
//在流程定义中定义的trigger的id
int triggerId = data.getInt("triggerId");
String username = data.getString("username");
Workflow wf = new BasicWorkflow(username);
try {
//执行真正的trigger
wf.executeTriggerFunction(id, triggerId);
} catch (WorkflowException e) {
//this cast is a fairly horrible hack, but it's more due to the fact that quartz is stupid enough to have wrapped exceptions
//wrap Exception, instead of Throwable.
throw new JobExecutionException("Error Executing local job", (e.getRootCause() != null) ? (Exception) e.getRootCause() : e, true);
}
}
其实,我们在自己的工作流引擎或者系统中,还可以用Quartz实现更多的功能.
比如,我们有需求是要为流程或者活动指定时间限制,到该时间限制前10分钟
要向任务执行者告警,那么我们可以这样实现:
在服务器启动时启动scheduler,然后每1分钟,计算引擎中的流程实例还剩下的
时间,这个时间不需要持久化,直接记录在内存中,可以由引擎的其它部分读取.