X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2FGraphSemaphore.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2FGraphSemaphore.java;h=d5d7735aad5d3188ce75253f20eb90fdebbcce2e;hb=ce7b6d82a401806b7d70c203c12dedd22fed799c;hp=2924f0275a394cb57e160a752c8323cb3c84f03d;hpb=a6c431919eb2ef9a06623cf0b9daa1fd5a04669c;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java index 2924f0275..d5d7735aa 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/GraphSemaphore.java @@ -8,41 +8,35 @@ import org.simantics.db.exception.DatabaseException; public class GraphSemaphore extends Semaphore { - private static final long serialVersionUID = 2114861433176831938L; - - private final AsyncReadGraph graph; - - public GraphSemaphore(AsyncReadGraph graph, int permits) { - super(permits); - this.graph = graph; - } - - public void waitFor(int permits) throws DatabaseException, InterruptedException { - - boolean success = false; - success = tryAcquire(permits); - if(success) return; - - while(!success) { - - if(graph.performPending()) { - // Some task was done - success = tryAcquire(permits); - } else { - // Nothing to do - just wait - try { - success = tryAcquire(permits, 10, TimeUnit.SECONDS); - if(!success) throw new DatabaseException("Timeout while waiting for async request to complete."); - } catch (InterruptedException e) { - throw new DatabaseException(e); - } - } - - } - - - } - - + private static final long serialVersionUID = 2114861433176831938L; + private final AsyncReadGraph graph; + + public GraphSemaphore(AsyncReadGraph graph, int permits) { + super(permits); + this.graph = graph; + } + + public void waitFor(int permits) throws DatabaseException, InterruptedException { + boolean success = false; + success = tryAcquire(permits); + if (success) + return; + + while (!success) { + if (graph.performPending()) { + // Some task was done + success = tryAcquire(permits); + } else { + // Nothing to do - just wait + try { + success = tryAcquire(permits, 10, TimeUnit.SECONDS); + if (!success) + throw new DatabaseException("Timeout while waiting for async request to complete."); + } catch (InterruptedException e) { + throw new DatabaseException(e); + } + } + } + } }