X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;h=2eced2b7c046ebef86a64760cee27106667c706c;hp=a693b29228e026c1e1f6a5c7f3652c8d4320eb4c;hb=90a52d58489b6c518b13dde238923125c8f63eec;hpb=bb61be97905f72c01fd99e21c263546c88edc5f7 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index a693b2922..2eced2b7c 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -1926,9 +1926,7 @@ public class ReadGraphImpl implements AsyncReadGraph { public T syncRequest(final Read request) throws DatabaseException { assert (request != null); - ITask task = ThreadLogger.task(request); T result = (T)QueryCache.runnerReadEntry(this, request, parent, null, null, true); - task.finish(); return result; } @@ -1950,10 +1948,8 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); - ITask task = ThreadLogger.task(request); ListenerBase listener = procedure != null ? getListenerBase(procedure) : null; - T result = QueryCache.resultReadEntry(this, request, parent, listener, procedure); - task.finish(); + T result = (T)QueryCache.runnerReadEntry(this, request, parent, listener, procedure, true); return result; } @@ -2038,10 +2034,8 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); - ITask task = ThreadLogger.task(request); ListenerBase listener = getListenerBase(procedure); T result = (T)QueryCache.runnerAsyncReadEntry(this, request, parent, listener, procedure, true); - task.finish(); return result; } @@ -5160,7 +5154,11 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); assert (procedure != null); - + + AsyncBarrierImpl barrier = asyncBarrier; + if(barrier != null) + barrier.inc(); + processor.scheduleNow(new SessionTask(this) { @Override @@ -5170,6 +5168,9 @@ public class ReadGraphImpl implements AsyncReadGraph { QueryCache.runnerReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false); } catch (DatabaseException e) { Logger.defaultLogError(e); + } finally { + if(barrier != null) + barrier.dec(); } } @@ -5241,29 +5242,39 @@ public class ReadGraphImpl implements AsyncReadGraph { assert (request != null); assert (procedure != null); - ITask task = ThreadLogger.task(request); + AsyncBarrierImpl barrier = asyncBarrier; + if(barrier != null) + barrier.inc(); processor.scheduleNow(new SessionTask(this) { @Override public void run0(int thread) { - try { + + if(barrier != null) + barrier.inc(); + + try { final ListenerBase listener = getListenerBase(procedure); QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, new AsyncProcedure() { @Override public void execute(AsyncReadGraph graph, T result) { - task.finish(); procedure.execute(graph, result); + if(barrier != null) + barrier.dec(); } @Override public void exception(AsyncReadGraph graph, Throwable throwable) { - task.finish(); procedure.exception(graph, throwable); + if(barrier != null) + barrier.dec(); } }, false); + if(barrier != null) + barrier.dec(); } catch (DatabaseException e) { Logger.defaultLogError(e); } @@ -5651,27 +5662,47 @@ public class ReadGraphImpl implements AsyncReadGraph { this.parentGraph = parentGraph; this.parent = parent; this.processor = support; - this.asyncBarrier = new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null, parent); + this.asyncBarrier = new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null, parent, null); } + ReadGraphImpl(ReadGraphImpl parentGraph, CacheEntry parent, QueryProcessor support, AsyncBarrierImpl asyncBarrier) { + this.parentGraph = parentGraph; + this.parent = parent; + this.processor = support; + this.asyncBarrier = asyncBarrier; + } + ReadGraphImpl(ReadGraphImpl graph, CacheEntry parent) { this(graph, parent, graph.processor); } + ReadGraphImpl(ReadGraphImpl parentGraph, CacheEntry parent, Runnable callback) { + this(parentGraph, parent, parentGraph.processor, new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null, parent, callback)); + } + ReadGraphImpl(ReadGraphImpl graph) { this(graph, graph.parent); } - public ReadGraphImpl withParent(CacheEntry parent) { - return new ReadGraphImpl(this, parent); + public ReadGraphImpl withParent(CacheEntry parent, Runnable callback) { + return new ReadGraphImpl(this, parent, callback); } + public ReadGraphImpl withParent(CacheEntry parent) { + return withParent(parent, null); + } + + public ReadGraphImpl syncWithParent(CacheEntry parent) { + return new ReadGraphImpl(this, parent, processor, null); + } + public ReadGraphImpl forRecompute(CacheEntry parent) { return new ReadGraphImpl(null, parent, processor); } public static ReadGraphImpl create(QueryProcessor support) { - return new ReadGraphImpl(null, null, support); + ReadGraphImpl result = new ReadGraphImpl(null, null, support); + return result; } public ReadGraphImpl newRestart(ReadGraphImpl impl) { @@ -6357,6 +6388,12 @@ public class ReadGraphImpl implements AsyncReadGraph { else return 1 + getLevelStatic(impl.parentGraph); } + public boolean isParent(ReadGraphImpl impl) { + if(impl == null) return false; + if(this == impl) return true; + return isParent(impl.parentGraph); + } + public ReadGraphImpl getTopLevelGraph() { return getTopLevelGraphStatic(this); }