- AsyncProcedure<T> procedure = entry != null ? entry : procedure_;
-
- ReadGraphImpl queryGraph = graph.withParent(entry);
- queryGraph.asyncBarrier.inc();
-
- BlockingAsyncProcedure<T> proc = new BlockingAsyncProcedure<>(queryGraph.asyncBarrier, graph, null, request);
-
- class AsyncTask extends SessionTask {
-
- int counter = 0;
- T result;
- DatabaseException exception;
-
- public AsyncTask(ReadGraphImpl graph) {
- super(graph);
- }
-
- @Override
- public void run0(int thread) {
- if(needsToBlock) proc.waitBarrier();
- if(proc.isDone()) {
- ReadGraphImpl executeGraph = graph.withParent(graph.parent);
- executeGraph.asyncBarrier.inc();
- try {
- result = (T)proc.get();
- if(procedure != null) {
- procedure.execute(executeGraph, result);
- }
- } catch (DatabaseException e) {
- if(procedure != null) procedure.exception(executeGraph, e);
- exception = e;
- } catch (Throwable t) {
- DatabaseException dbe = new DatabaseException(t);
- if(procedure != null) procedure.exception(executeGraph, dbe);
- exception = dbe;
- } finally {
- if (entry != null) {
- // This does not throw
- entry.performFromCache(executeGraph, procedure_);
- }
- executeGraph.asyncBarrier.dec();
- executeGraph.asyncBarrier.waitBarrier(procedure, executeGraph);
- }
- } else {
- if(counter++ > 10000) {
- if(BarrierTracing.BOOKKEEPING) {
- AsyncBarrierImpl.printReverse(queryGraph.asyncBarrier, 2);
- AsyncBarrierImpl caller = queryGraph.asyncBarrier.caller;
- while(caller != null) {
- System.err.println("called by " + AsyncBarrierImpl.report(caller));
- caller = caller.caller;
- }
- for(AsyncBarrierImpl ab : BarrierTracing.debuggerMap.keySet()) {
- AsyncBarrierImpl.printReverse(ab, 2);
- }
- }
- throw new IllegalStateException("Eternal loop in queries.");
- }
- graph.processor.schedule(new AsyncTask(graph));
- }
- }
-
- }
-
- try {
- request.perform(queryGraph, proc);
- } finally {
- queryGraph.asyncBarrier.dec();
- }
-
- AsyncTask task = new AsyncTask(graph);
-
- if(needsToBlock) task.run(0);
- else if (proc.isDone()) task.run(0);
- else {
- graph.processor.schedule(task);