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;
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.DataContainer;
import org.simantics.utils.datastructures.Pair;
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;
private ServiceLocator locator;
private FileCache fileCache;
private MainProgram mainProgram;
+ private EventSupportImpl eventSupport;
private static class ClientThreadFactory implements ThreadFactory {
cssi.updateWriteDirectory(clusters.workingDirectory);
mainProgram = new MainProgram(this, clusters);
executor.execute(mainProgram);
+ eventSupport = (EventSupportImpl)locator.getService(EventSupport.class);
+
}
public Path getDbFolder() {
throw new ProCoreException(e1);
}
closed = true;
+ eventSupport.fireEvent(CLOSE, null);
}
//impl.close();
}
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 {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package fi.vtt.simantics.procore.internal;
+
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.simantics.db.service.EventSupport;
+
+/**
+ * Simple implementation for Event Support.
+ *
+ * Note: for more extended / complicated scenarios, we could use org.simantics.utils.threads.SyncListenerList.
+ *
+ * @author luukkainen
+ *
+ */
+public class EventSupportImpl implements EventSupport {
+
+ private CopyOnWriteArrayList<EventListener> listeners = new CopyOnWriteArrayList<>();
+
+ @Override
+ public synchronized void addListener(EventListener l) {
+ listeners.add(l);
+ }
+
+ @Override
+ public synchronized void removeListener(EventListener l) {
+ listeners.remove(l);
+ }
+
+ public void fireEvent(String type, Object data) {
+ for (EventListener l : listeners) {
+ l.event(type, data);
+ }
+ }
+
+}
import org.simantics.db.service.CollectionSupport;
import org.simantics.db.service.DebugSupport;
import org.simantics.db.service.DirectQuerySupport;
+import org.simantics.db.service.EventSupport;
import org.simantics.db.service.GraphChangeListenerSupport;
import org.simantics.db.service.InitSupport;
import org.simantics.db.service.LifecycleSupport;
serviceLocator.registerService(ExternalValueSupport.class, new ExternalValueSupportImpl(this));
serviceLocator.registerService(RandomAccessValueSupport.class, new RandomAccessValueSupportImpl());
serviceLocator.registerService(ServiceActivityMonitor.class, new ServiceActivityMonitorImpl());
+ serviceLocator.registerService(EventSupport.class, new EventSupportImpl());
ServiceActivityUpdaterForWriteTransactions.register(this);
this.virtualGraphServerSupport = new VirtualGraphServerSupportImpl(this, t);
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.service;
+
+/**
+ * Interface for listening DB events.
+ *
+ * Note: At the moment, only "purge" is supported.
+ *
+ * @author luukkainen
+ *
+ */
+public interface EventSupport {
+
+ public void addListener(EventListener l);
+
+ public void removeListener(EventListener l);
+
+
+ public interface EventListener extends java.util.EventListener {
+ /**
+ *
+ * @param type Type of the event.
+ * @param data Data related to the event, may be null.
+ */
+ public void event(String type, Object data);
+ }
+}