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));
}
}
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);
}
}
}
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);
};
}
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());
}
}
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();
}
Aggregations