+
+ }
+
+ return getResult();
+
+ }
+
+ public static <T> T computeForEach(ReadGraphImpl callerGraph, AsyncRead<T> request, AsyncReadEntry<T> entry,
+ AsyncProcedure<T> procedure_, boolean needsToBlock) throws DatabaseException {
+
+ BlockingAsyncProcedure<T> proc = new BlockingAsyncProcedure(callerGraph, entry, procedure_, request, needsToBlock);
+ if(needsToBlock) {
+ return proc.performSync(request);
+ } else {
+ proc.performAsync(request);
+ return null;
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ if (isDiscarded())
+ return "DISCARDED " + id.toString();
+ else if (isExcepted())
+ return id.toString() + " " + getResult();
+ else
+ return id.toString() + " " + statusOrException;
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, T result) {
+ Collection<SessionTask> tasks = null;
+ synchronized(this) {
+ setResult(result);
+ setReady();
+ if(pendingTaskSupport != null)
+ tasks = pendingTaskSupport.executePending();
+ }
+ if(tasks != null)
+ for(SessionTask task : tasks)
+ ((ReadGraphImpl)graph).processor.scheduleNow(task);
+ }
+
+ @Override
+ public synchronized void exception(AsyncReadGraph graph, Throwable throwable) {
+ Collection<SessionTask> tasks = null;
+ synchronized(this) {
+ except(throwable);
+ if(pendingTaskSupport != null)
+ tasks = pendingTaskSupport.executePending();
+ }
+ if(tasks != null)
+ for(SessionTask task : tasks)
+ ((ReadGraphImpl)graph).processor.scheduleNow(task);
+ }
+
+ public void executeWhenResultIsAvailable(QueryProcessor processor, SessionTask task) {
+ boolean ready = false;
+ synchronized(this) {
+ if(pendingTaskSupport == null)
+ pendingTaskSupport = new PendingTaskSupport(this);
+ ready = pendingTaskSupport.executeWhenResultIsAvailable(task);
+ }
+ if(ready) {
+ processor.scheduleNow(task);