public Promise execute()

in src/main/java/com/amazonaws/services/simpleworkflow/flow/pojo/POJOWorkflowDefinition.java [67:128]


    public Promise<String> execute(final String input) throws WorkflowException {
        final DataConverter c;
        if (workflowMethod.getConverter() == null) {
            c = converter;
        }
        else {
            c = workflowMethod.getConverter();
        }
        final Settable<String> result = new Settable<>();
        final AtomicReference<Promise> methodResult = new AtomicReference<>();
        new TryCatchFinally() {

            @Override
            protected void doTry() throws Throwable {

                //TODO: Support ability to call workflow using old client 
                // after new parameters were added to @Execute method
                // It requires creation of parameters array of the correct size and
                // populating the new parameter values with default values for each type
                final Object[] parameters = ThreadLocalMetrics.getMetrics().recordSupplier(
                    () -> c.fromData(input, Object[].class),
                    c.getClass().getSimpleName() + "@" + MetricName.Operation.DATA_CONVERTER_DESERIALIZE.getName(),
                    TimeUnit.MILLISECONDS
                );
                Method method = workflowMethod.getMethod();
                Object r = invokeMethod(method, parameters);
                if (!method.getReturnType().equals(Void.TYPE)) {
                    methodResult.set((Promise) r);
                }
            }

            @Override
            protected void doCatch(Throwable e) throws Throwable {
                // CancellationException can be caused by:
                //  1. cancellation request from a server (indicated by isCancelRequested returning true). 
                //     Should not be converted.
                //  2. being thrown by user code. Ut should be converted to WorkflowException as any other exception.
                //  3. being caused by exception from the sibling (signal handler). 
                //     In this case the exception cause is already WorkflowException. No double conversion necessary.
                if (!(e instanceof CancellationException)
                        || (!context.getWorkflowContext().isCancelRequested() && !(e.getCause() instanceof WorkflowException))) {
                    throwWorkflowException(c, e);
                }
            }

            @Override
            protected void doFinally() throws Throwable {
                Promise r = methodResult.get();
                if (r == null || r.isReady()) {
                    final Object workflowResult = r == null ? null : r.get();
                    result.set(
                        ThreadLocalMetrics.getMetrics().recordSupplier(
                            () -> c.toData(workflowResult),
                            c.getClass().getSimpleName() + "@" + MetricName.Operation.DATA_CONVERTER_SERIALIZE.getName(),
                            TimeUnit.MILLISECONDS
                        )
                    );
                }
            }
        };
        return result;
    }