]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java
Yet another fixing commit
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / DocumentRequest.java
index 87b244c88ba28e1c43129cdf098a43e2f7781201..2f4f7eec62c3f887a70d7b8871cea1a347c3ad52 100644 (file)
@@ -6,11 +6,11 @@ import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
 
+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.exception.DatabaseException;
 import org.simantics.db.layer0.request.VariableRead;
 import org.simantics.db.layer0.variable.Variable;
@@ -79,47 +79,39 @@ public class DocumentRequest extends VariableRead<List<JSONObject>> {
                        System.out.println("               " + node.getURI(graph));
                }*/
 
-               Semaphore done = new Semaphore(0);
-               
-               for(Variable node : nodes) {
-                       
-                       graph.asyncRequest(new NodeRequestE(node), new Listener<JSONObject>() {
+               graph.syncRequest(new AsyncReadRequest() {
+                               
+                               @Override
+                               public void run(AsyncReadGraph graph) {
+                                       
+                               for(Variable node : nodes) {
+                                       
+                                       graph.asyncRequest(new NodeRequestE(node), new Listener<JSONObject>() {
 
-                                       @Override
-                                       public void execute(JSONObject result) {
-                                               synchronized(rs) {
-                                                       rs.add(result);
-                                               }
-                                               done.release();
-                                       }
+                                                       @Override
+                                                       public void execute(JSONObject result) {
+                                                               synchronized(rs) {
+                                                                       rs.add(result);
+                                                               }
+                                                       }
 
-                                       @Override
-                                       public void exception(Throwable t) {
-                                               t.printStackTrace();
-                                               done.release();
-                                       }
+                                                       @Override
+                                                       public void exception(Throwable t) {
+                                                               t.printStackTrace();
+                                                       }
 
-                                       @Override
-                                       public boolean isDisposed() {
-                                               return true;
-                                       }
+                                                       @Override
+                                                       public boolean isDisposed() {
+                                                               return true;
+                                                       }
+                                                       
+                                               });
+                                       
+                               }
                                        
-                               });
-                       
-//                 rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
-                       
-               }
-               
-               try {
-                       boolean success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
-                       while(!success) {
-                               success = done.tryAcquire(nodes.size(), 10, TimeUnit.MILLISECONDS);
-                               System.err.println("still trying to acquire semaphore, avail = " + done.availablePermits() );
-                       }
+                               }
                                
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       }
+                       });
        
                        ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
                        Collections.sort(result, new Comparator<JSONObject>() {