use of com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes in project cadence-client by uber-java.
the class WorkflowDecisionContext method signalWorkflowExecution.
Consumer<Exception> signalWorkflowExecution(final SignalExternalWorkflowParameters parameters, BiConsumer<Void, Exception> callback) {
final OpenRequestInfo<Void, Void> context = new OpenRequestInfo<>();
final SignalExternalWorkflowExecutionDecisionAttributes attributes = new SignalExternalWorkflowExecutionDecisionAttributes();
String signalId = decisions.getNextId();
if (parameters.getDomain() == null) {
attributes.setDomain(workflowContext.getDomain());
} else {
attributes.setDomain(parameters.getDomain());
}
attributes.setControl(signalId.getBytes(StandardCharsets.UTF_8));
attributes.setSignalName(parameters.getSignalName());
attributes.setInput(parameters.getInput());
WorkflowExecution execution = new WorkflowExecution();
execution.setRunId(parameters.getRunId());
execution.setWorkflowId(parameters.getWorkflowId());
attributes.setExecution(execution);
decisions.signalExternalWorkflowExecution(attributes);
context.setCompletionHandle(callback);
final String finalSignalId = new String(attributes.getControl(), StandardCharsets.UTF_8);
scheduledSignals.put(finalSignalId, context);
return (e) -> {
if (!scheduledSignals.containsKey(finalSignalId)) {
// Cancellation handlers are not deregistered. So they fire after a signal completion.
return;
}
decisions.cancelSignalExternalWorkflowExecution(finalSignalId, null);
OpenRequestInfo<Void, Void> scheduled = scheduledSignals.remove(finalSignalId);
if (scheduled == null) {
throw new IllegalArgumentException("Signal \"" + finalSignalId + "\" wasn't scheduled");
}
callback.accept(null, e);
};
}
Aggregations