Skip to content

Commit 1e6cd9f

Browse files
committed
Activate auto querying of all goals
1 parent 1c7f3b3 commit 1e6cd9f

File tree

4 files changed

+36
-52
lines changed

4 files changed

+36
-52
lines changed

server/src/main/java/org/diskproject/server/quering/Match.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,16 @@ private List<WorkflowInstantiation> createWorkflowInstance (WorkflowSeed seed) {
228228
if (queryResult == null || queryVariables == null || !ready || queryResult.size() == 0 || queryVariables.size() == 0) {
229229
return null;
230230
}
231-
List<DataResult> filteredResults = filterQueryResults(selectVariables);
231+
List<DataResult> filteredResults = filterQueryResults(seedVariables);
232+
Set<String> filteredVariables = new HashSet<String>();
233+
for (String varSeed: seedVariables) {
234+
filteredVariables.add(varSeed.substring(1));
235+
}
236+
232237
// One seed can create multiple instances. As the results are a table, we need to aggregate the results.
233238
int runs = 0;
234239
Map<String,Integer> ticks = new HashMap<String,Integer>();
235-
for (String name: this.queryVariables) {
240+
for (String name: filteredVariables) {
236241
ticks.put(name, 0);
237242
String lastValue = null;
238243
boolean isArray = arrayVariables.contains("?" + name);
@@ -276,7 +281,7 @@ private List<WorkflowInstantiation> createWorkflowInstance (WorkflowSeed seed) {
276281
newBindingValues.add(csvURL);
277282
} else if (wfBiding.startsWith("?")) {
278283
String name = wfBiding.substring(1);
279-
if (queryVariables.contains(name)) {
284+
if (filteredVariables.contains(name)) {
280285
if (arrayVariables.contains(wfBiding)) {
281286
//Is array, send a list with all values.
282287
for (DataResult cell: resultsToBind) {

server/src/main/java/org/diskproject/server/repository/DiskRepository.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ public Map<LineOfInquiry, List<Map<String, String>>> getLOIByHypothesisId(String
482482
// return tlois;
483483
//}
484484

485+
public void queryAllGoals () {
486+
for (Goal goal: this.listGoals()) {
487+
String localId = DiskDB.getLocalId(goal.getId());
488+
try {
489+
this.queryGoal(localId);
490+
} catch (Exception e) {
491+
System.err.println("Error querying goal " + localId);
492+
}
493+
}
494+
}
495+
485496
public List<TriggeredLOI> queryGoal (String id) throws Exception, QueryParseException {
486497
System.out.println("Quering goal: " + id);
487498
Goal goal = this.getGoal(id);
@@ -505,7 +516,7 @@ public List<TriggeredLOI> queryGoal (String id) throws Exception, QueryParseExce
505516
String template = loiMatch.createQueryTemplate();
506517
if (dataSource != null && template != null) {
507518
String query = this.getAllPrefixes() + "SELECT DISTINCT " +
508-
String.join(" ", loiMatch.seedVariables)
519+
String.join(" ", loiMatch.selectVariables)
509520
+ " WHERE { \n" + template + "\n}";
510521
String cacheId = dataSource.getId() + "|" + query;
511522
if (!queryCache.containsKey(cacheId)) {
Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,22 @@
11
package org.diskproject.server.threads;
22

3+
import org.diskproject.server.repository.DiskRepository;
4+
35
public class DataThread implements Runnable {
6+
DiskRepository disk;
7+
public DataThread(DiskRepository disk) {
8+
this.disk = disk;
9+
}
410

511
@Override
612
public void run() {
7-
// TODO Auto-generated method stub
8-
throw new UnsupportedOperationException("Unimplemented method 'run'");
13+
System.out.println("[D] Running data monitor thread");
14+
disk.queryAllGoals();
915
}
1016

11-
// All of this needs to be reworked to clear caches and re run queries.
12-
/*public class DataMonitor implements Runnable {
13-
boolean stop;
14-
ScheduledFuture<?> scheduledFuture;
15-
16-
public DataMonitor() {
17-
stop = false;
18-
scheduledFuture = monitor.scheduleWithFixedDelay(this, 0, 1, TimeUnit.DAYS);
17+
public void stop() {
18+
while (!Thread.interrupted()) {
19+
Thread.currentThread().interrupt();
1920
}
20-
21-
public void run() {
22-
System.out.println("[D] Running data monitor thread");
23-
try {
24-
Thread.sleep(5000);
25-
if (stop) {
26-
scheduledFuture.cancel(false);
27-
while (!Thread.currentThread().isInterrupted()) {
28-
Thread.currentThread().interrupt();
29-
}
30-
} else if (!this.equals(dataThread)) {
31-
stop();
32-
return;
33-
} else {
34-
// Re-run all hypothesis FIXME:
35-
// runAllHypotheses("admin");
36-
}
37-
} catch (Exception e) {
38-
scheduledFuture.cancel(false);
39-
while (!Thread.interrupted()) {
40-
stop = true;
41-
Thread.currentThread().interrupt();
42-
}
43-
}
44-
45-
}
46-
47-
public void stop() {
48-
while (!Thread.interrupted()) {
49-
stop = true;
50-
scheduledFuture.cancel(false);
51-
Thread.currentThread().interrupt();
52-
}
53-
}
54-
}*/
55-
21+
}
5622
}

server/src/main/java/org/diskproject/server/threads/ThreadManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,29 @@
1111

1212
import org.diskproject.server.managers.MethodAdapterManager;
1313
import org.diskproject.server.repository.DiskRepository;
14-
import org.diskproject.shared.classes.adapters.MethodAdapter;
1514
import org.diskproject.shared.classes.common.Status;
1615
import org.diskproject.shared.classes.loi.LineOfInquiry;
1716
import org.diskproject.shared.classes.loi.TriggeredLOI;
1817
import org.diskproject.shared.classes.workflow.Execution;
1918
import org.diskproject.shared.classes.workflow.VariableBinding;
2019
import org.diskproject.shared.classes.workflow.WorkflowInstantiation;
2120
import org.diskproject.shared.classes.workflow.WorkflowSeed;
22-
import org.diskproject.shared.classes.workflow.WorkflowVariable;
2321

2422
public class ThreadManager {
2523
protected MethodAdapterManager methodAdapters;
2624
private DiskRepository disk;
2725
protected ScheduledExecutorService monitor;
2826
protected ExecutorService executor;
27+
private DataThread dataThread;
2928

3029
public ThreadManager (MethodAdapterManager methodAdapters, DiskRepository disk) {
3130
this.disk = disk;
3231
this.methodAdapters = methodAdapters;
3332
this.executor = Executors.newFixedThreadPool(2);
3433
this.monitor = Executors.newScheduledThreadPool(0);
34+
35+
this.dataThread = new DataThread(disk);
36+
this.monitor.scheduleWithFixedDelay(this.dataThread, 0, 1, TimeUnit.DAYS);
3537
}
3638

3739
public void shutdownExecutors () {

0 commit comments

Comments
 (0)