X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionRequestManager.java;h=fb421b6105ba1e526f6bfcd883b01b1fe41e4287;hp=5bdec52e99cfcb3cdb71010584250904e65ad9ac;hb=HEAD;hpb=09366c7018d046746832e4e7033ca2588455dac2 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionRequestManager.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionRequestManager.java index 5bdec52e9..fb421b610 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionRequestManager.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionRequestManager.java @@ -6,7 +6,6 @@ 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; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.WriteGraphImpl; @@ -16,9 +15,13 @@ import org.simantics.db.impl.query.QueryProcessor.SessionRead; import org.simantics.db.impl.query.QueryProcessor.SessionTask; import org.simantics.db.request.WriteTraits; import org.simantics.utils.datastructures.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SessionRequestManager { + private static final Logger LOGGER = LoggerFactory.getLogger(SessionRequestManager.class); + private static boolean DEBUG = false; enum State { @@ -115,15 +118,15 @@ 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.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { try { transactionState.startReadTransaction(thread); task.run(thread); } catch (Throwable t) { - Logger.defaultLogError(new DatabaseException("Read transaction could not be started", t)); + LOGGER.error("Read transaction could not be started", t); if(task.throwable != null) task.throwable.set(t); state = State.ERROR; @@ -139,17 +142,17 @@ public class SessionRequestManager { public synchronized void startReadUpdate(int thread) { - session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) { + session.queryProvider2.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { session.fireFinishReadTransaction(); try { transactionState.stopReadTransaction(); } catch (DatabaseException e) { - e.printStackTrace(); + LOGGER.error("Read transaction could not be stopped", e); } } @@ -158,28 +161,17 @@ public class SessionRequestManager { } -// public synchronized void stopRead(int thread) { -// -// try { -// transactionState.stopReadTransaction(); -// } catch (DatabaseException e) { -// e.printStackTrace(); -// } -// -// } - public synchronized void startWrite(int thread, final SessionTask task) { - session.queryProvider2.scheduleAlways(thread, new SessionTask((WriteTraits)task.object, task.thread) { + session.queryProvider2.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { try { transactionState.startWriteTransaction(thread); } catch (Throwable t) { - DatabaseException e = new DatabaseException("Write transaction could not be started", t); - Logger.defaultLogError(e); + LOGGER.error("Write transaction could not be started", t); return; } task.run(thread); @@ -192,10 +184,10 @@ public class SessionRequestManager { public synchronized void startWriteUpdate(int thread) { - session.queryProvider2.scheduleAlways(thread, new SessionTask(null, thread) { + session.queryProvider2.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { // Support for DelayedWriteRequest cancels during the // read-only part of the request. @@ -224,13 +216,16 @@ public class SessionRequestManager { if(!session.state.isAlive()) return; WriteState writeState = session.writeState; + + assert(writeState != null); + WriteGraphImpl graph = writeState.getGraph(); if(writeState.isExcepted()) { - + if(!(writeState.exception instanceof CancelTransactionException)) - writeState.exception.printStackTrace(); - + LOGGER.error("Write request failed", writeState.exception); + transactionState.cancelWriteTransaction(graph); } else { @@ -257,20 +252,6 @@ public class SessionRequestManager { } -// public synchronized void stopWrite(int thread) { -// -// session.clientChanges = new ClientChangesImpl(session); -// -// WriteState state = session.writeState; -// -// System.err.println("D"); -// state.finish(); -// System.err.println("E"); -// -// session.writeState = null; -// -// } - public synchronized void ceased(int thread) { if(State.WRITE == state) { @@ -290,10 +271,10 @@ 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.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { read.run(thread); if(read.notify != null) read.notify.release(); } @@ -318,7 +299,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 + ")"); } @@ -329,10 +312,10 @@ 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.scheduleNow(new SessionTask(null) { @Override - public void run(int thread) { + public void run0(int thread) { try { task.run(thread); } finally { @@ -371,6 +354,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) { @@ -401,7 +386,7 @@ public class SessionRequestManager { try { value.second.binaryFile.close(); } catch (IOException e) { - Logger.defaultLogError("I/O exception while closing random access value file " + value.second.binaryFile.file() + " for resource " + value.first , e); + LOGGER.error("I/O exception while closing random access value file " + value.second.binaryFile.file() + " for resource " + value.first , e); } } }