X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterSetsSupportImpl2.java;h=6e6140399f28a3b23a921e7e9ed7abb571ba2063;hp=5da4e37615f8c4f2def8e31228b6b1985d7fbbe5;hb=4b3689543c26ac085970dd200218a9a6c122467b;hpb=0580ea8b675c868685993b0780c9ecc31010f681 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java index 5da4e3761..6e6140399 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterSetsSupportImpl2.java @@ -1,86 +1,86 @@ -package fi.vtt.simantics.procore.internal; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -import org.simantics.db.Disposable; -import org.simantics.db.service.ClusterSets; -import org.simantics.db.service.ClusterSetsSupport; - -public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable { - - final private static boolean DEBUG = false; - final private static Map sClusterSets = new HashMap(); - private Path readDirectory; - private Path writeDirectory; - private String databaseId; // Unique identifier for database of session. Initialized in connect. - private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect. - public ClusterSetsSupportImpl2() { - this.databaseId = null; - this.clusterSets = null; - } - - public synchronized void connect(String databaseId) { - assert(null == this.databaseId); - this.databaseId = databaseId; - clusterSets = sClusterSets.get(databaseId); - int count = 1; - if (null == clusterSets) { - clusterSets = new ClusterSets(readDirectory.toFile(), writeDirectory.toFile(), databaseId); - sClusterSets.put(databaseId, clusterSets); - } else { - count = clusterSets.inc(); - } - if (DEBUG) - System.out.println("Starting session " + count + " for database=" + databaseId); - clusterSets.touch(); - } - @Override - public synchronized void dispose() { - if (clusterSets == null) - return; - clusterSets.dispose(); - if (0 >= clusterSets.dec()) { - sClusterSets.remove(databaseId); - if (DEBUG) - System.out.println("Stopping session for database=" + databaseId); - } - clusterSets = null; - } - public synchronized boolean containsKey(long resourceId) { - return clusterSets.containsKey(resourceId); - } - public synchronized Long get(Long resourceId) { - return clusterSets.get(resourceId); - } - public synchronized void put(long resourceId, long clusterId) { - clusterSets.put(resourceId, clusterId); - } - public synchronized void save() throws IOException { - clusterSets.save(); - } - - public synchronized Long getSet(long clusterId) { - return clusterSets.getClusterSet(clusterId); - } - @Override - public void clear() { - clusterSets.clear(); - } - @Override - public void updateWriteDirectory(Path write) { - this.writeDirectory = write; - if(clusterSets != null) { - clusterSets.setWriteDirectory(writeDirectory.toFile()); - clusterSets.touch(); - } - } - - @Override - public void setReadDirectory(Path read) { - this.readDirectory = read; - } - -} +package fi.vtt.simantics.procore.internal; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.Disposable; +import org.simantics.db.service.ClusterSets; +import org.simantics.db.service.ClusterSetsSupport; + +public class ClusterSetsSupportImpl2 implements ClusterSetsSupport, Disposable { + + final private static boolean DEBUG = false; + final private static Map sClusterSets = new HashMap(); + private Path readDirectory; + private Path writeDirectory; + private String databaseId; // Unique identifier for database of session. Initialized in connect. + private ClusterSets clusterSets; // Cluster sets for session. Initialized in connect. + public ClusterSetsSupportImpl2() { + this.databaseId = null; + this.clusterSets = null; + } + + public synchronized void connect(String databaseId) { + assert(null == this.databaseId); + this.databaseId = databaseId; + clusterSets = sClusterSets.get(databaseId); + int count = 1; + if (null == clusterSets) { + clusterSets = new ClusterSets(readDirectory.toFile(), writeDirectory.toFile(), databaseId); + sClusterSets.put(databaseId, clusterSets); + } else { + count = clusterSets.inc(); + } + if (DEBUG) + System.out.println("Starting session " + count + " for database=" + databaseId); + clusterSets.touch(); + } + @Override + public synchronized void dispose() { + if (clusterSets == null) + return; + clusterSets.dispose(); + if (0 >= clusterSets.dec()) { + sClusterSets.remove(databaseId); + if (DEBUG) + System.out.println("Stopping session for database=" + databaseId); + } + clusterSets = null; + } + public synchronized boolean containsKey(long resourceId) { + return clusterSets.containsKey(resourceId); + } + public synchronized Long get(Long resourceId) { + return clusterSets.get(resourceId); + } + public synchronized void put(long resourceId, long clusterId) { + clusterSets.put(resourceId, clusterId); + } + public synchronized void save() throws IOException { + clusterSets.save(); + } + + public synchronized Long getSet(long clusterId) { + return clusterSets.getClusterSet(clusterId); + } + @Override + public void clear() { + clusterSets.clear(); + } + @Override + public void updateWriteDirectory(Path write) { + this.writeDirectory = write; + if(clusterSets != null) { + clusterSets.setWriteDirectory(writeDirectory.toFile()); + clusterSets.touch(); + } + } + + @Override + public void setReadDirectory(Path read) { + this.readDirectory = read; + } + +}