1 package org.simantics.db.common;
\r
3 import org.simantics.db.ReadGraph;
\r
4 import org.simantics.db.service.QueryControl;
\r
6 public class QueryMemoryWatcher {
\r
8 final ReadGraph graph;
\r
9 final QueryControl support;
\r
11 final long baseline;
\r
12 final long highLimit;
\r
13 final long lowLimit;
\r
14 boolean collecting = false;
\r
16 public QueryMemoryWatcher(ReadGraph graph, int allowedQueries) {
\r
17 this(graph, allowedQueries, 0.5, 10);
\r
20 public QueryMemoryWatcher(ReadGraph graph, int allowedQueries, double ratio, int stopTime) {
\r
21 this.support = graph.getService(QueryControl.class);
\r
22 baseline = support.count();
\r
23 highLimit = baseline + allowedQueries;
\r
24 lowLimit = baseline + (int)(allowedQueries*ratio);
\r
27 //System.err.println("QueryMemoryWatcher started with " + baseline + " queries.");
\r
30 public void maintain() {
\r
31 long current = support.count();
\r
33 if(current > lowLimit) support.gc(graph, stopTime);
\r
35 // System.err.println("QueryMemoryWatcher stops collecting");
\r
39 if(current > highLimit) {
\r
40 // System.err.println("QueryMemoryWatcher starts collecting");
\r