]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterControlImpl.java
Fail safe import fixes made by Antti
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / ClusterControlImpl.java
1 package fi.vtt.simantics.procore.internal;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
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;
10
11 public class ClusterControlImpl implements ClusterControl {
12
13         final private SessionImplSocket session;
14         
15         ClusterControlImpl(SessionImplSocket session) {
16                 this.session = session;
17         }
18         
19         @Override
20         public ClusterCollectorPolicy setPolicy(ClusterCollectorPolicy newPolicy) {
21                 return session.clusterTable.collector.setPolicy(newPolicy);
22         }
23         
24     @Override
25     public int flushClusters() {
26         session.clusterTable.gc();
27         System.gc();
28         System.gc();
29         return session.clusterTable.size();
30     }
31
32
33     @Override
34     public int collectClusters(int desiredBytes) {
35         session.clusterTable.collector.collect(desiredBytes);
36         return 0;
37     }
38
39     @Override
40     public int gc(ReadGraph graph) {
41         session.clusterTable.collector.collect();
42         return 0;
43     }
44     
45     @Override
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);
50         return 0;
51     }
52
53     static class ClusterStateImpl implements ClusterState {
54         public Set<CollectorCluster> ids = new HashSet<CollectorCluster>();
55     }
56     
57     @Override
58     public ClusterState getClusterState() {
59         return session.clusterTable.getState();
60     }
61     
62     @Override
63     public void restoreClusterState(ClusterState state) {
64         session.clusterTable.restoreState((ClusterStateImpl)state);
65     }
66     
67     @Override
68     public int used() {
69         return (int)session.clusterTable.getSizeInBytes();
70     }
71
72 }