abstract Query getQuery();
abstract CacheEntry pruneFirstParents();
+ abstract void pruneParentSet();
abstract void removeParent(CacheEntry entry);
abstract void addParent(CacheEntry entry);
abstract boolean hasParents();
}
}
-
+
+ @Override
+ void pruneParentSet() {
+ // First parent is discarded => look for more parents
+ if(p2OrParents instanceof QueryIdentityHashSet) {
+
+ QueryIdentityHashSet set = (QueryIdentityHashSet)p2OrParents;
+ set.removeDiscardedReally();
+ if(set.isEmpty()) p2OrParents = null;
+
+ } else if(p2OrParents instanceof CacheEntry) {
+
+ CacheEntry entry = (CacheEntry)p2OrParents;
+ if(entry.isDiscarded()) {
+ // Second entry is also discarded => all empty
+ p2OrParents = null;
+ }
+
+ } else {
+
+ // Nothing left
+
+ }
+ }
+
@Override
final public void removeParent(CacheEntry entry) {
final LinkedList<T> items = new LinkedList<T>();
protected ExternalRead<T> id;
- protected ReadGraphImpl graph;
+ protected QueryProcessor processor;
protected boolean registered = false;
@Override
public void discard() {
id.unregistered();
id = null;
- graph = null;
+ processor = null;
super.discard();
}
public ExternalReadEntry(ExternalRead<T> request, ReadGraphImpl graph) {
assert request != null;
this.id = request;
- this.graph = graph;
+ this.processor = graph.processor;
}
@Override
synchronized(items) {
items.addLast(result);
- graph.processor.updatePrimitive(id);
+ processor.updatePrimitive(id);
// TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated
// In some cases where data is produced really fast this might be necessary but currently this queueing will do.
}
@Override
public boolean isDisposed() {
- return registered && (isDiscarded() || !graph.processor.isBound(this));
+ return registered && (isDiscarded() || !processor.isBound(this));
}
}
} else {
+ entry.pruneParentSet();
support.setLevel(entry, parent.getLevel() + 1);
}
// TODO Auto-generated method stub
return null;
}
-
+
+ @Override
+ void pruneParentSet() {
+ }
+
};
/**
}
}
-
+
+ final public void removeDiscardedReally() {
+
+ tempDisableAutoCompaction();
+ try {
+
+ for(int i=0;i<_set.length;i++) {
+ CacheEntry entry = _set[i];
+ if(entry != null && REMOVED != entry) {
+ if(entry.isDiscarded()) removeAt(i);
+ }
+ }
+
+ } finally {
+ reenableAutoCompaction(false);
+ }
+
+ }
+
/**
* Creates an iterator over the values of the set. The iterator
* supports element deletion.
if(base == null) return;
consumer.accept(() -> {
- ListenerEntry entry = addedEntries.get(base);
+ ListenerEntry entry = addedEntries.remove(base);
if(entry != null) entry.setLastKnown(result);
});
package org.simantics.document.server.request;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
-import org.simantics.db.common.request.AsyncReadRequest;
+import org.simantics.db.common.request.UnaryAsyncRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.VariableRead;
import org.simantics.db.layer0.variable.Variable;
super(var);
}
- @Override
- public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
-
- long s = System.nanoTime();
-
- Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
- HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
- if(nodes.isEmpty()) {
- return Collections.emptyList();
- }
+ static class CollectNodesRequest extends UnaryAsyncRead<Collection<Variable>, Collection<JSONObject>> {
- if(PROFILE) {
- long dura = System.nanoTime()-s;
- System.err.println("DocumentRequest1 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ public CollectNodesRequest(Collection<Variable> nodes) {
+ super(nodes);
}
- graph.syncRequest(new AsyncReadRequest() {
+ @Override
+ public void perform(AsyncReadGraph graph, AsyncProcedure<Collection<JSONObject>> procedure) {
+ HashSet<JSONObject> rs = new HashSet<JSONObject>(); // result
- @Override
- public void run(AsyncReadGraph graph) throws DatabaseException {
+ for(Variable node : parameter) {
+ graph.asyncRequest(new NodeRequest(node), new AsyncProcedure<JSONObject> () {
- for(Variable node : nodes) {
- graph.asyncRequest(new NodeRequest(node), new AsyncProcedure<JSONObject> () {
-
- @Override
- public void execute(AsyncReadGraph graph, JSONObject result) {
- synchronized (rs) {
- rs.add(result);
- }
+ @Override
+ public void execute(AsyncReadGraph graph, JSONObject result) {
+ synchronized(rs) {
+ rs.add(result);
}
+ }
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- }
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ }
+
+ });
- });
-
- }
-
}
-
- });
+ procedure.execute(graph, rs);
+
+ }
+
+ }
+
+ @Override
+ public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
+
+ long s = System.nanoTime();
+
+ Set<Variable> nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.<Set<Variable>>instance());
+ if(nodes.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ if(PROFILE) {
+ long dura = System.nanoTime()-s;
+ System.err.println("DocumentRequest1 " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
+ }
+ Collection<JSONObject> rs = graph.syncRequest(new CollectNodesRequest(nodes));
if(PROFILE) {
long dura = System.nanoTime()-s;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
-import org.simantics.db.common.request.AsyncReadRequest;
+import org.simantics.db.common.request.UnaryAsyncRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.VariableChildren;
import org.simantics.db.layer0.request.VariableRead;
import org.simantics.utils.threads.logger.ITask;
import org.simantics.utils.threads.logger.ThreadLogger;
-import gnu.trove.set.hash.THashSet;
-
public class NodesRequest extends VariableRead<Set<Variable>> {
public NodesRequest(Variable var) {
super(var);
}
- @Override
- public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
+ static class CollectNodesRequest2 extends UnaryAsyncRead<Collection<Variable>, Set<Variable>> {
- ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null;
+ public CollectNodesRequest2(Collection<Variable> nodes) {
+ super(nodes);
+ }
- StructuralResource2.getInstance(graph);
- if(variable == null)
- return Collections.emptySet();
+ @Override
+ public void perform(AsyncReadGraph graph, AsyncProcedure<Set<Variable>> procedure) {
+ HashSet<Variable> rs = new HashSet<Variable>(); // result
- Set<Variable> nodes = new THashSet<Variable>();
+ for(Variable node : parameter) {
+ graph.asyncRequest(new NodesRequest2(node), new AsyncProcedure<Set<Variable>> () {
- Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
+ @Override
+ public void execute(AsyncReadGraph graph, Set<Variable> result) {
+ synchronized(rs) {
+ rs.addAll(result);
+ }
+ }
- graph.syncRequest(new AsyncReadRequest() {
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable throwable) {
+ }
- @Override
- public void run(AsyncReadGraph graph) throws DatabaseException {
+ });
- for(Variable child : children) {
- graph.asyncRequest(new NodesRequest2(child), new AsyncProcedure<Set<Variable>>() {
+ }
+ procedure.execute(graph, rs);
- @Override
- public void execute(AsyncReadGraph graph, Set<Variable> result) {
- synchronized(nodes) {
- nodes.addAll(result);
- }
- }
+ }
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- }
-
- });
- }
+ }
- }
+ @Override
+ public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
+
+ ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null;
+
+ StructuralResource2.getInstance(graph);
+ if(variable == null)
+ return Collections.emptySet();
+
+ Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
- });
+ Set<Variable> nodes = graph.syncRequest(new CollectNodesRequest2(children));
if(DocumentRequest.PROFILE) task.finish();