/** * Set the result. * Listener notifications occur on calling thread of this method. * @param result The result. */ @Override protected synchronized boolean doSetResult(Collection<E> result, boolean undone) { synchronized(this) { if(intermediate) { throw new RuntimeException("setResult() only allowed without intermediate results: "+results); } boolean ret = super.doSetResult(result, undone); if(ret) { this.results = result; } return ret; } }
/** * Set the result. * Listener notifications occur on calling thread of this method. * @param result The result. */ public void setResult(E result) { doSetResult(result, false); resume(); }
/** * Set the result. * Listener notifications occur on calling thread of this method. * @param result The result. * @return True if result was set. */ public boolean setResultIfUndone(E result) { boolean ret = doSetResult(result, true); if(ret) { resume(); } return ret; }
/** * Declare that the future is finished. */ protected synchronized boolean doSetFinished(boolean undone) { boolean ret; Collection<E> res = getIntermediateResults(); ret = super.doSetResult(res, undone); if(ret) { // Hack!!! Set results to avoid inconsistencies between super.result and this.results, // because getIntermediateResults() returns empty list when results==null. if(results==null) { results = res; } } return ret; }
/** * Overwritten to change result, if necessary. */ @Override public boolean doSetResult(Object result, boolean undone) { try { result = func.handleResult(result); return DelegatingFuture.super.doSetResult(result, func.isUndone(undone)); } catch(Exception e) { return doSetException(e, func.isUndone(undone)); } }