import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import org.simantics.databoard.Bindings;
private THashSet<ListenerEntry> scheduledListeners = new THashSet<ListenerEntry>();
private boolean firingListeners = false;
final THashMap<CacheEntry, ArrayList<ListenerEntry>> listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
- private BlockingQueue<Runnable> tasks = new LinkedBlockingQueue<Runnable>();
+ private BlockingQueue<Runnable> tasks = new ArrayBlockingQueue<Runnable>(2048);
private Map<ListenerBase,ListenerEntry> addedEntries = new HashMap<>();
QueryListening(QueryProcessor processor) {
public void sync() {
Semaphore s = new Semaphore(0);
- tasks.add(() -> {
- s.release();
- });
try {
+ tasks.put(() -> {
+ s.release();
+ });
s.acquire();
} catch (Throwable t) {
LOGGER.error("Error while waiting for query dependency management", t);
void registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) {
- tasks.offer(() -> {
+ try {
+ tasks.put(() -> {
- if (parent != null && !inferred) {
- try {
- if(!child.isImmutable(graph))
- child.addParent(parent);
- } catch (DatabaseException e) {
- LOGGER.error("Error while registering query dependencies", e);
- }
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) {
- System.out.println(child + " -> " + parent);
+ if (parent != null && !inferred) {
+ try {
+ if(!child.isImmutable(graph))
+ child.addParent(parent);
+ } catch (DatabaseException e) {
+ LOGGER.error("Error while registering query dependencies", e);
+ }
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) {
+ System.out.println(child + " -> " + parent);
+ }
}
}
- }
- if (listener != null)
- registerListener(child, listener, procedure);
+ if (listener != null)
+ registerListener(child, listener, procedure);
- });
+ });
+ } catch (InterruptedException e) {
+ LOGGER.error("Error while registering dependencies", e);
+ }
}