]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java
Still working for multiple readers
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / SessionImplSocket.java
index b7adbe49bd40c5466fe7a039eb7511ffa71c6b93..cf50a09b526b68278147ba44300efe541cd6732d 100644 (file)
@@ -50,6 +50,7 @@ import org.simantics.db.authentication.UserAuthenticationAgent;
 import org.simantics.db.authentication.UserAuthenticator;
 import org.simantics.db.common.Indexing;
 import org.simantics.db.common.TransactionPolicyRelease;
+import org.simantics.db.common.procedure.BlockingAsyncProcedure;
 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncListener;
@@ -89,6 +90,8 @@ import org.simantics.db.impl.graph.WriteSupport;
 import org.simantics.db.impl.internal.RandomAccessValueSupport;
 import org.simantics.db.impl.procedure.ResultCallWrappedQueryProcedure4;
 import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
+import org.simantics.db.impl.query.QueryCache;
+import org.simantics.db.impl.query.QueryCacheBase;
 import org.simantics.db.impl.query.QueryProcessor;
 import org.simantics.db.impl.query.QueryProcessor.SessionRead;
 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
@@ -1496,9 +1499,9 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
         assert (request != null);
         assert (procedure != null);
 
-        int thread = request.hashCode() & queryProvider2.THREAD_MASK;
+        //int thread = request.hashCode() & queryProvider2.THREAD_MASK;
 
-        requestManager.scheduleRead(new SessionRead(request, throwable, notify, thread, thread) {
+        requestManager.scheduleRead(new SessionRead(request, throwable, notify, queryProvider2.THREAD_MASK + 1, -1) {
 
             @Override
             public void run(int thread) {
@@ -1514,7 +1517,8 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                     if (listener != null) {
 
                        try {
-                               newGraph.processor.query(newGraph, request, null, new AsyncProcedure<T>() {
+                               
+                               AsyncProcedure ap = new AsyncProcedure<T>() {
 
                                        @Override
                                        public void exception(AsyncReadGraph graph, Throwable t) {
@@ -1532,7 +1536,10 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                                                procedure.execute(graph, t);
                                        }
 
-                               }, listener);
+                               };
+                               
+                               QueryCache.runnerReadEntry(newGraph, request, null, listener, ap, true);
+                               
                        } catch (Throwable t) {
                            // This is handled by the AsyncProcedure
                                //Logger.defaultLogError("Internal error", t);
@@ -1626,27 +1633,30 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
                     if (listener != null) {
 
                         try {
-                                                       newGraph.processor.query(newGraph, request, null, procedure, listener);
+                               QueryCacheBase.resultAsyncReadEntry(newGraph, request, null, listener, procedure);
+                               //QueryCache.runnerAsyncReadEntry(newGraph, request, null, listener, procedure, true);
+                                                       //newGraph.processor.query(newGraph, request, null, procedure, listener);
                                                } catch (DatabaseException e) {
                                                        Logger.defaultLogError(e);
                                                }
 
                     } else {
 
-                        final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
-                                procedure, "request");
+//                        final ResultCallWrappedSingleQueryProcedure4<T> wrapper = new ResultCallWrappedSingleQueryProcedure4<T>(
+//                                procedure, "request");
 
-                        try {
+                       BlockingAsyncProcedure<T> wrap = new BlockingAsyncProcedure<T>(procedure, request);
 
-//                            newGraph.state.barrier.inc();
-
-                            request.perform(newGraph, wrapper);
+                       try {
 
-//                            newGraph.waitAsync(request);
+                            request.perform(newGraph, wrap);
+                            wrap.get();
 
                         } catch (Throwable t) {
 
-                            wrapper.exception(newGraph, t);
+                               wrap.exception(newGraph, t);
+                               
+//                            wrapper.exception(newGraph, t);
 //                            newGraph.waitAsync(request);
 
 
@@ -1744,23 +1754,30 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
                     if (listener != null) {
 
-                        newGraph.processor.query(newGraph, request, null, new Procedure<T>() {
-
-                            @Override
-                            public void exception(Throwable t) {
-                                procedure.exception(t);
-                                if(throwable != null) {
-                                    throwable.set(t);
-                                }
-                            }
-
-                            @Override
-                            public void execute(T t) {
-                                if(result != null) result.set(t);
-                                procedure.execute(t);
-                            }
-
-                        }, listener);
+                        try {
+                            QueryCacheBase.resultExternalReadEntry(newGraph, request, null, listener, procedure);
+                        } catch (DatabaseException e) {
+                            Logger.defaultLogError(e);
+                        }
+                        
+                        
+//                        newGraph.processor.query(newGraph, request, null, new Procedure<T>() {
+//
+//                            @Override
+//                            public void exception(Throwable t) {
+//                                procedure.exception(t);
+//                                if(throwable != null) {
+//                                    throwable.set(t);
+//                                }
+//                            }
+//
+//                            @Override
+//                            public void execute(T t) {
+//                                if(result != null) result.set(t);
+//                                procedure.execute(t);
+//                            }
+//
+//                        }, listener);
 
 //                        newGraph.waitAsync(request);
 
@@ -3509,7 +3526,7 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule
 
     public int getAmountOfQueryThreads() {
         // This must be a power of two
-        return 4;
+        return 16;
 //        return Integer.highestOneBit(Runtime.getRuntime().availableProcessors());
     }