import org.simantics.db.procedure.AsyncProcedure;
public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
+<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
final private Object key;
final private ReadGraphImpl graph;
public Result getResult() {
return result;
+=======
+
+ final private static Object NO_RESULT = new Object();
+
+ final private Object key;
+ final private ReadGraphImpl graph;
+ final private AsyncProcedure<Result> procedure;
+
+ private Object result = NO_RESULT;
+ private Throwable exception = null;
+
+ public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure<Result> procedure, Object key) {
+ this.procedure = procedure;
+ this.key = key;
+ this.graph = ReadGraphImpl.newAsync(graph);
+ this.graph.asyncBarrier.inc();
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, Result result) {
+ this.result = result;
+ this.graph.asyncBarrier.dec();
+ try {
+ if(procedure != null) procedure.execute(graph, result);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
+ }
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ this.exception = t;
+ try {
+ if(procedure != null) procedure.exception(graph, t);
+ } catch (Throwable throwable) {
+ Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
+ } finally {
+ }
+ this.graph.asyncBarrier.dec();
+ }
+
+ public Result get() throws DatabaseException {
+
+ graph.asyncBarrier.waitBarrier(key, graph);
+
+ if(exception != null) {
+ if(exception instanceof DatabaseException) throw (DatabaseException)exception;
+ throw new DatabaseException(exception);
+ } else {
+ return (Result)result;
+ }
+
+ }
+
+ public Result getResult() {
+ return (Result)result;
+>>>>>>> 82fa68e Generate parts of db client query code
}
public Throwable getException() {