implement DEV workspace and project automation authority
This commit is contained in:
@@ -39,6 +39,9 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
private final String summary;
|
||||
private final Callable<R> operation;
|
||||
private final CompletableFuture<R> completion = new CompletableFuture<>();
|
||||
private final CompletableFuture<Void> termination = new CompletableFuture<>();
|
||||
private final Object workerLifecycle = new Object();
|
||||
private boolean started;
|
||||
private final CopyOnWriteArrayList<Consumer<OperationSnapshot>> subscribers = new CopyOnWriteArrayList<>();
|
||||
private final AtomicReference<OperationSnapshot> snapshot;
|
||||
private volatile Future<?> task;
|
||||
@@ -62,12 +65,19 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}) {
|
||||
@Override public void run() {
|
||||
synchronized (workerLifecycle) { started = true; }
|
||||
try { super.run(); }
|
||||
finally { termination.complete(null); }
|
||||
}
|
||||
};
|
||||
task = submitted;
|
||||
try {
|
||||
transition(OperationState.RUNNING, summary);
|
||||
executor.execute(submitted);
|
||||
} catch (RuntimeException failure) {
|
||||
termination.complete(null);
|
||||
if (transitionTerminal(OperationState.FAILED, failureSummary(failure))) {
|
||||
completion.completeExceptionally(failure);
|
||||
}
|
||||
@@ -89,6 +99,8 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
return completion;
|
||||
}
|
||||
|
||||
@Override public CompletionStage<Void> termination() { return termination; }
|
||||
|
||||
@Override
|
||||
public boolean cancel() {
|
||||
while (true) {
|
||||
@@ -99,8 +111,9 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
final OperationSnapshot cancelled = new OperationSnapshot(id, OperationState.CANCELLED, Instant.now(), summary);
|
||||
if (snapshot.compareAndSet(current, cancelled)) {
|
||||
final Future<?> submitted = task;
|
||||
if (submitted != null) {
|
||||
submitted.cancel(true);
|
||||
synchronized (workerLifecycle) {
|
||||
if (submitted != null) submitted.cancel(true);
|
||||
if (!started) termination.complete(null);
|
||||
}
|
||||
completion.cancel(false);
|
||||
publish(cancelled);
|
||||
|
||||
Reference in New Issue
Block a user