X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryListening.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryListening.java;h=db9d0310f257a33fbfd53334a930fb31bdef7630;hb=63369acd7e6020a2148f40f6bab96b0b2ba392d8;hp=b873bfd73ef8f9b97773977b2459d7cdb502e9c6;hpb=89539b3b9d550028d15c6abcc9ecee3423d5a4a7;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java index b873bfd73..db9d0310f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java @@ -46,9 +46,6 @@ public class QueryListening { private Consumer consumer; private Map addedEntries = new HashMap<>(); - int execCount=0; - int queueCount = 0; - static class TL extends ThreadLocal> { Map> allQueues = new HashMap<>(); @@ -179,33 +176,70 @@ public class QueryListening { return !scheduledListeners.isEmpty(); } - public synchronized void dispatch(Runnable r) { - queueCount++; - consumer.accept(r); + static class RegisterParentRunnable implements Runnable { + + final CacheEntry parent; + final CacheEntry child; + + public RegisterParentRunnable(CacheEntry parent, CacheEntry child) { + this.parent = parent; + this.child = child; + } + + @Override + public void run() { + child.addParent(parent); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) { + System.out.println(child + " -> " + parent); + } + } + } + + } + + static class RegisterListenerRunnable implements Runnable { + + final QueryListening queryListening; + final ListenerBase base; + final Object procedure; + final CacheEntry parent; + final CacheEntry entry; + + public RegisterListenerRunnable(QueryListening queryListening, ListenerBase base, Object procedure, CacheEntry parent, CacheEntry entry) { + this.queryListening = queryListening; + this.base = base;; + this.procedure = procedure; + this.parent = parent; + this.entry = entry; + } + + @Override + public void run() { + queryListening.addListener(entry, base, procedure); + } + } void registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) { - dispatch(() -> { + if(inferred) { + assert(listener == null); + return; + } - if (parent != null && !inferred) { - try { - if(!child.isImmutable(graph)) - child.addParent(parent); - } catch (DatabaseException e) { - LOGGER.error("Error while registering query dependencies", e); - } - if (Development.DEVELOPMENT) { - if(Development.getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) { - System.out.println(child + " -> " + parent); - } - } + if(parent != null) { + try { + if(!child.isImmutable(graph)) + consumer.accept(new RegisterParentRunnable(parent, child)); + } catch (DatabaseException e) { + LOGGER.error("Error while registering query dependencies", e); } + } - if (listener != null) - registerListener(child, listener, procedure); - - }); + if(listener != null) + if(!listener.isDisposed()) + consumer.accept(new RegisterListenerRunnable(this, listener, procedure, parent, child)); } @@ -213,26 +247,13 @@ public class QueryListening { if(base == null) return; - dispatch(() -> { - + consumer.accept(() -> { ListenerEntry entry = addedEntries.get(base); if(entry != null) entry.setLastKnown(result); - }); } - public ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) { - - assert (entry != null); - - if (base.isDisposed()) - return null; - - return addListener(entry, base, procedure); - - } - /* * Registers a listener and returns an entry iff the entry was added */