in src/main/java/com/amazonaws/services/simpleworkflow/flow/DynamicActivitiesClientImpl.java [116:192]
public <T> Promise<T> scheduleActivity(final ActivityType activityType, final Object[] arguments,
final ActivitySchedulingOptions optionsOverride, final Class<T> returnType, Promise<?>... waitFor) {
final Settable<T> result = new Settable<T>();
new TryCatchFinally(waitFor) {
Promise<String> stringOutput;
@Override
protected void doTry() throws Throwable {
ExecuteActivityParameters parameters = new ExecuteActivityParameters();
parameters.setActivityType(activityType);
final String stringInput = ThreadLocalMetrics.getMetrics().recordSupplier(
() -> dataConverter.toData(arguments),
dataConverter.getClass().getSimpleName() + "@" + MetricName.Operation.DATA_CONVERTER_SERIALIZE.getName(),
TimeUnit.MILLISECONDS
);
parameters.setInput(stringInput);
final ExecuteActivityParameters _scheduleParameters_ = parameters.createExecuteActivityParametersFromOptions(
schedulingOptions, optionsOverride);
GenericActivityClient client;
if (genericClient == null) {
client = decisionContextProvider.getDecisionContext().getActivityClient();
} else {
client = genericClient;
}
stringOutput = client.scheduleActivityTask(_scheduleParameters_);
result.setDescription(stringOutput.getDescription());
}
@Override
protected void doCatch(Throwable e) throws Throwable {
if (e instanceof ActivityTaskFailedException) {
ActivityTaskFailedException taskFailedException = (ActivityTaskFailedException) e;
try {
String details = taskFailedException.getDetails();
if (details != null) {
final Throwable cause = ThreadLocalMetrics.getMetrics().recordSupplier(
() -> dataConverter.fromData(details, Throwable.class),
dataConverter.getClass().getSimpleName() + "@" + MetricName.Operation.DATA_CONVERTER_DESERIALIZE.getName(),
TimeUnit.MILLISECONDS
);
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 (stringOutput != null && stringOutput.isReady()) {
if (returnType.equals(Void.class)) {
result.set(null);
}
else {
final T output = ThreadLocalMetrics.getMetrics().recordSupplier(
() -> dataConverter.fromData(stringOutput.get(), returnType),
dataConverter.getClass().getSimpleName() + "@" + MetricName.Operation.DATA_CONVERTER_DESERIALIZE.getName(),
TimeUnit.MILLISECONDS
);
result.set(output);
}
}
}
};
return result;
}