X-Git-Url: https://gerrit.simantics.org/r/gitweb?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=2e5411d39f8ea5c90242d22fc0fe400c4bda058a;hb=26b755c7e98b7bb3d9038abba139bef0e71f6607;hp=a693b29228e026c1e1f6a5c7f3652c8d4320eb4c;hpb=501ad95ad5ca980ef4c6e65af1451a0d7b63cddc;p=simantics%2Fplatform.git 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..2e5411d39 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 @@ -5160,7 +5160,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 +5174,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(); } } @@ -5242,12 +5249,20 @@ public class ReadGraphImpl implements AsyncReadGraph { 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() { @@ -5255,15 +5270,21 @@ public class ReadGraphImpl implements AsyncReadGraph { 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 +5672,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 +6398,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); }