MyWork myWork = ... WorkItem wi = wm.startWork(myWork); ... try { myWork = (MyWork)wi.getResult(); ... } catch (WorkException e) { Throwable cause = e.getCause(); ... }
// Submit the work WorkItem workItem = workManager.startWork(new MyWork()); // Wait for the work to be done for up to 60s ArrayList<WorkItem> items = new ArrayList<WorkItem>(); boolean workFinished = workManager.join(items, WorkManager.JOIN_AND, 60*1000); if(workFinished) try { MyWork work = workItem.getResult(); // if we get here, the work completed without errors } catch(WorkException e) { throw e.getCause(); // this will be the exception thrown by your Work impl } else { // the Work did not finish in 60s }
public void workRejected(WorkEvent event) { if (event.getException() != null) { if (event.getException() instanceof WorkCompletedException && event.getException().getCause() != null) { log.error(event.getWork().toString(), event.getException().getCause()); } else { log.error(event.getWork().toString(), event.getException()); } } } };
protected void handleWorkException(WorkEvent event, String type) { Throwable e; if (event != null && event.getException() != null) { e = event.getException(); } else { return; } if (event.getException().getCause() != null) { e = event.getException().getCause(); } logger.error("Work caused exception on '" + type + "'. Work being executed was: " + event.getWork().toString()); logger.error(e); } }
protected void handleWorkException(WorkEvent event, String type) { super.handleWorkException(event, type); if (event.getException() != null) { Throwable t = event.getException().getCause(); if (t != null) { if (t instanceof Error) { throw (Error) t; } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } } } } }