/** * Iterate over the intermediate results in a blocking fashion. * Manages results independently for different callers, i.e. when called * from different threads, each thread receives all intermediate results. * * The operation is guaranteed to be non-blocking, if hasNextIntermediateResult() * has returned true before for the same caller. Otherwise the caller is blocked * until a result is available or the future is finished. * * @return The next intermediate result. * @throws NoSuchElementException, when there are no more intermediate results and the future is finished. */ public E getNextIntermediateResult(long timeout, boolean realtime) { Integer index; synchronized(this) { index = indices!=null ? indices.get(Thread.currentThread()) : null; index = index==null ? Integer.valueOf(1) : Integer.valueOf(index.intValue()+1); if(indices==null) { indices = new HashMap<Thread, Integer>(); } indices.put(Thread.currentThread(), index); } return doGetNextIntermediateResult(index.intValue()-1, timeout, realtime); }
ret = doGetNextIntermediateResult(index, timeout, realtime);