]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java
Fixing problems in the database unit testing environment with Acorn
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / GraphClientImpl2.java
index dce477ebeae0fdf35d1db078acfd7e6e885ea825..20abf68db0e6853ac882b5df5c22dbf638ef6eb7 100644 (file)
@@ -61,6 +61,7 @@ public class GraphClientImpl2 implements Database.Session {
        private Path dbFolder;
        private final Database database;
        private ServiceLocator locator;
+       private FileCache fileCache;
        private MainProgram mainProgram;
 
        static class ClientThreadFactory implements ThreadFactory {
@@ -85,7 +86,10 @@ public class GraphClientImpl2 implements Database.Session {
            this.database = database;
            this.dbFolder = dbFolder;
            this.locator = locator;
-           this.clusters = new ClusterManager(dbFolder);
+           this.fileCache = new FileCache();
+           // This disposes the cache when the session is shut down 
+           locator.registerService(FileCache.class, fileCache);
+           this.clusters = new ClusterManager(dbFolder, fileCache);
            load();
            ClusterSetsSupport cssi = locator.getService(ClusterSetsSupport.class); 
            cssi.setReadDirectory(clusters.lastSessionDirectory);
@@ -192,7 +196,7 @@ public class GraphClientImpl2 implements Database.Session {
                        try {
                            if (!unexpectedClose)
                                makeSnapshot(true);
-                               
+
                                mainProgram.close();
                                clusters.shutdown();
                                executor.shutdown();
@@ -201,7 +205,13 @@ public class GraphClientImpl2 implements Database.Session {
                                boolean saverTerminated = saver.awaitTermination(500, TimeUnit.MILLISECONDS);
                                
                                System.err.println("executorTerminated=" + executorTerminated + ", saverTerminated=" + saverTerminated);
-                               
+
+                               try {
+                                       clusters.mainState.save(dbFolder);
+                               } catch (IOException e) {
+                                       LOGGER.error("Failed to save " + MainState.MAIN_STATE + " file in database folder " + dbFolder);
+                               }
+
                                mainProgram = null;
                                executor = null;
                                saver = null;