1 package org.simantics.db.common;
3 import java.util.concurrent.Semaphore;
4 import java.util.concurrent.TimeUnit;
6 import org.simantics.db.AsyncReadGraph;
7 import org.simantics.db.exception.DatabaseException;
9 public class GraphSemaphore extends Semaphore {
11 private static final long serialVersionUID = 2114861433176831938L;
13 private final AsyncReadGraph graph;
15 public GraphSemaphore(AsyncReadGraph graph, int permits) {
20 public void waitFor(int permits) throws DatabaseException, InterruptedException {
21 boolean success = false;
22 success = tryAcquire(permits);
27 if (graph.performPending()) {
29 success = tryAcquire(permits);
31 // Nothing to do - just wait
33 success = tryAcquire(permits, 10, TimeUnit.SECONDS);
35 throw new DatabaseException("Timeout while waiting for async request to complete.");
36 } catch (InterruptedException e) {
37 throw new DatabaseException(e);