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%2FClusterChangeManager.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterChangeManager.java;h=83088135559fe16603c060a13325436b6e3fbd34;hp=9f203c8af5a1402853fa10593fcaeb5049a1001d;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChangeManager.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChangeManager.java index 9f203c8af..830881355 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChangeManager.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChangeManager.java @@ -1,65 +1,65 @@ -package fi.vtt.simantics.procore.internal; - -import gnu.trove.set.hash.THashSet; - -import java.util.Collection; -import java.util.LinkedList; - -public class ClusterChangeManager { - - final private THashSet clusterChanges = new THashSet(); - final private LinkedList removeList = new LinkedList(); - private int changeCounter = 0; - private int byteLimit = 65536; - - public void checkFlush() { - if(changeCounter < 50) return; - ClusterChange test = removeList.poll(); - if(test == null) return; - if(test.byteIndex > byteLimit) { - test.flushCollect(null); - } else { - removeList.add(test); - } - } - - public void updateChangeCounters() { - changeCounter = clusterChanges.size(); - byteLimit = (100-changeCounter)*ClusterChange.MAX_FIXED_BYTES; - } - - void addChange(ClusterChange change) { - clusterChanges.add(change); - updateChangeCounters(); - } - - Collection get() { - return clusterChanges; - } - - void add(ClusterChange change) { - if(clusterChanges.add(change)) { - removeList.add(change); - } else { - new Exception("trying to add change that already exists").printStackTrace(); - } - updateChangeCounters(); - } - - void remove(Collection changes) { - clusterChanges.removeAll(changes); - removeList.removeAll(changes); - updateChangeCounters(); - } - - int size() { - return clusterChanges.size(); - } - - void clear() { - clusterChanges.clear(); - removeList.clear(); - updateChangeCounters(); - } - -} +package fi.vtt.simantics.procore.internal; + +import gnu.trove.set.hash.THashSet; + +import java.util.Collection; +import java.util.LinkedList; + +public class ClusterChangeManager { + + final private THashSet clusterChanges = new THashSet(); + final private LinkedList removeList = new LinkedList(); + private int changeCounter = 0; + private int byteLimit = 65536; + + public void checkFlush() { + if(changeCounter < 50) return; + ClusterChange test = removeList.poll(); + if(test == null) return; + if(test.byteIndex > byteLimit) { + test.flushCollect(null); + } else { + removeList.add(test); + } + } + + public void updateChangeCounters() { + changeCounter = clusterChanges.size(); + byteLimit = (100-changeCounter)*ClusterChange.MAX_FIXED_BYTES; + } + + void addChange(ClusterChange change) { + clusterChanges.add(change); + updateChangeCounters(); + } + + Collection get() { + return clusterChanges; + } + + void add(ClusterChange change) { + if(clusterChanges.add(change)) { + removeList.add(change); + } else { + new Exception("trying to add change that already exists").printStackTrace(); + } + updateChangeCounters(); + } + + void remove(Collection changes) { + clusterChanges.removeAll(changes); + removeList.removeAll(changes); + updateChangeCounters(); + } + + int size() { + return clusterChanges.size(); + } + + void clear() { + clusterChanges.clear(); + removeList.clear(); + updateChangeCounters(); + } + +}