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%2FBlockingAsyncMultiProcedure.java;h=5f7571ea8cab48a69fce0b88df2184c3d8bcad5a;hp=cc50ea9b8fcc4447f209f55fd370c4b477380a89;hb=785f638bab44e70ec6103c3891daea95bcda9a07;hpb=9f0fd59be54719b1fe9322d8fd37e4950857308c diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncMultiProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncMultiProcedure.java index cc50ea9b8..5f7571ea8 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncMultiProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncMultiProcedure.java @@ -14,6 +14,7 @@ package org.simantics.db.impl; import org.simantics.db.AsyncReadGraph; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.graph.AsyncBarrierImpl; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.procedure.AsyncMultiProcedure; @@ -22,24 +23,26 @@ public class BlockingAsyncMultiProcedure implements AsyncMultiProcedure< private static final Object NO_RESULT = new Object(); private final Object key; - private final ReadGraphImpl graph; + private final AsyncBarrierImpl barrier; + private final ReadGraphImpl procedureGraph; private final AsyncMultiProcedure procedure; private Object result = NO_RESULT; private Throwable exception = null; - public BlockingAsyncMultiProcedure(ReadGraphImpl graph, AsyncMultiProcedure procedure, Object key) { + public BlockingAsyncMultiProcedure(AsyncBarrierImpl barrier, ReadGraphImpl procedureGraph, AsyncMultiProcedure procedure, Object key) { this.procedure = procedure; this.key = key; - this.graph = ReadGraphImpl.newAsync(graph); - this.graph.asyncBarrier.inc(); + this.barrier = barrier; + this.barrier.inc(); + this.procedureGraph = procedureGraph; } @Override public void execute(AsyncReadGraph graph, Result result) { this.result = result; try { - if(procedure != null) procedure.execute(graph, result); + if(procedure != null) procedure.execute(procedureGraph, result); } catch (Throwable throwable) { Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable); } @@ -47,11 +50,12 @@ public class BlockingAsyncMultiProcedure implements AsyncMultiProcedure< @Override public void finished(AsyncReadGraph graph) { - this.graph.asyncBarrier.dec(); try { - if(procedure != null) procedure.finished(graph); + if(procedure != null) procedure.finished(procedureGraph); } catch (Throwable throwable) { Logger.defaultLogError("AsyncProcedure.finish threw for " + procedure, throwable); + } finally { + barrier.dec(); } } @@ -59,23 +63,26 @@ public class BlockingAsyncMultiProcedure implements AsyncMultiProcedure< public void exception(AsyncReadGraph graph, Throwable t) { this.exception = t; try { - if (procedure != null) procedure.exception(graph, t); + if (procedure != null) procedure.exception(procedureGraph, t); } catch (Throwable throwable) { Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable); } finally { - this.graph.asyncBarrier.dec(); + barrier.dec(); } } @SuppressWarnings("unchecked") public Result get() throws DatabaseException { - graph.asyncBarrier.waitBarrier(key, graph); + + barrier.waitBarrier(key, procedureGraph); + if (exception != null) { if (exception instanceof DatabaseException) throw (DatabaseException) exception; throw new DatabaseException(exception); } else { return (Result) result; } + } @SuppressWarnings("unchecked")