1 package org.simantics.db.common;
3 import java.util.concurrent.atomic.AtomicInteger;
5 import org.simantics.db.AsyncReadGraph;
6 import org.simantics.db.procedure.AsyncProcedure;
8 final public class ProcedureBarrier<T> extends AtomicInteger {
10 private static final long serialVersionUID = -2699547741948233067L;
12 private volatile Throwable throwable;
14 public ProcedureBarrier(int initial) {
18 final synchronized public void except(Throwable throwable) {
19 this.throwable = throwable;
22 final public Throwable getThrowable() {
26 final public void dec(AsyncReadGraph graph, AsyncProcedure<T> procedure, Throwable throwable) {
28 this.throwable = throwable;
30 if(decrementAndGet() == 0) {
31 procedure.exception(graph, throwable);
35 final public void dec(AsyncReadGraph graph, AsyncProcedure<T> procedure, T result) {
36 if(decrementAndGet() == 0) {
37 if(throwable != null) procedure.exception(graph, throwable);
38 else procedure.execute(graph, result);