Search in sources :

Example 16 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.

the class ActivityId method toBytes.

/**
 * Used for task tokens.
 */
public byte[] toBytes() throws InternalServiceError {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bout);
    try {
        out.writeUTF(executionId.getDomain());
        WorkflowExecution execution = executionId.getExecution();
        out.writeUTF(execution.getWorkflowId());
        out.writeUTF(execution.getRunId());
        out.writeUTF(id);
        return bout.toByteArray();
    } catch (IOException e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) WorkflowExecution(com.uber.cadence.WorkflowExecution) InternalServiceError(com.uber.cadence.InternalServiceError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 17 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.

the class WorkflowDecisionContext method handleChildWorkflowExecutionTimedOut.

void handleChildWorkflowExecutionTimedOut(HistoryEvent event) {
    ChildWorkflowExecutionTimedOutEventAttributes attributes = event.getChildWorkflowExecutionTimedOutEventAttributes();
    WorkflowExecution execution = attributes.getWorkflowExecution();
    String workflowId = execution.getWorkflowId();
    if (decisions.handleChildWorkflowExecutionClosed(workflowId)) {
        OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
        if (scheduled != null) {
            RuntimeException failure = new ChildWorkflowTimedOutException(event.getEventId(), execution, attributes.getWorkflowType());
            BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
            completionCallback.accept(null, failure);
        }
    }
}
Also used : WorkflowExecution(com.uber.cadence.WorkflowExecution) ChildWorkflowTimedOutException(com.uber.cadence.workflow.ChildWorkflowTimedOutException) ChildWorkflowExecutionTimedOutEventAttributes(com.uber.cadence.ChildWorkflowExecutionTimedOutEventAttributes) StartChildWorkflowFailedException(com.uber.cadence.workflow.StartChildWorkflowFailedException) ChildWorkflowTerminatedException(com.uber.cadence.workflow.ChildWorkflowTerminatedException) CancellationException(java.util.concurrent.CancellationException) ChildWorkflowTimedOutException(com.uber.cadence.workflow.ChildWorkflowTimedOutException) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException)

Example 18 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution 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)

Example 19 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.

the class WorkflowDecisionContext method handleChildWorkflowExecutionStarted.

void handleChildWorkflowExecutionStarted(HistoryEvent event) {
    ChildWorkflowExecutionStartedEventAttributes attributes = event.getChildWorkflowExecutionStartedEventAttributes();
    WorkflowExecution execution = attributes.getWorkflowExecution();
    String workflowId = execution.getWorkflowId();
    decisions.handleChildWorkflowExecutionStarted(event);
    OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.get(workflowId);
    if (scheduled != null) {
        scheduled.getExecutionCallback().accept(attributes.getWorkflowExecution());
    }
}
Also used : ChildWorkflowExecutionStartedEventAttributes(com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes) WorkflowExecution(com.uber.cadence.WorkflowExecution)

Example 20 with WorkflowExecution

use of com.uber.cadence.WorkflowExecution in project cadence-client by uber-java.

the class WorkflowDecisionContext method generateUniqueId.

String generateUniqueId() {
    WorkflowExecution workflowExecution = workflowContext.getWorkflowExecution();
    String runId = workflowExecution.getRunId();
    return runId + ":" + decisions.getNextId();
}
Also used : WorkflowExecution(com.uber.cadence.WorkflowExecution)

Aggregations

WorkflowExecution (com.uber.cadence.WorkflowExecution)30 CancellationException (java.util.concurrent.CancellationException)11 SignalExternalWorkflowException (com.uber.cadence.workflow.SignalExternalWorkflowException)8 ChildWorkflowTerminatedException (com.uber.cadence.workflow.ChildWorkflowTerminatedException)7 ChildWorkflowTimedOutException (com.uber.cadence.workflow.ChildWorkflowTimedOutException)7 StartChildWorkflowFailedException (com.uber.cadence.workflow.StartChildWorkflowFailedException)7 HistoryEvent (com.uber.cadence.HistoryEvent)6 Test (org.junit.Test)6 TimeoutException (java.util.concurrent.TimeoutException)5 TException (org.apache.thrift.TException)5 WorkflowStub (com.uber.cadence.client.WorkflowStub)4 GetWorkflowExecutionHistoryRequest (com.uber.cadence.GetWorkflowExecutionHistoryRequest)3 History (com.uber.cadence.History)3 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)3 WorkflowExecutionAlreadyStartedError (com.uber.cadence.WorkflowExecutionAlreadyStartedError)3 WorkflowType (com.uber.cadence.WorkflowType)3 DeterministicRunnerTest (com.uber.cadence.internal.sync.DeterministicRunnerTest)3 ChildWorkflowExecutionCanceledEventAttributes (com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes)2 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)2 ChildWorkflowExecutionFailedCause (com.uber.cadence.ChildWorkflowExecutionFailedCause)2