1 package fi.vtt.simantics.procore.internal;
3 import gnu.trove.set.hash.THashSet;
5 import java.util.Collection;
6 import java.util.LinkedList;
8 public class ClusterChangeManager {
10 final private THashSet<ClusterChange> clusterChanges = new THashSet<ClusterChange>();
11 final private LinkedList<ClusterChange> removeList = new LinkedList<ClusterChange>();
12 private int changeCounter = 0;
13 private int byteLimit = 65536;
15 public void checkFlush() {
16 if(changeCounter < 50) return;
17 ClusterChange test = removeList.poll();
18 if(test == null) return;
19 if(test.byteIndex > byteLimit) {
20 test.flushCollect(null);
26 public void updateChangeCounters() {
27 changeCounter = clusterChanges.size();
28 byteLimit = (100-changeCounter)*ClusterChange.MAX_FIXED_BYTES;
31 void addChange(ClusterChange change) {
32 clusterChanges.add(change);
33 updateChangeCounters();
36 Collection<ClusterChange> get() {
37 return clusterChanges;
40 void add(ClusterChange change) {
41 if(clusterChanges.add(change)) {
42 removeList.add(change);
44 new Exception("trying to add change that already exists " + change.clusterUID + " " + System.identityHashCode(change.clusterImpl)).printStackTrace();
46 updateChangeCounters();
49 void remove(Collection<ClusterChange> changes) {
50 clusterChanges.removeAll(changes);
51 removeList.removeAll(changes);
52 updateChangeCounters();
56 return clusterChanges.size();
60 clusterChanges.clear();
62 updateChangeCounters();