public void decide()

in src/main/java/com/amazonaws/services/simpleworkflow/flow/worker/AsyncDecider.java [465:523]


    public void decide() throws Exception {
        try {
            // Reusing the existing workflow definition for a cached decider
            if (definition != null) {
                CurrentDecisionContext.set(context);
                if (savedWorkflowExecutionLocalValues == null) {
                    ThreadLocalMetrics.getMetrics().recordCount(MetricName.AFFINITY_WORKER_WORKFLOW_EXECUTION_LOCAL_FAILURE.getName(), 1);
                    log.error("Unable to restore WorkflowExecutionLocals for affinity worker. Your WorkflowExecutionLocals will not work as expected.");
                } else {
                    WorkflowExecutionLocal.restoreFromSavedValues(savedWorkflowExecutionLocalValues);
                }
            } else {
                try {
                    definition = workflowDefinitionFactory.getWorkflowDefinition(context);
                } catch (Exception e) {
                    throw new Error("Failed to get workflow definition for " + context, e);
                }
            }
            if (definition == null) {
                final WorkflowType workflowType = context.getWorkflowContext().getWorkflowType();
                ThreadLocalMetrics.getMetrics().recordCount(MetricName.TYPE_NOT_FOUND.getName(), 1, MetricName.getWorkflowTypeDimension(workflowType));
            	throw new IllegalStateException("Null workflow definition returned for: " + workflowType);
            }
            decideImpl();
        } catch (AwsServiceException e) {
            // We don't want to fail workflow on service exceptions like 500 or throttling
            // Throwing from here drops decision task which is OK as it is rescheduled after its StartToClose timeout.
            if (e.isThrottlingException()) {
                if (log.isErrorEnabled()) {
                    log.error("Failing workflow " + workflowContext.getWorkflowExecution(), e);
                }
                decisionsHelper.failWorkflowDueToUnexpectedError(e);
            } else {
                throw e;
            }
        } catch (SdkClientException | Error e) {
            // Do not fail workflow on SdkClientException or Error. Fail the decision.
            throw e;
        } catch (Throwable e) {
            if (log.isErrorEnabled()) {
                log.error("Failing workflow " + workflowContext.getWorkflowExecution(), e);
            }
            decisionsHelper.failWorkflowDueToUnexpectedError(e);
        } finally {
            try {
                if (definition != null) {
                    decisionsHelper.setWorkflowContextData(definition.getWorkflowState());
                }
            } catch (WorkflowException e) {
                decisionsHelper.setWorkflowContextData(e.getDetails());
            } catch (Throwable e) {
                decisionsHelper.setWorkflowContextData(e.getMessage());
            }
            if (definition != null) {
                savedWorkflowExecutionLocalValues = WorkflowExecutionLocal.saveCurrentValues();
                workflowDefinitionFactory.deleteWorkflowDefinition(definition);
            }
        }
    }