]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PendingTaskSupport.java
Add possibility to bookkeep barrier tracing with env var
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / PendingTaskSupport.java
1 package org.simantics.db.impl.query;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.db.impl.query.QueryProcessor.SessionTask;
7
8 /*
9  * Support class for queuing pending tasks to be executed when result gets ready
10  */
11 public class PendingTaskSupport {
12
13     private ArrayList<SessionTask> pendingTasks;
14     private IPending pending;
15     
16     public PendingTaskSupport(IPending pending) {
17         this.pending = pending;
18     }
19     
20     /*
21      * We assume here that the associated IPending performs this atomically
22      * The caller is responsible for execution of the returned task after the critical section
23      */
24     public boolean executeWhenResultIsAvailable(SessionTask task) {
25         if(pending.isPending()) {
26             if(pendingTasks == null)
27                 pendingTasks = new ArrayList<SessionTask>();
28             pendingTasks.add(task);
29             return false;
30         } else {
31             return true;
32         }
33     }
34
35     /*
36      * We assume here that the associated IPending performs this atomically after changing the pending result
37      * The caller is responsible for execution of the returned task after the critical section
38      */
39     public Collection<SessionTask> executePending() {
40         ArrayList<SessionTask> ret = pendingTasks;
41         pendingTasks = null;
42         return ret;
43     }
44
45 }