X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FDocumentRequest.java;h=5b76cd344043f10dd05428642bee688c418ed12f;hp=8acc2f0d192899316c870cfba8ce27366b93d699;hb=HEAD;hpb=883a1447e1da4fb8365b85817e4d04588a0eb11d diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java index 8acc2f0d1..5b76cd344 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java @@ -1,6 +1,7 @@ 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; @@ -10,7 +11,7 @@ import java.util.Set; 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; @@ -28,49 +29,55 @@ public class DocumentRequest extends VariableRead> { super(var); } - @Override - public List perform(ReadGraph graph) throws DatabaseException { - - long s = System.nanoTime(); - - Set nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.>instance()); - HashSet rs = new HashSet(); // result - if(nodes.isEmpty()) { - return Collections.emptyList(); - } + static class CollectNodesRequest extends UnaryAsyncRead, Collection> { - 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 nodes) { + super(nodes); } - graph.syncRequest(new AsyncReadRequest() { + @Override + public void perform(AsyncReadGraph graph, AsyncProcedure> procedure) { + HashSet rs = new HashSet(); // result - @Override - public void run(AsyncReadGraph graph) throws DatabaseException { + for(Variable node : parameter) { + graph.asyncRequest(new NodeRequest(node), new AsyncProcedure () { - for(Variable node : nodes) { - graph.asyncRequest(new NodeRequest(node), new AsyncProcedure () { - - @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 perform(ReadGraph graph) throws DatabaseException { + + long s = System.nanoTime(); + + Set nodes = graph.syncRequest(new NodesRequest(variable), TransientCacheAsyncListener.>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 rs = graph.syncRequest(new CollectNodesRequest(nodes)); if(PROFILE) { long dura = System.nanoTime()-s;