X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FDocumentHistoryCollector.java;h=9d29ef9c7544d2b9b5226215a2c385821d020e4d;hp=b759d38b95b15586d77764d6f8a2d9e98438d5cb;hb=ae2e31aa5eb35410e5b2ce222d42421154f3fecc;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentHistoryCollector.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentHistoryCollector.java index b759d38b9..9d29ef9c7 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentHistoryCollector.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentHistoryCollector.java @@ -1,62 +1,62 @@ -package org.simantics.document.server; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import org.simantics.db.procedure.Listener; -import org.simantics.utils.datastructures.Pair; - -import gnu.trove.map.hash.THashMap; - -public class DocumentHistoryCollector { - - static Map histories = new THashMap(); - - private static DocumentHistory getHistory(String location, boolean create) { - - synchronized(histories) { - - DocumentHistory history = histories.get(location); - if(history == null && create) { - history = new DocumentHistory(); - pruneHistories(); - histories.put(location, history); - } - return history; - - } - - } - - private static void pruneHistories() { - synchronized (histories) { - // remove histories with no listeners - Iterator> iter = histories.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); - DocumentHistory entryHistory = entry.getValue(); - synchronized(entryHistory) { - if (!entryHistory.hasListeners()) { - iter.remove(); - } - } - } - } - } - - public static Pair> readChanges(String location, int sequenceNumber) { - DocumentHistory history = getHistory(location, false); - if (history != null) { - return history.readChanges(sequenceNumber); - } else { - return null; - } - } - - public static Pair> getContent(Listener listener, String location, int sequenceNumber) { - DocumentHistory history = getHistory(location, true); - return history.getContent(listener, location, sequenceNumber); - } +package org.simantics.document.server; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import org.simantics.db.procedure.Listener; +import org.simantics.utils.datastructures.Pair; + +import gnu.trove.map.hash.THashMap; + +public class DocumentHistoryCollector { + + static Map histories = new THashMap(); + + private static DocumentHistory getHistory(String location, boolean create) { + + synchronized(histories) { + + DocumentHistory history = histories.get(location); + if(history == null && create) { + history = new DocumentHistory(); + pruneHistories(); + histories.put(location, history); + } + return history; + + } + + } + + private static void pruneHistories() { + synchronized (histories) { + // remove histories with no listeners + Iterator> iter = histories.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + DocumentHistory entryHistory = entry.getValue(); + synchronized(entryHistory) { + if (!entryHistory.hasListeners()) { + iter.remove(); + } + } + } + } + } + + public static Pair> readChanges(String location, int sequenceNumber) { + DocumentHistory history = getHistory(location, false); + if (history != null) { + return history.readChanges(sequenceNumber); + } else { + return null; + } + } + + public static Pair> getContent(Listener listener, String location, int sequenceNumber) { + DocumentHistory history = getHistory(location, true); + return history.getContent(listener, location, sequenceNumber); + } } \ No newline at end of file