在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分鐘,計算引擎中的流程執行個體還剩下的
時間,這個時間不需要持久化,直接記錄在記憶體中,可以由引擎的其它部分讀取.