]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Yet another fixing commit private/antti_threads
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 27 Jul 2018 17:01:49 +0000 (20:01 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Fri, 27 Jul 2018 17:01:49 +0000 (20:01 +0300)
Change-Id: Ie0d47e541b5cc784d94d57acd1242b4be2e387a8

bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CodeGen.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java
bundles/org.simantics.document.server/META-INF/MANIFEST.MF
bundles/org.simantics.document.server/src/org/simantics/document/server/request/DocumentRequest.java

index b751e8f70d5771f8bd0994e58dbaa1d890b53b93..c29e5f9920e26c6166901999d636dfdc28943213 100644 (file)
@@ -22,61 +22,6 @@ import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.procedure.AsyncProcedure;
 
 public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
-
-       final private Object key;
-    final private ReadGraphImpl graph;
-       final private AsyncProcedure<Result> procedure;
-       
-    private Result result = null;
-    private Throwable exception = null;
-    
-    public BlockingAsyncProcedure(ReadGraphImpl graph, AsyncProcedure<Result> procedure, Object key) {
-       this.procedure = procedure;
-       this.key = key;
-       this.graph = ReadGraphImpl.newAsync(graph);
-        this.graph.asyncBarrier.inc();
-    }
-    
-    @Override
-    public void execute(AsyncReadGraph graph, Result result) {
-        this.result = result;
-        this.graph.asyncBarrier.dec();
-        try {
-               if(procedure != null) procedure.execute(graph, result);
-        } catch (Throwable throwable) {
-               Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
-        }
-    }
-
-    @Override
-    public void exception(AsyncReadGraph graph, Throwable t) {
-        this.exception = t;
-        try {
-               if(procedure != null) procedure.exception(graph, t);
-        } catch (Throwable throwable) {
-               Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
-        } finally {
-        }
-        this.graph.asyncBarrier.dec();
-    }
-    
-    public Result get() throws DatabaseException {
-       
-       graph.asyncBarrier.waitBarrier(key, graph);
-       
-       if(exception != null) {
-               if(exception instanceof DatabaseException) throw (DatabaseException)exception;
-               throw new DatabaseException(exception);
-       } else {
-               return result;
-       }
-       
-    }
-    
-    public Result getResult() {
-        return result;
-=======
        
        final private static Object NO_RESULT = new Object();
 
@@ -132,7 +77,6 @@ public class BlockingAsyncProcedure<Result> implements AsyncProcedure<Result> {
     
     public Result getResult() {
         return (Result)result;
->>>>>>> 82fa68e Generate parts of db client query code
     }
     
     public Throwable getException() {
index 16af00b30ba0250725ae9d2107bb132d10f56e8f..212326087a19581198d85ed28672c97891fb3334 100644 (file)
@@ -25,147 +25,6 @@ public class CodeGen {
        String[] signatureChildMap = { "int r", "r", "keyR", "long", "InternalProcedure<ObjectResourceIdMap<String>>", "entry.id" };
        String[] signatureRead = { "Read<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
        String[] signatureAsyncRead = { "AsyncRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
-       String[] signatureMultiRead = { "MultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "entry.request" };
-       String[] signatureAsyncMultiRead = { "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "entry.request" };
-       String[] signatureExternalRead = { "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
-
-       private void line(StringBuilder content, String line) {
-               for(int i=0;i<indent;i++)
-                       content.append(" ");
-               content.append(line);
-               content.append("\n");
-       }
-       
-       public void generateQuery(StringBuilder content, String clazz, String[] signature, boolean runnerShortcut, boolean genAsync) {
-               generateGetOrCreate(content, clazz, signature, genAsync);
-               generateRemove(content, clazz, signature);
-               generateRunner(content, clazz, signature, runnerShortcut, genAsync);
-       }
-       
-       public void generateRunner(StringBuilder content, String clazz, String[] signature, boolean shortcut, boolean genAsync) {
-               
-               line(content, "public static void runner" + clazz + "(ReadGraphImpl graph, " + signature[0] + ", CacheEntry parent, ListenerBase listener, final " + signature[4] + " procedure" + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
-               line(content, "    QueryCache cache  = graph.processor.cache;");
-               if(shortcut) {
-                       line(content, "    if(parent == null && listener == null && !cache.shouldCache(graph.processor, " + signature[1] + ")) {");
-                       line(content, "        " + clazz + ".computeForEach(graph, " + signature[1] + ", null, procedure);");
-                       line(content, "        return;");
-                       line(content, "    }");
-               }
-               line(content, "    " + clazz + " entry = (" + clazz + ")cache.getOrCreate" + clazz + "(graph.processor, " + signature[1] + (genAsync ? ", isSync" : "") + ");");
-               if(genAsync) {
-                       line(content, "    if(entry == null) {");
-                       line(content, "        graph.processor.schedule(new SessionTask(false) {");
-                       line(content, "            @Override");
-                       line(content, "            public void run(int thread) {");
-                       line(content, "                try {");
-                       line(content, "                    assert(!isSync);");
-                       line(content, "                    runner" + clazz + "(graph, r, parent, listener, procedure, isSync);");
-                       line(content, "                } catch (DatabaseException e) {");
-                       line(content, "                    Logger.defaultLogError(e);");
-                       line(content, "                }");
-                       line(content, "            }");
-                       line(content, "        });");
-                       line(content, "        return;");
-                       line(content, "    }");
-               }
-               line(content, "    " + signature[4] + " procedure_ = procedure != null ? procedure : emptyProcedure" + clazz + ";");
-               line(content, "    ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false);");
-               line(content, "    if(entry.isReady()) entry.performFromCache(graph, procedure_);");
-               line(content, "    else {");
-               line(content, "      assert(entry.isPending());");
-               if(shortcut) line(content, "        " + clazz + ".computeForEach(graph, " + signature[1] + ", entry, procedure_);");
-               else line(content, "        entry.compute(graph, procedure_);"); 
-               line(content, "        if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult());");
-               line(content, "    }");
-               line(content, "}");
-               line(content, "");
-
-       }
-       
-       public void generateRemove(StringBuilder content, String clazz, String[] signature) {
-
-               String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-
-               line(content, "void remove(" + clazz + " entry) {");
-               line(content, "    synchronized(" + lower + "Map) {");
-               line(content, "        " + lower + "Map.remove(" + signature[5] + ");");
-               line(content, "    }");
-               line(content, "}");
-               line(content, "");
-
-       }
-
-       public void generateGetOrCreate(StringBuilder content, String clazz, String[] signature, boolean genAsync) {
-               
-               String lower = Character.toLowerCase(clazz.charAt(0)) + clazz.substring(1);
-               
-               line(content, "" + clazz + " getOrCreate" + clazz + "(QueryProcessor processor, " + signature[0] + (genAsync ? ", boolean isSync" : "") + ") throws DatabaseException {");
-               line(content, "    " + clazz + " existing = null;");
-               line(content, "    synchronized(" + lower + "Map) {");
-               line(content, "        existing = (" + clazz + ")" + lower + "Map.get(" + signature[1] + ");");
-               line(content, "        if(existing == null) {");
-               line(content, "            existing = new " + clazz + "(" + signature[1] + ");");
-               line(content, "            existing.clearResult(querySupport);");
-               line(content, "            existing.setPending();");
-               line(content, "            " + lower + "Map.put(" + signature[2] + "(" + signature[1] + "), existing);");
-               line(content, "            size++;");
-               line(content, "            return existing;");
-               line(content, "        }");
-               line(content, "        if(existing.requiresComputation()) {");
-               line(content, "            existing.setPending();");
-               line(content, "            return existing;");
-               line(content, "        }");
-               line(content, "    }");
-               if(genAsync) {
-                       line(content, "    if(existing.isPending()) {");
-                       line(content, "      if(isSync) waitPending(processor, existing);");
-                       line(content, "      else return null;");
-                       line(content, "    }");
-               } else {
-                       line(content, "    if(existing.isPending()) waitPending(processor, existing);");
-               }
-               line(content, "    return existing;");
-               line(content, "}");
-               line(content, "");
-               
-       }
-       
-       public void generate() {
-
-        URL classLocation = CodeGen.class.getResource(".");
-        if (classLocation != null) {
-            if (classLocation.getProtocol().equals("file")) {
-                try {
-                    URL resource = new URL(classLocation, ".");
-                    File path = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
-                    String target = path.getAbsolutePath().replace("\\", "/");
-                    target = target.replace("/bin/", "/src/") + "/QueryCache.java";
-                    System.err.println("target=" + target);
-                    File source = new File(target);
-                    StringBuilder content = new StringBuilder();
-                    content.append("package org.simantics.db.impl.query;\n");
-                    content.append("\n");
-                    
-                    content.append("import org.simantics.db.ObjectResourceIdMap;\n");
-                    content.append("import org.simantics.db.RelationInfo;\n");
-                    content.append("import org.simantics.db.common.utils.Logger;\n");
-                    content.append("import org.simantics.db.exception.DatabaseException;\n");
-                    content.append("import org.simantics.db.impl.graph.ReadGraphImpl;\n");
-                    content.append("import org.simantics.db.impl.procedure.InternalProcedure;\n");
-                    content.append("import org.simantics.db.impl.query.QueryProcessor.SessionTask;\n");
-                    content.append("import org.simantics.db.procedure.AsyncMultiProcedure;\n");
-                    content.append("import org.simantics.db.procedure.AsyncProcedure;\n");
-                    content.append("import org.simantics.db.procedure.ListenerBase;\n");
-                    content.append("import org.simantics.db.request.AsyncMultiRead;\n");
-                    content.append("import org.simantics.db.request.AsyncRead;\n");
-                    content.append("import org.simantics.db.request.ExternalRead;\n");
-                    content.append("import org.simantics.db.request.MultiRead;\n");
-                    content.append("import org.simantics.db.request.Read;\n");
-                    content.append("\n");
-                    content.append("import gnu.trove.map.hash.TObjectIntHashMap;\n");
-=======
        String[] signatureMultiRead = { "MultiRead<?> r", "r", "id", "long", "SyncMultiProcedure", "entry.request" };
        String[] signatureAsyncMultiRead = { "AsyncMultiRead<?> r", "r", "id", "long", "AsyncMultiProcedure", "entry.request" };
        String[] signatureExternalRead = { "ExternalRead<?> r", "r", "id", "long", "AsyncProcedure", "entry.request" };
@@ -304,7 +163,6 @@ public class CodeGen {
                     content.append("import org.simantics.db.request.ExternalRead;\n");
                     content.append("import org.simantics.db.request.MultiRead;\n");
                     content.append("import org.simantics.db.request.Read;\n");
->>>>>>> 82fa68e Generate parts of db client query code
                     content.append("\n");
                     
                     content.append("public class QueryCache extends QueryCacheBase {\n");                    
index 91faecfb752986a6eb1694f4d70e2b671271b5f8..a3d3c630e1677a4cd029fa0ac0fb6c66aa02e4a0 100644 (file)
@@ -1653,29 +1653,11 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
                             request.perform(newGraph, wrap);
                             wrap.get();
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
-=======
 
                         } catch (DatabaseException e) {
 
                                                        Logger.defaultLogError(e);
 
-//                             wrap.exception(newGraph, t);
-//                            wrapper.exception(newGraph, t);
-//                            newGraph.waitAsync(request);
->>>>>>> 82fa68e Generate parts of db client query code
-
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
-                        } catch (Throwable t) {
-
-                               wrap.exception(newGraph, t);
-                               
-//                            wrapper.exception(newGraph, t);
-//                            newGraph.waitAsync(request);
-
-
-=======
->>>>>>> 82fa68e Generate parts of db client query code
                         }
 
                     }
index d7b561f8f7f653e4359904f40782d16578d71ac9..71eac90b2b89002e6bfb40bde160a47baf788ec8 100644 (file)
@@ -24,13 +24,9 @@ Require-Bundle:
  org.simantics.document.server.io;visibility:=reexport,
  org.simantics.scl.db;bundle-version="0.1.3",
  org.slf4j.api,
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
- org.simantics.threadlog
-=======
  org.simantics.threadlog,
  org.simantics.simulator.toolkit,
  org.simantics.simulator.toolkit.db;bundle-version="1.0.0";visibility:=reexport
->>>>>>> 82fa68e Generate parts of db client query code
 Bundle-ActivationPolicy: lazy
 Bundle-Activator: org.simantics.document.server.Activator
 Export-Package: org.simantics.document.server,
@@ -38,6 +34,7 @@ Export-Package: org.simantics.document.server,
  org.simantics.document.server.client,
  org.simantics.document.server.handler,
  org.simantics.document.server.request,
- org.simantics.document.server.serverResponse
+ org.simantics.document.server.serverResponse,
+ org.simantics.document.server.state
 Import-Package: org.simantics.layer0.utils.direct
 Bundle-ClassPath: .
index 779cf4fe1381acb5979e541d54fce12047115103..2f4f7eec62c3f887a70d7b8871cea1a347c3ad52 100644 (file)
@@ -6,12 +6,9 @@ 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.GraphSemaphore;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.common.request.AsyncReadRequest;
 import org.simantics.db.exception.DatabaseException;
@@ -82,44 +79,6 @@ public class DocumentRequest extends VariableRead<List<JSONObject>> {
                        System.out.println("               " + node.getURI(graph));
                }*/
 
-<<<<<<< Upstream, based on branch 'private/antti_threads' of ssh://villberg@gerrit.simantics.org:29418/simantics/platform.git
-               GraphSemaphore done = new GraphSemaphore(graph, 0);
-               
-               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 exception(Throwable t) {
-                                               t.printStackTrace();
-                                               done.release();
-                                       }
-
-                                       @Override
-                                       public boolean isDisposed() {
-                                               return true;
-                                       }
-                                       
-                               });
-                       
-//                 rs.add(graph.syncRequest(new NodeRequest(node), TransientCacheAsyncListener.<JSONObject>instance()));
-                       
-               }
-               
-               try {
-                       done.waitFor(nodes.size());
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       }
-=======
                graph.syncRequest(new AsyncReadRequest() {
                                
                                @Override
@@ -153,7 +112,6 @@ public class DocumentRequest extends VariableRead<List<JSONObject>> {
                                }
                                
                        });
->>>>>>> 82fa68e Generate parts of db client query code
        
                        ArrayList<JSONObject> result = new ArrayList<JSONObject>(rs);
                        Collections.sort(result, new Comparator<JSONObject>() {