Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public interface WorkflowInstance extends WorkflowInstanceData {

boolean resume();

default CompletableFuture<Boolean> suspendFuture() {
return CompletableFuture.completedFuture(suspend());
}

default CompletableFuture<Boolean> cancelFuture() {
return CompletableFuture.completedFuture(cancel());
}

default CompletableFuture<Boolean> resumeFuture() {
return CompletableFuture.completedFuture(resume());
}
Comment thread
fjtirado marked this conversation as resolved.

<T> T addMetadataIfAbsent(String key, Supplier<T> supplier);

void removeMetadata(String key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,29 @@ public String toString() {

@Override
public boolean suspend() {
boolean result = _suspend();
if (result) {
publishEvent(
workflowContext, l -> l.onWorkflowSuspended(new WorkflowSuspendedEvent(workflowContext)));
}
return result;
}

@Override
public CompletableFuture<Boolean> suspendFuture() {
return _suspend()
? publishEvent(
workflowContext,
l -> l.onWorkflowSuspended(new WorkflowSuspendedEvent(workflowContext)))
.thenApply(__ -> true)
: CompletableFuture.completedFuture(false);
}

private boolean _suspend() {
try {
Comment thread
fjtirado marked this conversation as resolved.
statusLock.lock();
if (TaskExecutorHelper.isActive(status.get()) && suspended == null) {
internalSuspend();
publishEvent(
workflowContext,
l -> l.onWorkflowSuspended(new WorkflowSuspendedEvent(workflowContext)));
return true;
} else {
return false;
Expand All @@ -257,11 +273,29 @@ protected final void internalSuspend() {

@Override
public boolean resume() {
boolean result = _resume();
if (result) {
publishEvent(
workflowContext, l -> l.onWorkflowResumed(new WorkflowResumedEvent(workflowContext)));
}
return result;
}

@Override
public CompletableFuture<Boolean> resumeFuture() {
return _resume()
? publishEvent(
workflowContext,
l -> l.onWorkflowResumed(new WorkflowResumedEvent(workflowContext)))
.thenApply(__ -> true)
: CompletableFuture.completedFuture(false);
}

private boolean _resume() {
boolean result;
try {
statusLock.lock();
if (TaskExecutorHelper.isActive(status.get()) && suspended != null) {

suspended.forEach(
(k, v) -> {
k.complete(v);
Expand All @@ -274,10 +308,6 @@ public boolean resume() {
} finally {
statusLock.unlock();
}
if (result) {
publishEvent(
workflowContext, l -> l.onWorkflowResumed(new WorkflowResumedEvent(workflowContext)));
}
return result;
}

Expand Down Expand Up @@ -314,6 +344,25 @@ public CompletableFuture<TaskContext> suspendedCheck(TaskContext t) {

@Override
public boolean cancel() {
boolean result = _cancel();
if (result) {
publishEvent(
workflowContext, l -> l.onWorkflowCancelled(new WorkflowCancelledEvent(workflowContext)));
}
return result;
Comment thread
fjtirado marked this conversation as resolved.
}

@Override
public CompletableFuture<Boolean> cancelFuture() {
return _cancel()
? publishEvent(
workflowContext,
l -> l.onWorkflowCancelled(new WorkflowCancelledEvent(workflowContext)))
.thenApply(__ -> true)
: CompletableFuture.completedFuture(false);
}

private boolean _cancel() {
boolean result;
Collection<CompletableFuture<?>> toCancel = null;
try {
Expand All @@ -330,8 +379,6 @@ public boolean cancel() {
statusLock.unlock();
}
if (result) {
publishEvent(
workflowContext, l -> l.onWorkflowCancelled(new WorkflowCancelledEvent(workflowContext)));
if (toCancel != null) {
toCancel.forEach(t -> t.cancel(true));
}
Expand Down
Loading