不論產生作業是否成功,只有在遠端文件產生作業完成時,publishSync 方法才會返回。當該方法返回時,您可以檢查結果碼來判斷狀態。另一個驗證選項方法是使用非同步的 publish 方法。然後您可以在用戶端執行緒中,等待執行緒完成,並使用產生器的 getStatus 方法來檢查狀態。
使用 publishSync 方法:
RRDGEngine.EngineStatus status = generator.publishSync(docSpec, previewQueryLimit);
// At this point all is done ( successfully or not) and the job status is in the status variable
使用 publish 方法:
在大部分情況下,
publishSync 方法是最方便的方法。如果用戶端程式碼不會等待工作完成(尤其是在遠端文件產生實務中),就可以使用
publish 方法,如此一來,驗證就不會鎖定用戶端應用程式。
Thread t = generator.publish(docSpec, previewQueryLimit);
// this reeturns almost immediately and at this point the docgen is usually still running so the client code needs to wait for it
// wait for the job to finish
try
{
t.join();
// here the job is finished and it status can be obtaine with
RRDGEngine.EngineStatus status = generator.getStatus();
}
catch (InterruptedException e)
{
throw new RPEException(e);
}