X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCacheBase.java;h=6abaf6b6518e7b9239dad4830aa9acadd65492c5;hb=236aa4e765e0acd6e31cbc42dd9df9c2c23677e2;hp=b3d1c5f8836dcfdc82637dc01fec5bd3dfebce82;hpb=9f0fd59be54719b1fe9322d8fd37e4950857308c;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java index b3d1c5f88..6abaf6b65 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java @@ -189,71 +189,6 @@ public class QueryCacheBase { // // } - public Object performQuery(ReadGraphImpl parentGraph, final ExternalRead query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException { - - ExternalReadEntry entry = (ExternalReadEntry)entry_; - AsyncProcedure procedure = (AsyncProcedure)procedure_; - - try { - - query.register(parentGraph, new Listener() { - - AtomicBoolean used = new AtomicBoolean(false); - - @Override - public void execute(T result) { - - // Just for safety - if(entry.isDiscarded()) return; - - if(used.compareAndSet(false, true)) { - //entry.setPending(); - entry.addOrSet(parentGraph.processor, result); - procedure.execute(parentGraph, result); - } else { - entry.queue(result); - parentGraph.processor.updatePrimitive(query); - } - - } - - @Override - public void exception(Throwable t) { - - entry.except(t); - - if(used.compareAndSet(false, true)) { - procedure.exception(parentGraph, t); - } else { -// entry.queue(result); - parentGraph.processor.updatePrimitive(query); - } - - } - - @Override - public String toString() { - return procedure.toString(); - } - - @Override - public boolean isDisposed() { - return entry.isDiscarded() || !parentGraph.processor.isBound(entry); - } - - }); - - return entry.getResult(); - - } catch (Throwable t) { - - entry.except(t); - procedure.exception(parentGraph, t); - return entry.getResult(); - - } - - } public Object performQuery(ReadGraphImpl parentGraph, final AsyncMultiRead query, final CacheEntryBase entry_, Object procedure_) throws DatabaseException { @@ -637,18 +572,16 @@ public class QueryCacheBase { } } - public static void waitPending(QueryProcessor processor, CacheEntry entry) throws DatabaseException { + public static void waitPending(ReadGraphImpl graph, CacheEntry entry) throws DatabaseException { int counter = 0; while(entry.isPending()) { try { - SessionTask task = null;//processor.getOwnTask(processor.thread.get()); - if(task != null) { - task.run(processor.thread.get()); - } else { + boolean performed = graph.performPending(); + if(!performed) { Thread.sleep(1); counter++; - if(counter > 5000) { + if(counter > 30000) { CacheEntryBase base = ((CacheEntryBase)entry); // if(base.created != null) { // System.err.println("created:"); @@ -662,8 +595,8 @@ public class QueryCacheBase { // System.err.println("ready:"); // base.ready.printStackTrace(); // } - new Exception("Timeout waiting for request to complete: " + entry.getOriginalRequest().toString()).printStackTrace(); - throw new DatabaseException("Timeout waiting for request to complete."); + new Exception("Timeout waiting for request to complete: " + entry.getOriginalRequest()).printStackTrace(); + throw new DatabaseException("Timeout waiting for request to complete." + entry.getOriginalRequest()); //System.err.println("asd"); //base.getQuery().recompute(null, null, entry); } @@ -1129,15 +1062,11 @@ public class QueryCacheBase { } public static T resultReadEntry(ReadGraphImpl graph, Read r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { - AsyncProcedureWrapper wrap = new AsyncProcedureWrapper<>(procedure); - QueryCache.runnerReadEntry(graph, r, parent, listener, wrap, true); - return wrap.get(); + return (T)QueryCache.runnerReadEntry(graph, r, parent, listener, procedure, true); } public static T resultAsyncReadEntry(ReadGraphImpl graph, AsyncRead r, CacheEntry parent, ListenerBase listener, AsyncProcedure procedure) throws DatabaseException { - AsyncProcedureWrapper wrap = new AsyncProcedureWrapper<>(procedure); - QueryCache.runnerAsyncReadEntry(graph, r, parent, listener, wrap, true); - return wrap.get(); + return (T)QueryCache.runnerAsyncReadEntry(graph, r, parent, listener, procedure, true); } public static byte[] resultValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException {