final SyncResultListener lis = new SyncResultListener(); IGoalListener listener = new IGoalListener() lis.waitForResult();
lis = new SyncResultListener(); lis.reset();
/** * Wait for the result. * @param timeout The timeout. * @return The result. * @throws TimeoutException when result is not available in specified time frame. */ public Object waitForResult(long timeout) { if(!getInterpreter().isPlanThread()) throw new RuntimeException("SyncResultListener may only be used from plan thread."); if(!alreadyresumed) { this.alreadysuspended = true; waitForExternalCondition(this, timeout); } Exception ex = exception; Object res = result; reset(); // if(ex instanceof RuntimeException) // throw (RuntimeException)ex; if(ex!=null) throw new RuntimeException(ex); return res; }
public void goalFinished(AgentEvent ae) { IGoal goal = (IGoal)ae.getSource(); if(goal.isSucceeded()) { goalcnt++; if(goalcnt==agoalnames.length) lis.resultAvailable(null); } else { lis.exceptionOccurred(goal.getException()); } }
/** * Resume the execution of the plan. */ public void resume(Future<?> future) { // Only wake up if still waiting for same futur // (invalid resume might be called from outdated future after timeout already occurred or body aborted). if(this.future==future) { // if(toString().indexOf("ExtinguishFirePlan")!=-1) // System.out.println("resume "+this+", "+lis); lis.resultAvailable(null); } }
/** * Wait for the result. * @return The result. */ public Object waitForResult() { return waitForResult(-1); }