]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/backup/AcornBackupProvider.java
Acorn: Fix WriteRunnable.runReally() and other fixes
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / backup / AcornBackupProvider.java
index 5ea0799d82fd116d2c9467a24a81a47cfeb1e6ac..3977ad73d0d86bb1e2a11dba50899ea3955494a2 100644 (file)
@@ -16,7 +16,9 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
+import org.simantics.acorn.AcornSessionManagerImpl;
 import org.simantics.acorn.GraphClientImpl2;
+import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.backup.BackupException;
 import org.simantics.backup.IBackupProvider;
 import org.simantics.db.server.ProCoreException;
@@ -32,7 +34,12 @@ public class AcornBackupProvider implements IBackupProvider {
     private static final String IDENTIFIER = "AcornBackupProvider";
     private long trId = -1;
     private final Semaphore lock = new Semaphore(1);
+    private final GraphClientImpl2 client;
 
+    public AcornBackupProvider() {
+        this.client = AcornSessionManagerImpl.getInstance().getClient();
+    }
+    
     private static Path getAcornMetadataFile(Path dbFolder) {
         return dbFolder.getParent().resolve(IDENTIFIER);
     }
@@ -42,8 +49,7 @@ public class AcornBackupProvider implements IBackupProvider {
         try {
             if (trId != -1)
                 throw new IllegalStateException(this + " backup provider is already locked");
-            trId = GraphClientImpl2.getInstance().askWriteTransaction(-1)
-                    .getTransactionId();
+            trId = client.askWriteTransaction(-1).getTransactionId();
         } catch (ProCoreException e) {
             e.printStackTrace();
         }
@@ -55,7 +61,6 @@ public class AcornBackupProvider implements IBackupProvider {
         try {
             lock.acquire();
 
-            GraphClientImpl2 client = GraphClientImpl2.getInstance();
             client.makeSnapshot(true);
 
             Path dbDir = client.getDbFolder();
@@ -79,7 +84,7 @@ public class AcornBackupProvider implements IBackupProvider {
             throw new BackupException("Failed to lock Acorn for backup.", e);
         } catch (NumberFormatException e) {
             throw new BackupException("Failed to read Acorn head state file.", e);
-        } catch (IOException e) {
+        } catch (IllegalAcornStateException | IOException e) {
             throw new BackupException("I/O problem during Acorn backup.", e);
         } finally {
             if (releaseLock)
@@ -92,7 +97,7 @@ public class AcornBackupProvider implements IBackupProvider {
         try {
             if (trId == -1)
                 throw new BackupException(this + " backup provider is not locked");
-            GraphClientImpl2.getInstance().endTransaction(trId);
+            client.endTransaction(trId);
             trId = -1;
         } catch (ProCoreException e) {
             throw new BackupException(e);
@@ -105,7 +110,7 @@ public class AcornBackupProvider implements IBackupProvider {
             // 1. Resolve initial backup restore target.
             // This can be DB directory directly or a temporary directory that
             // will replace the DB directory.
-            Path dbRoot = GraphClientImpl2.getInstance().getDbFolder();
+            Path dbRoot = client.getDbFolder();
             Path restorePath = dbRoot;
             if (!Files.exists(dbRoot, LinkOption.NOFOLLOW_LINKS)) {
                 Files.createDirectories(dbRoot);