X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.acorn%2Fsrc%2Forg%2Fsimantics%2Facorn%2FGraphClientImpl2.java;h=cde943464d89fcb928c1753795e2254520bebaf7;hb=0a3ac110124135491d244cddf50be728125aa02a;hp=05f9c8de00b66c315f9a6c5317026f28c0c664cb;hpb=06718abb2b3cc780748553811c4857c165499809;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java index 05f9c8de0..cde943464 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java @@ -21,6 +21,7 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; +import org.simantics.acorn.MainProgram.MainProgramRunnable; import org.simantics.acorn.exception.AcornAccessVerificationException; import org.simantics.acorn.exception.IllegalAcornStateException; import org.simantics.acorn.internal.ClusterChange; @@ -122,10 +123,10 @@ public class GraphClientImpl2 implements Database.Session { mainProgram.mutex.release(); } } catch (IllegalAcornStateException | ProCoreException e) { - Logger.defaultLogError(e); + Logger.defaultLogError("Snapshotting failed", e); unexpectedClose = true; } catch (InterruptedException e) { - Logger.defaultLogError(e); + Logger.defaultLogError("Snapshotting interrupted", e); } finally { try { if(tr != null) @@ -135,11 +136,11 @@ public class GraphClientImpl2 implements Database.Session { try { support.close(); } catch (DatabaseException e1) { - Logger.defaultLogError(e1); + Logger.defaultLogError("Failed to close database as a safety measure due to failed snapshotting", e1); } } } catch (ProCoreException e) { - Logger.defaultLogError(e); + Logger.defaultLogError("Failed to end snapshotting write transaction", e); } } } @@ -239,18 +240,17 @@ public class GraphClientImpl2 implements Database.Session { @Override public long cancelCommit(long transactionId, long changeSetId, byte[] metadata, OnChangeSetUpdate onChangeSetUpdate) throws ProCoreException { - UnsupportedOperationException e = new UnsupportedOperationException("org.simantics.acorn.GraphClientImpl2.cancelCommit() is not supported operation! Closing down to prevent further havoc"); - clusters.notSafeToMakeSnapshot(new IllegalAcornStateException(e)); - throw e; -// System.err.println("GraphClientImpl2.cancelCommit() called!! this is experimental and might cause havoc!"); -// try { -// undo(new long[] {changeSetId}, onChangeSetUpdate); -// } catch (SDBException e) { -// e.printStackTrace(); -// throw new ProCoreException(e); -// } -// clusters.state.headChangeSetId++; -// return clusters.state.headChangeSetId; + // Accept and finalize current transaction and then undo it + acceptCommit(transactionId, changeSetId, metadata); + + try { + undo(new long[] {changeSetId+1}, onChangeSetUpdate); + clusters.state.headChangeSetId++; + return clusters.state.headChangeSetId; + } catch (SDBException e) { + Logger.defaultLogError("Failed to undo cancelled transaction", e); + throw new ProCoreException(e); + } } @Override @@ -604,89 +604,111 @@ public class GraphClientImpl2 implements Database.Session { clusters.clusterLRU.releaseMutex(); } } - + @Override public boolean undo(long[] changeSetIds, OnChangeSetUpdate onChangeSetUpdate) throws SDBException { - try { - final ArrayList> clusterChanges = new ArrayList>(); - - UndoClusterSupport support = new UndoClusterSupport(clusters); - - final int changeSetId = clusters.state.headChangeSetId; - - if(ClusterUpdateProcessorBase.DEBUG) - System.err.println(" === BEGIN UNDO ==="); - - for(int i=0;i ccss = clusters.getChanges(id); - - for(int j=0;j pair = clusterChanges.get(i); - - final ClusterUID cuid = pair.first; - final byte[] data = pair.second; - - onChangeSetUpdate.onChangeSetUpdate(new ChangeSetUpdate() { - - @Override - public long getChangeSetId() { - return changeSetId; - } - - @Override - public int getChangeSetIndex() { - return 0; - } - - @Override - public int getNumberOfClusterChangeSets() { - return clusterChanges.size(); - } - - @Override - public int getIndexOfClusterChangeSet() { - return changeSetIndex; - } - - @Override - public byte[] getClusterId() { - return cuid.asBytes(); - } - - @Override - public boolean getNewCluster() { - return false; - } - - @Override - public byte[] getData() { - return data; - } - - }); - } - } catch (AcornAccessVerificationException | IllegalAcornStateException e1) { - throw new ProCoreException(e1); - } + + Exception exception = mainProgram.runIdle(new MainProgramRunnable() { + + @Override + public void run() throws Exception { + + try { + + final ArrayList> clusterChanges = new ArrayList>(); + + UndoClusterSupport support = new UndoClusterSupport(clusters); + + final int changeSetId = clusters.state.headChangeSetId; + + if(ClusterUpdateProcessorBase.DEBUG) + System.err.println(" === BEGIN UNDO ==="); + + for(int i=0;i ccss = clusters.getChanges(id); + + for(int j=0;j pair = clusterChanges.get(i); + + final ClusterUID cuid = pair.first; + final byte[] data = pair.second; + + onChangeSetUpdate.onChangeSetUpdate(new ChangeSetUpdate() { + + @Override + public long getChangeSetId() { + return changeSetId; + } + + @Override + public int getChangeSetIndex() { + return 0; + } + + @Override + public int getNumberOfClusterChangeSets() { + return clusterChanges.size(); + } + + @Override + public int getIndexOfClusterChangeSet() { + return changeSetIndex; + } + + @Override + public byte[] getClusterId() { + return cuid.asBytes(); + } + + @Override + public boolean getNewCluster() { + return false; + } + + @Override + public byte[] getData() { + return data; + } + + }); + } + } catch (AcornAccessVerificationException | IllegalAcornStateException e1) { + throw new ProCoreException(e1); + } + + } + + @Override + public void done() { + + } + + }); + + if(exception instanceof SDBException) throw (SDBException)exception; + else if(exception != null) throw new IllegalAcornStateException(exception); + return false; + } public ServiceLocator getServiceLocator() {