X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FPendingTaskSupport.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FPendingTaskSupport.java;h=f63bad581695656ff9b367de74129981b1c0311c;hb=26b755c7e98b7bb3d9038abba139bef0e71f6607;hp=0000000000000000000000000000000000000000;hpb=501ad95ad5ca980ef4c6e65af1451a0d7b63cddc;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PendingTaskSupport.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PendingTaskSupport.java new file mode 100644 index 000000000..f63bad581 --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PendingTaskSupport.java @@ -0,0 +1,45 @@ +package org.simantics.db.impl.query; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.impl.query.QueryProcessor.SessionTask; + +/* + * Support class for queuing pending tasks to be executed when result gets ready + */ +public class PendingTaskSupport { + + private ArrayList pendingTasks; + private IPending pending; + + public PendingTaskSupport(IPending pending) { + this.pending = pending; + } + + /* + * We assume here that the associated IPending performs this atomically + * The caller is responsible for execution of the returned task after the critical section + */ + public boolean executeWhenResultIsAvailable(SessionTask task) { + if(pending.isPending()) { + if(pendingTasks == null) + pendingTasks = new ArrayList(); + pendingTasks.add(task); + return false; + } else { + return true; + } + } + + /* + * We assume here that the associated IPending performs this atomically after changing the pending result + * The caller is responsible for execution of the returned task after the critical section + */ + public Collection executePending() { + ArrayList ret = pendingTasks; + pendingTasks = null; + return ret; + } + +}