Search in sources :

Example 1 with GridBusyLock

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;
}
Also used : GridBusyLock(org.apache.ignite.internal.util.GridBusyLock) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 2 with GridBusyLock

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);
    });
}
Also used : GridBusyLock(org.apache.ignite.internal.util.GridBusyLock)

Example 3 with GridBusyLock

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.");
}
Also used : GridBusyLock(org.apache.ignite.internal.util.GridBusyLock)

Aggregations

GridBusyLock (org.apache.ignite.internal.util.GridBusyLock)3 CompletableFuture (java.util.concurrent.CompletableFuture)1