]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionRequestManager.java
Work in progress
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / SessionRequestManager.java
index 0ec6387ae941b0e9cb9c6358282c3b3849ff9d0d..3209961ed61519ac4e22ba100f20ff9882cbd1be 100644 (file)
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.LinkedList;
 
+import org.simantics.db.Disposable;
 import org.simantics.db.Resource;
 import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.CancelTransactionException;
@@ -114,7 +115,7 @@ public class SessionRequestManager {
        
        public synchronized void startRead(int thread, final SessionRead task) {
                
-               session.queryProvider2.scheduleAlways(thread, new SessionTask(task.object, task.thread, task.syncCaller) {
+               session.queryProvider2.schedule(new SessionTask(true) {
 
                        @Override
             public void run(int thread) {
@@ -138,7 +139,7 @@ public class SessionRequestManager {
        
        public synchronized void startReadUpdate(int thread) {
                
-               session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) {
+               session.queryProvider2.schedule(new SessionTask(true) {
 
                        @Override
                        public void run(int thread) {
@@ -169,7 +170,7 @@ public class SessionRequestManager {
 
        public synchronized void startWrite(int thread, final SessionTask task) {
                
-               session.queryProvider2.scheduleAlways(thread, new SessionTask((WriteTraits)task.object, task.thread) {
+               session.queryProvider2.schedule(new SessionTask(true) {
 
                        @Override
                        public void run(int thread) {
@@ -191,7 +192,7 @@ public class SessionRequestManager {
 
        public synchronized void startWriteUpdate(int thread) {
                
-               session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) {
+               session.queryProvider2.schedule(new SessionTask(true) {
 
                        @Override
                        public void run(int thread) {
@@ -213,6 +214,7 @@ public class SessionRequestManager {
                        } else {
                            throw new UnsupportedOperationException("delayedWriteState may only exist when request fails.");
                        }
+                       Disposable.safeDispose(session.clientChanges);
                        session.clientChanges = new ClientChangesImpl(session);
                                        delayedState.finish();
                                        return;
@@ -222,6 +224,9 @@ public class SessionRequestManager {
                                if(!session.state.isAlive()) return;
 
                                WriteState<?> writeState = session.writeState;
+                               
+                               assert(writeState != null);
+                               
                                WriteGraphImpl graph = writeState.getGraph();
 
                                if(writeState.isExcepted()) {
@@ -242,6 +247,7 @@ public class SessionRequestManager {
 
                                }
 
+                               Disposable.safeDispose(session.clientChanges);
                                session.clientChanges = new ClientChangesImpl(session);
 
                                WriteState<?> state = session.writeState;
@@ -287,7 +293,7 @@ public class SessionRequestManager {
                        if (!reads.isEmpty()) {
 
                                final SessionRead read = reads.poll();
-                               session.queryProvider2.scheduleAlways(thread, new SessionTask(read.object, read.thread, read.syncCaller) {
+                               session.queryProvider2.schedule(new SessionTask(true) {
 
                                        @Override
                                        public void run(int thread) {
@@ -315,7 +321,9 @@ public class SessionRequestManager {
                        
                } else {
 
-                   throw new IllegalStateException("State in ceased should be WRITE or READ or INIT (was " + state + ")"); 
+                       // Spurious wakeup
+                       
+                   //throw new IllegalStateException("State in ceased should be WRITE or READ or INIT (was " + state + ")"); 
                        
                }
                
@@ -326,7 +334,7 @@ public class SessionRequestManager {
                assert(State.INIT != state);
                
                if(State.READ == state) {
-                       session.queryProvider2.schedule(Integer.MIN_VALUE, new SessionTask(task.object, task.thread, task.syncCaller) {
+                       session.queryProvider2.schedule(new SessionTask(true) {
 
                                @Override
                                public void run(int thread) {
@@ -368,6 +376,8 @@ public class SessionRequestManager {
 
                boolean inUpdate = state == State.WRITE_UPDATE;
 
+               //System.err.println("schedule write " + task);
+               
                assert(State.INIT != state);
                //task.combine = combine != null ? combine : inUpdate;
                if(State.IDLE == state) {