]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java
Multiple readers in db client
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / QueryCache.java
index 06882a48943e711e502d725108ee2f0e4147f213..35ebdbc65ba4ce82e5e7e7dced301310c30f8b17 100644 (file)
@@ -19,7 +19,7 @@ import org.simantics.db.request.Read;
 
 public class QueryCache extends QueryCacheBase {
 
-    private static final boolean SINGLE = false;
+    private static final boolean SINGLE = true;
 
     public QueryCache(QuerySupport querySupport, int threads) {
         super(querySupport, threads);
@@ -68,12 +68,14 @@ public class QueryCache extends QueryCacheBase {
         }
         Objects entry = (Objects)cache.getOrCreateObjects(graph, r1,r2);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureObjects;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Objects.computeForEach(graph, r1,r2, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -126,12 +128,14 @@ public class QueryCache extends QueryCacheBase {
         }
         Statements entry = (Statements)cache.getOrCreateStatements(graph, r1,r2);
         TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureStatements;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Statements.computeForEach(graph, r1,r2, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -184,12 +188,14 @@ public class QueryCache extends QueryCacheBase {
         }
         DirectObjects entry = (DirectObjects)cache.getOrCreateDirectObjects(graph, r1,r2);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectObjects;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           DirectObjects.computeForEach(graph, r1,r2, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -242,12 +248,14 @@ public class QueryCache extends QueryCacheBase {
         }
         RelationInfoQuery entry = (RelationInfoQuery)cache.getOrCreateRelationInfoQuery(graph, r);
         InternalProcedure<RelationInfo> procedure_ = procedure != null ? procedure : emptyProcedureRelationInfoQuery;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           RelationInfoQuery.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -300,12 +308,14 @@ public class QueryCache extends QueryCacheBase {
         }
         URIToResource entry = (URIToResource)cache.getOrCreateURIToResource(graph, id);
         InternalProcedure<Integer> procedure_ = procedure != null ? procedure : emptyProcedureURIToResource;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           URIToResource.computeForEach(graph, id, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -358,12 +368,14 @@ public class QueryCache extends QueryCacheBase {
         }
         ValueQuery entry = (ValueQuery)cache.getOrCreateValueQuery(graph, r);
         InternalProcedure<byte[]> procedure_ = procedure != null ? procedure : emptyProcedureValueQuery;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           ValueQuery.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -416,12 +428,14 @@ public class QueryCache extends QueryCacheBase {
         }
         OrderedSet entry = (OrderedSet)cache.getOrCreateOrderedSet(graph, r);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureOrderedSet;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           OrderedSet.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -474,12 +488,14 @@ public class QueryCache extends QueryCacheBase {
         }
         PrincipalTypes entry = (PrincipalTypes)cache.getOrCreatePrincipalTypes(graph, r);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedurePrincipalTypes;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           PrincipalTypes.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -532,12 +548,14 @@ public class QueryCache extends QueryCacheBase {
         }
         DirectPredicates entry = (DirectPredicates)cache.getOrCreateDirectPredicates(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureDirectPredicates;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           DirectPredicates.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -590,12 +608,14 @@ public class QueryCache extends QueryCacheBase {
         }
         Predicates entry = (Predicates)cache.getOrCreatePredicates(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedurePredicates;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Predicates.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -605,7 +625,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read<?> r, boolean needsToBlock) throws DatabaseException {
+    private final ReadEntry getOrCreateReadEntry(ReadGraphImpl graph, Read<?> r, boolean needsToBlock) throws DatabaseException {
         ReadEntry existing = null;
         synchronized(readEntryMap) {
             existing = (ReadEntry)readEntryMap.get(r);
@@ -650,11 +670,13 @@ public class QueryCache extends QueryCacheBase {
         }
         ReadEntry entry = (ReadEntry)cache.getOrCreateReadEntry(graph, r, needsToBlock);
         if(entry == null) {
-          graph.processor.schedule(new SessionTask(graph) {
+          graph.asyncBarrier.inc();  
+          graph.processor.scheduleNow(new SessionTask() {
             @Override
             public void run0(int thread) {
               try {
                 runnerReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+                graph.asyncBarrier.dec();  
               } catch (DatabaseException e) {
                 Logger.defaultLogError(e);
               }
@@ -663,12 +685,17 @@ public class QueryCache extends QueryCacheBase {
           return null;
         }
         AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureReadEntry;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) return entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          Object result = entry.performFromCache(graph, procedure_);
+          graph.processor.listening.registerFirstKnown(listener, result);
+          return result;
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Object result = ReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
+          graph.processor.listening.registerFirstKnown(listener, result);
           return result;
         }
     }
@@ -679,7 +706,7 @@ public class QueryCache extends QueryCacheBase {
         }
     }
     
-    AsyncReadEntry getOrCreateAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, boolean needsToBlock) throws DatabaseException {
+    AsyncReadEntry getOrCreateAsyncReadEntry(ReadGraphImpl graph, AsyncRead<?> r, CacheEntry parent, ListenerBase listener, final AsyncProcedure procedure, boolean needsToBlock) throws DatabaseException {
         AsyncReadEntry existing = null;
         synchronized(asyncReadEntryMap) {
             existing = (AsyncReadEntry)asyncReadEntryMap.get(r);
@@ -696,11 +723,21 @@ public class QueryCache extends QueryCacheBase {
             }
         }
         if(existing.isPending()) {
-          if(needsToBlock)
-            waitPending(graph, existing);
-          else {
-            return null;
-          }
+            if(needsToBlock)
+                waitPending(graph, existing);
+            else {
+                existing.executeWhenResultIsAvailable(graph.processor, new SessionTask(graph) {
+                    @Override
+                    public void run0(int thread) {
+                        try {
+                            runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
+                        } catch (DatabaseException e) {
+                            Logger.defaultLogError(e);
+                        }
+                    }
+                });
+                return null;
+            }
         }
         return existing;
     }
@@ -722,27 +759,23 @@ public class QueryCache extends QueryCacheBase {
             }
             return AsyncReadEntry.computeForEach(graph, r, null, procedure, needsToBlock);
         }
-        AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, needsToBlock);
+        AsyncReadEntry entry = (AsyncReadEntry)cache.getOrCreateAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
         if(entry == null) {
-          graph.processor.schedule(new SessionTask(graph) {
-            @Override
-            public void run0(int thread) {
-              try {
-                runnerAsyncReadEntry(graph, r, parent, listener, procedure, needsToBlock);
-              } catch (DatabaseException e) {
-                Logger.defaultLogError(e);
-              }
-            }
-          });
-          return null;
+            // Entry was pending and this request has been queued  
+            return null;
         }
         AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncReadEntry;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) return entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          Object result = entry.performFromCache(graph, procedure_);
+          graph.processor.listening.registerFirstKnown(listener, result);
+          return result;
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Object result = AsyncReadEntry.computeForEach(graph, r, entry, procedure_, needsToBlock);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
+          graph.processor.listening.registerFirstKnown(listener, result);
           return result;
         }
     }
@@ -796,12 +829,14 @@ public class QueryCache extends QueryCacheBase {
         }
         Types entry = (Types)cache.getOrCreateTypes(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypes;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           Types.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -854,12 +889,14 @@ public class QueryCache extends QueryCacheBase {
         }
         ChildMap entry = (ChildMap)cache.getOrCreateChildMap(graph, r);
         InternalProcedure<ObjectResourceIdMap<String>> procedure_ = procedure != null ? procedure : emptyProcedureChildMap;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           ChildMap.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -912,12 +949,14 @@ public class QueryCache extends QueryCacheBase {
         }
         TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           TypeHierarchy.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -970,12 +1009,14 @@ public class QueryCache extends QueryCacheBase {
         }
         SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           SuperTypes.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1028,12 +1069,14 @@ public class QueryCache extends QueryCacheBase {
         }
         SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph, r);
         InternalProcedure<IntSet> procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           SuperRelations.computeForEach(graph, r, entry, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1075,12 +1118,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph, r);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1122,12 +1167,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph, r1,r2);
         TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1169,12 +1216,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph, r);
         IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1216,12 +1265,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph, r);
         SyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1263,12 +1314,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         AsyncMultiReadEntry entry = (AsyncMultiReadEntry)cache.getOrCreateAsyncMultiReadEntry(graph, r);
         AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureAsyncMultiReadEntry;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }
     
@@ -1310,12 +1363,14 @@ public class QueryCache extends QueryCacheBase {
         QueryCache cache  = graph.processor.cache;
         ExternalReadEntry entry = (ExternalReadEntry)cache.getOrCreateExternalReadEntry(graph, r);
         AsyncProcedure procedure_ = procedure != null ? procedure : emptyProcedureExternalReadEntry;
-        ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);
-        if(entry.isReady()) entry.performFromCache(graph, procedure_);
+        if(entry.isReady()) {
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
+          entry.performFromCache(graph, procedure_);
+        }
         else {
           assert(entry.isPending());
+          graph.processor.listening.registerDependencies(graph, entry, parent, listener, procedure_, false);
           entry.compute(graph, procedure_);
-          if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());
         }
     }