]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java
General event listening interface for DB and purge events.
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / GraphClientImpl2.java
index a0c2ef860ba0353b6a1eb7ea0feabe605efb2a63..172fdd103150f28b88fac4ce604a74723e49b504 100644 (file)
@@ -17,6 +17,8 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -45,18 +47,23 @@ import org.simantics.db.exception.SDBException;
 import org.simantics.db.server.ProCoreException;
 import org.simantics.db.service.ClusterSetsSupport;
 import org.simantics.db.service.ClusterUID;
+import org.simantics.db.service.EventSupport;
 import org.simantics.db.service.LifecycleSupport;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.logging.TimeLogger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import fi.vtt.simantics.procore.internal.EventSupportImpl;
 import gnu.trove.map.hash.TLongObjectHashMap;
 
 public class GraphClientImpl2 implements Database.Session {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(GraphClientImpl2.class);
        public static final boolean DEBUG = false;
+       
+       public static final String CLOSE = "close";
+       public static final String PURGE = "purge";
 
        final ClusterManager clusters;
 
@@ -69,6 +76,7 @@ public class GraphClientImpl2 implements Database.Session {
        private ServiceLocator locator;
        private FileCache fileCache;
        private MainProgram mainProgram;
+       private EventSupportImpl eventSupport;
 
        private static class ClientThreadFactory implements ThreadFactory {
 
@@ -102,6 +110,8 @@ public class GraphClientImpl2 implements Database.Session {
            cssi.updateWriteDirectory(clusters.workingDirectory);
            mainProgram = new MainProgram(this, clusters);
            executor.execute(mainProgram);
+           eventSupport = (EventSupportImpl)locator.getService(EventSupport.class);
+           
        }
 
        public Path getDbFolder() {
@@ -216,6 +226,7 @@ public class GraphClientImpl2 implements Database.Session {
                                throw new ProCoreException(e1);
                        }
                        closed = true;
+                       eventSupport.fireEvent(CLOSE, null);
                }
                //impl.close();
        }
@@ -797,8 +808,10 @@ public class GraphClientImpl2 implements Database.Session {
                                        unexpectedClose = true;
                                } finally {
                                        try {
-                                               if(tr != null)
+                                               if(tr != null) {
                                                        endTransaction(tr.getTransactionId());
+                                                       eventSupport.fireEvent(PURGE, null);
+                                               }
                                                if (unexpectedClose) {
                                                        LifecycleSupport support = getServiceLocator().getService(LifecycleSupport.class);
                                                        try {