in src/main/java/com/amazonaws/services/simpleworkflow/flow/DynamicWorkflowClientImpl.java [169:244]
public <T> Promise<T> startWorkflowExecution(final Object[] arguments, final StartWorkflowOptions startOptionsOverride,
final Class<T> returnType, Promise<?>... waitFor) {
checkState();
final Settable<T> result = new Settable<T>();
if (runId.isReady()) {
runId = new Settable<String>();
}
new TryFinally(waitFor) {
Promise<StartChildWorkflowReply> reply;
@Override
protected void doTry() throws Throwable {
StartChildWorkflowExecutionParameters parameters = new StartChildWorkflowExecutionParameters();
parameters.setWorkflowType(workflowType);
String convertedArguments = dataConverter.toData(arguments);
parameters.setInput(convertedArguments);
parameters.setWorkflowId(workflowExecution.getWorkflowId());
final StartChildWorkflowExecutionParameters startParameters = parameters.createStartChildWorkflowExecutionParametersFromOptions(
schedulingOptions, startOptionsOverride);
GenericWorkflowClient client = getGenericClientToUse();
reply = client.startChildWorkflow(startParameters);
runId.setDescription("runId of " + reply.getDescription());
result.setDescription(reply.getDescription());
new Task(reply) {
@Override
protected void doExecute() throws Throwable {
if (!runId.isReady()) {
runId.set(reply.get().getRunId());
workflowExecution.setRunId(runId.get());
}
}
};
}
@Override
protected void doCatch(Throwable e) throws Throwable {
if (e instanceof ChildWorkflowFailedException) {
ChildWorkflowFailedException taskFailedException = (ChildWorkflowFailedException) e;
try {
String details = taskFailedException.getDetails();
if (details != null) {
Throwable cause = dataConverter.fromData(details, Throwable.class);
if (cause != null && taskFailedException.getCause() == null) {
taskFailedException.initCause(cause);
}
}
}
catch (DataConverterException dataConverterException) {
if (dataConverterException.getCause() == null) {
dataConverterException.initCause(taskFailedException);
}
throw dataConverterException;
}
}
throw e;
}
@Override
protected void doFinally() throws Throwable {
if (reply != null && reply.isReady() && reply.get().getResult().isReady()) {
if (returnType.equals(Void.class)) {
result.set(null);
}
else {
T output = dataConverter.fromData(reply.get().getResult().get(), returnType);
result.set(output);
}
}
}
};
return result;
}