use of org.apache.ignite.internal.util.GridBusyLock in project ignite by apache.
the class BusyExecutor method submit.
/**
* Submit task to execute in thread pool under busy lock.
* Task surrounded with try/catch and if it's complete with any exception - resulting future will return
*
* @param r Task to execute.
* @return Completable future with executed flag in result.
*/
public CompletableFuture<Boolean> submit(Runnable r) {
GridBusyLock lock = busyLock;
CompletableFuture<Boolean> res = new CompletableFuture<>();
if (r instanceof CancellableTask) {
CancellableTask ct = (CancellableTask) r;
res.thenApply(result -> {
cancellableTasks.remove(ct);
return result;
});
cancellableTasks.add(ct);
}
pool.execute(() -> res.complete(busyRun(r, lock)));
return res;
}
use of org.apache.ignite.internal.util.GridBusyLock in project ignite by apache.
the class BusyExecutor method execute.
/**
* Execute cancellable task in thread pool under busy lock. Track task to cancel on executor stop.
*
* @param ct Cancellable task to execute.
*/
public void execute(CancellableTask ct) {
GridBusyLock lock = busyLock;
cancellableTasks.add(ct);
pool.execute(() -> {
busyRun(ct, lock);
cancellableTasks.remove(ct);
});
}
use of org.apache.ignite.internal.util.GridBusyLock in project ignite by apache.
the class BusyExecutor method activate.
/**
* Allow operations.
*/
public synchronized void activate() {
busyLock = new GridBusyLock();
active = true;
if (log.isDebugEnabled())
log.debug("Busy executor " + name + " activated.");
}
Aggregations