javav2/example_code/swf/src/main/java/com/example/helloswf/WorkflowWorker.java
/**
     * The goal of this workflow is to execute at least one HelloActivity successfully.
     *
     * We pass the workflow execution's input to the activity, and we use the activity's result
     * as the output of the workflow.
     */
The goal of this workflow is to execute at least one HelloActivity successfully.

We pass the workflow execution's input to the activity, and we use the activity's result
as the output of the workflow.
The goal of this workflow is to execute at least one HelloActivity successfully . We pass the workflow execution ' s input to the activity and we use the activity ' s result as the output of the workflow .
private static void executeDecisionTask(String taskToken, List<HistoryEvent> events)
            throws Throwable {
        List<Decision> decisions = new ArrayList<Decision>();
        String workflow_input = null;
        int scheduled_activities = 0;
        int open_activities = 0;
        boolean activity_completed = false;
        String result = null;
        System.out.println("Executing the decision task for the history events: [");
        for (HistoryEvent event : events) {
            System.out.println("  " + event);
            switch(event.eventType()) {
                case WORKFLOW_EXECUTION_STARTED:
                    workflow_input =
                        event.workflowExecutionStartedEventAttributes()
                             .input();
                    break;
                case ACTIVITY_TASK_SCHEDULED:
                    scheduled_activities++;
                    break;
                case SCHEDULE_ACTIVITY_TASK_FAILED:
                    scheduled_activities--;
                    break;
                case ACTIVITY_TASK_STARTED:
                    scheduled_activities--;
                    open_activities++;
                    break;
                case ACTIVITY_TASK_COMPLETED:
                    open_activities--;
                    activity_completed = true;
                    result = event.activityTaskCompletedEventAttributes()
                                  .result();
                    break;
                case ACTIVITY_TASK_FAILED:
                    open_activities--;
                    break;
                case ACTIVITY_TASK_TIMED_OUT:
                    open_activities--;
                    break;
            }
        }
        System.out.println("]");
        if (activity_completed) {
            decisions.add(
                Decision.builder()
                    .decisionType(DecisionType.COMPLETE_WORKFLOW_EXECUTION)
                    .completeWorkflowExecutionDecisionAttributes(
                        CompleteWorkflowExecutionDecisionAttributes.builder()
                            .result(result)
                            .build())
                    .build());
        } else {
            if (open_activities == 0 && scheduled_activities == 0) {
                ScheduleActivityTaskDecisionAttributes attrs =
                    ScheduleActivityTaskDecisionAttributes.builder()
                        .activityType(ActivityType.builder()
                            .name(HelloTypes.ACTIVITY)
                            .version(HelloTypes.ACTIVITY_VERSION)
                            .build())
                        .activityId(UUID.randomUUID().toString())
                        .input(workflow_input)
                        .build();
                decisions.add(
                        Decision.builder()
                            .decisionType(DecisionType.SCHEDULE_ACTIVITY_TASK)
                            .scheduleActivityTaskDecisionAttributes(attrs).build());
            } else {
            }
        }
        System.out.println("Exiting the decision task with the decisions " + decisions);
        swf.respondDecisionTaskCompleted(
             RespondDecisionTaskCompletedRequest.builder()
                .taskToken(taskToken)
                .decisions(decisions)
                .build());
    }
private static void executeDecisionTask ( String taskToken , List < HistoryEvent > events ) throws Throwable { List < Decision > decisions = new ArrayList < Decision > ( ) ; String workflow_input = null ; int scheduled_activities = 0 ; int open_activities = 0 ; boolean activity_completed = false ; String result = null ; System . out . println ( "Executing the decision task for the history events: [" ) ; for ( HistoryEvent event : events ) { System . out . println ( "  " + event ) ; switch ( event . eventType ( ) ) { case WORKFLOW_EXECUTION_STARTED : workflow_input = event . workflowExecutionStartedEventAttributes ( ) . input ( ) ; break ; case ACTIVITY_TASK_SCHEDULED : scheduled_activities ++ ; break ; case SCHEDULE_ACTIVITY_TASK_FAILED : scheduled_activities -- ; break ; case ACTIVITY_TASK_STARTED : scheduled_activities -- ; open_activities ++ ; break ; case ACTIVITY_TASK_COMPLETED : open_activities -- ; activity_completed = true ; result = event . activityTaskCompletedEventAttributes ( ) . result ( ) ; break ; case ACTIVITY_TASK_FAILED : open_activities -- ; break ; case ACTIVITY_TASK_TIMED_OUT : open_activities -- ; break ; } } System . out . println ( "]" ) ; if ( activity_completed ) { decisions . add ( Decision . builder ( ) . decisionType ( DecisionType . COMPLETE_WORKFLOW_EXECUTION ) . completeWorkflowExecutionDecisionAttributes ( CompleteWorkflowExecutionDecisionAttributes . builder ( ) . result ( result ) . build ( ) ) . build ( ) ) ; } else { if ( open_activities == 0 && scheduled_activities == 0 ) { ScheduleActivityTaskDecisionAttributes attrs = ScheduleActivityTaskDecisionAttributes . builder ( ) . activityType ( ActivityType . builder ( ) . name ( HelloTypes . ACTIVITY ) . version ( HelloTypes . ACTIVITY_VERSION ) . build ( ) ) . activityId ( UUID . randomUUID ( ) . toString ( ) ) . input ( workflow_input ) . build ( ) ; decisions . add ( Decision . builder ( ) . decisionType ( DecisionType . SCHEDULE_ACTIVITY_TASK ) . scheduleActivityTaskDecisionAttributes ( attrs ) . build ( ) ) ; } else { } } System . out . println ( "Exiting the decision task with the decisions " + decisions ) ; swf . respondDecisionTaskCompleted ( RespondDecisionTaskCompletedRequest . builder ( ) . taskToken ( taskToken ) . decisions ( decisions ) . build ( ) ) ; }
The goal of this workflow is to execute at least one HelloActivity successfully.
The goal of this workflow is to execute at least one HelloActivity successfully .
// an instance of HelloActivity is already scheduled or running. Do nothing, another
 // task will be scheduled once the activity completes, fails or times out
