?

??????????????? ???? Work Flow 學習筆記

1.??? WfRequester

WfRequester is the interface that has a direct concern with the execution and results

of a workflow process - it represents the request for some work to be done. Its

performer, a WfProcess, is expected to handle its request and communicate significant

status changes; in particular to inform the requester when it has completed performing

the requested work. A single requester can have many processes associated with it.

?
??
?
?

說明: WfRequester 接口是一個和工作流流程的執(zhí)行及結果有直接關系的接口;它代表了對一些工作執(zhí)行的請求;它的一個主要功能是把 WfProcess 鏈接到一個其它應用;其中 WfRequester 會關聯(lián)到多個 WfProcee, WfProcess 發(fā)生 complete terminate abort 事件時會通過回調 receiveEvent() 方法來通知 WfRequest ;在 receiveEvent(event) 方法中,參數 event 是一個 WfEventAudit 對象,其中 WfEventAudit 中有一個方法 source(), 通過這個方法我們可以得知是哪個 WfExecutionObject 對象觸發(fā)了事件源;得到了 WfExcutionObject WfProcess 我們也進而 得到了和這個 WfProcess 相關聯(lián)的其它應用;

主要步驟 :

(1)??? 自定義一個自己的類或接口,如 GenericRequester, 這個 GenericRequester 類代表用戶自定義的一個請求者;

(2)??? 在啟動 WfProcess 是,把這個請求者和 WfProcess 進行綁定注冊到 WfRequester 中;

?

WfReuester registerProcess() 就是做這個功能,主要代碼如下

protected Map performers = null;

public void registerProcess(WfProcess process, Map context, GenericRequester requester){

?????????????? performers.put(process, requester);

?

}

(3)??? 當工作流程在執(zhí)行的過程中發(fā)生 complete terminate abort 事件時會回調 WfRequest 中的 receiveEvent() 方法:

??? ? requester.receiveEvent(audit);

(4) ?? receiveEvent() 中首先根據 WfEventAudit source() 獲取觸發(fā)事件的 WfProcess 對象;

receiveEvent(WfEventAudit event){

??????? // 獲取事件源 process 對象

WfProcess? process = (WfProcess) event.source();

// 根據 prcocess 對象獲取在注冊時綁定的自定義請求者 GenericRequester

GenericRequester ?req = (GenericRequester) performers.get(process);

// 執(zhí)行自定義請求者的方法

req.receiveResult(process.result());

}

其它:在這里 GenericRequester 也可是一個 WfProcess WfActivity 對象,這樣可以在 WfProcess 完成操作后又啟動另一個子流程或某個活動; ???

?

?
?
?
?