1 package fi.vtt.simantics.procore.internal;
3 import java.util.HashSet;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.service.ClusterCollectorPolicy;
8 import org.simantics.db.service.ClusterCollectorPolicy.CollectorCluster;
9 import org.simantics.db.service.ClusterControl;
11 public class ClusterControlImpl implements ClusterControl {
13 final private SessionImplSocket session;
15 ClusterControlImpl(SessionImplSocket session) {
16 this.session = session;
20 public ClusterCollectorPolicy setPolicy(ClusterCollectorPolicy newPolicy) {
21 return session.clusterTable.collector.setPolicy(newPolicy);
25 public int flushClusters() {
26 session.clusterTable.gc();
29 return session.clusterTable.size();
34 public int collectClusters(int desiredBytes) {
35 session.clusterTable.collector.collect(desiredBytes);
40 public int gc(ReadGraph graph) {
41 session.clusterTable.collector.collect();
46 public int gc(ReadGraph graph, int objectiveBytes) {
47 if(objectiveBytes < 0) return gc(graph);
48 if(objectiveBytes > used()) return 0;
49 session.clusterTable.collector.collect(used() - objectiveBytes);
53 static class ClusterStateImpl implements ClusterState {
54 public Set<CollectorCluster> ids = new HashSet<CollectorCluster>();
58 public ClusterState getClusterState() {
59 return session.clusterTable.getState();
63 public void restoreClusterState(ClusterState state) {
64 session.clusterTable.restoreState((ClusterStateImpl)state);
69 return (int)session.clusterTable.getSizeInBytes();