public Promise startChildWorkflow()

in src/main/java/com/amazonaws/services/simpleworkflow/flow/worker/GenericWorkflowClientImpl.java [133:185]


    public Promise<StartChildWorkflowReply> startChildWorkflow(final StartChildWorkflowExecutionParameters parameters) {
        final OpenRequestInfo<StartChildWorkflowReply, WorkflowType> context = new OpenRequestInfo<StartChildWorkflowReply, WorkflowType>();
        final StartChildWorkflowExecutionDecisionAttributes attributes = new StartChildWorkflowExecutionDecisionAttributes();
        attributes.setWorkflowType(parameters.getWorkflowType());
        String workflowId = parameters.getWorkflowId();
        if (workflowId == null) {
            workflowId = generateUniqueId();
        }
        attributes.setWorkflowId(workflowId);
        attributes.setInput(parameters.getInput());
        attributes.setExecutionStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getExecutionStartToCloseTimeoutSeconds()));
        attributes.setTaskStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getTaskStartToCloseTimeoutSeconds()));
        attributes.setTaskPriority(FlowHelpers.taskPriorityToString(parameters.getTaskPriority()));
        List<String> tagList = parameters.getTagList();
        if (tagList != null) {
            attributes.setTagList(tagList);
        }
        ChildPolicy childPolicy = parameters.getChildPolicy();
        if (childPolicy != null) {
            attributes.setChildPolicy(childPolicy);
        }
        String taskList = parameters.getTaskList();
        if (taskList != null && !taskList.isEmpty()) {
            attributes.setTaskList(new TaskList().withName(taskList));
        }
        attributes.setLambdaRole(parameters.getLambdaRole());
        String taskName = "workflowId=" + workflowId + ", workflowType=" + attributes.getWorkflowType();
        new ExternalTask() {

            @Override
            protected ExternalTaskCancellationHandler doExecute(final ExternalTaskCompletionHandle handle) throws Throwable {
                context.setCompletionHandle(handle);
                String workflowId = attributes.getWorkflowId();
                
            	if (scheduledExternalWorkflows.containsKey(workflowId)) {
                    WorkflowExecution workflowExecution = new WorkflowExecution();
                    workflowExecution.setWorkflowId(workflowId);
                    WorkflowType workflowType = attributes.getWorkflowType();
                    long fakeEventId = -1;

                    handle.fail(new StartChildWorkflowFailedException(fakeEventId, workflowExecution, workflowType, StartChildWorkflowExecutionFailedCause.WORKFLOW_ALREADY_RUNNING.toString()));
                    return new ChildWorkflowCancellationHandler(workflowId, handle);
            	}

                // should not update this map if the same work flow is running
                decisions.startChildWorkflowExecution(attributes);
                scheduledExternalWorkflows.put(workflowId, context);
                return new ChildWorkflowCancellationHandler(workflowId, handle);
            }
        }.setName(taskName);
        context.setResultDescription("startChildWorkflow " + taskName);
        return context.getResult();
    }