Search in sources :

Example 1 with SignalExternalWorkflowExecutionDecisionAttributes

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);
    };
}
Also used : ChildWorkflowExecutionCompletedEventAttributes(com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes) SignalExternalWorkflowExecutionFailedEventAttributes(com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution) StartChildWorkflowFailedException(com.uber.cadence.workflow.StartChildWorkflowFailedException) TaskList(com.uber.cadence.TaskList) ChildWorkflowExecutionFailedCause(com.uber.cadence.ChildWorkflowExecutionFailedCause) HistoryEvent(com.uber.cadence.HistoryEvent) HashMap(java.util.HashMap) RequestCancelExternalWorkflowExecutionDecisionAttributes(com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes) ChildPolicy(com.uber.cadence.ChildPolicy) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ChildWorkflowTerminatedException(com.uber.cadence.workflow.ChildWorkflowTerminatedException) SignalExternalWorkflowExecutionDecisionAttributes(com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes) WorkflowType(com.uber.cadence.WorkflowType) ChildWorkflowExecutionCanceledEventAttributes(com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes) ChildWorkflowExecutionStartedEventAttributes(com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes) ChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes) StartChildWorkflowExecutionDecisionAttributes(com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes) CancellationException(java.util.concurrent.CancellationException) StandardCharsets(java.nio.charset.StandardCharsets) Consumer(java.util.function.Consumer) ChildWorkflowTimedOutException(com.uber.cadence.workflow.ChildWorkflowTimedOutException) ExternalWorkflowExecutionSignaledEventAttributes(com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException) ChildWorkflowExecutionTerminatedEventAttributes(com.uber.cadence.ChildWorkflowExecutionTerminatedEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution) SignalExternalWorkflowExecutionDecisionAttributes(com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes)

Aggregations

ChildPolicy (com.uber.cadence.ChildPolicy)1 ChildWorkflowExecutionCanceledEventAttributes (com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)1 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)1 ChildWorkflowExecutionFailedCause (com.uber.cadence.ChildWorkflowExecutionFailedCause)1 ChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes)1 ChildWorkflowExecutionStartedEventAttributes (com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes)1 ChildWorkflowExecutionTerminatedEventAttributes (com.uber.cadence.ChildWorkflowExecutionTerminatedEventAttributes)1 ChildWorkflowExecutionTimedOutEventAttributes (com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes)1 ExternalWorkflowExecutionSignaledEventAttributes (com.uber.cadence.ExternalWorkflowExecutionSignaledEventAttributes)1 HistoryEvent (com.uber.cadence.HistoryEvent)1 RequestCancelExternalWorkflowExecutionDecisionAttributes (com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes)1 SignalExternalWorkflowExecutionDecisionAttributes (com.uber.cadence.SignalExternalWorkflowExecutionDecisionAttributes)1 SignalExternalWorkflowExecutionFailedEventAttributes (com.uber.cadence.SignalExternalWorkflowExecutionFailedEventAttributes)1 StartChildWorkflowExecutionDecisionAttributes (com.uber.cadence.StartChildWorkflowExecutionDecisionAttributes)1 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)1 TaskList (com.uber.cadence.TaskList)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowType (com.uber.cadence.WorkflowType)1 ChildWorkflowTerminatedException (com.uber.cadence.workflow.ChildWorkflowTerminatedException)1 ChildWorkflowTimedOutException (com.uber.cadence.workflow.ChildWorkflowTimedOutException)1