-package org.simantics.document.server;\r
-\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-import gnu.trove.map.hash.THashMap;\r
-\r
-public class DocumentHistoryCollector {\r
-\r
- static Map<String, DocumentHistory> histories = new THashMap<String, DocumentHistory>();\r
-\r
- private static DocumentHistory getHistory(String location, boolean create) {\r
-\r
- synchronized(histories) {\r
-\r
- DocumentHistory history = histories.get(location);\r
- if(history == null && create) {\r
- history = new DocumentHistory();\r
- pruneHistories();\r
- histories.put(location, history);\r
- }\r
- return history;\r
- \r
- }\r
-\r
- }\r
- \r
- private static void pruneHistories() {\r
- synchronized (histories) {\r
- // remove histories with no listeners\r
- Iterator<Map.Entry<String, DocumentHistory>> iter = histories.entrySet().iterator();\r
- while (iter.hasNext()) {\r
- Entry<String, DocumentHistory> entry = iter.next();\r
- DocumentHistory entryHistory = entry.getValue();\r
- synchronized(entryHistory) {\r
- if (!entryHistory.hasListeners()) {\r
- iter.remove();\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- public static Pair<Integer, Collection<JSONObject>> readChanges(String location, int sequenceNumber) {\r
- DocumentHistory history = getHistory(location, false);\r
- if (history != null) {\r
- return history.readChanges(sequenceNumber);\r
- } else {\r
- return null;\r
- }\r
- }\r
-\r
- public static Pair<Integer, Collection<JSONObject>> getContent(Listener<Integer> listener, String location, int sequenceNumber) {\r
- DocumentHistory history = getHistory(location, true);\r
- return history.getContent(listener, location, sequenceNumber);\r
- }\r
+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<String, DocumentHistory> histories = new THashMap<String, DocumentHistory>();
+
+ 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<Map.Entry<String, DocumentHistory>> iter = histories.entrySet().iterator();
+ while (iter.hasNext()) {
+ Entry<String, DocumentHistory> entry = iter.next();
+ DocumentHistory entryHistory = entry.getValue();
+ synchronized(entryHistory) {
+ if (!entryHistory.hasListeners()) {
+ iter.remove();
+ }
+ }
+ }
+ }
+ }
+
+ public static Pair<Integer, Collection<JSONObject>> readChanges(String location, int sequenceNumber) {
+ DocumentHistory history = getHistory(location, false);
+ if (history != null) {
+ return history.readChanges(sequenceNumber);
+ } else {
+ return null;
+ }
+ }
+
+ public static Pair<Integer, Collection<JSONObject>> getContent(Listener<Integer> listener, String location, int sequenceNumber) {
+ DocumentHistory history = getHistory(location, true);
+ return history.getContent(listener, location, sequenceNumber);
+ }
}
\ No newline at end of file