Example usage for com.amazonaws.services.simpleworkflow.model ActivityType ActivityType

List of usage examples for com.amazonaws.services.simpleworkflow.model ActivityType ActivityType

Introduction

In this page you can find the example usage for com.amazonaws.services.simpleworkflow.model ActivityType ActivityType.

Prototype

ActivityType

Source Link

Usage

From source file:aws.example.helloswf.WorkflowWorker.java

License:Apache License

/**
 * 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./*from w  ww.j  a  va  2 s .co m*/
 */
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.getEventType()) {
        case "WorkflowExecutionStarted":
            workflow_input = event.getWorkflowExecutionStartedEventAttributes().getInput();
            break;
        case "ActivityTaskScheduled":
            scheduled_activities++;
            break;
        case "ScheduleActivityTaskFailed":
            scheduled_activities--;
            break;
        case "ActivityTaskStarted":
            scheduled_activities--;
            open_activities++;
            break;
        case "ActivityTaskCompleted":
            open_activities--;
            activity_completed = true;
            result = event.getActivityTaskCompletedEventAttributes().getResult();
            break;
        case "ActivityTaskFailed":
            open_activities--;
            break;
        case "ActivityTaskTimedOut":
            open_activities--;
            break;
        }
    }
    System.out.println("]");

    if (activity_completed) {
        decisions.add(new Decision().withDecisionType(DecisionType.CompleteWorkflowExecution)
                .withCompleteWorkflowExecutionDecisionAttributes(
                        new CompleteWorkflowExecutionDecisionAttributes().withResult(result)));
    } else {
        if (open_activities == 0 && scheduled_activities == 0) {

            ScheduleActivityTaskDecisionAttributes attrs = new ScheduleActivityTaskDecisionAttributes()
                    .withActivityType(new ActivityType().withName(HelloTypes.ACTIVITY)
                            .withVersion(HelloTypes.ACTIVITY_VERSION))
                    .withActivityId(UUID.randomUUID().toString()).withInput(workflow_input);

            decisions.add(new Decision().withDecisionType(DecisionType.ScheduleActivityTask)
                    .withScheduleActivityTaskDecisionAttributes(attrs));
        } else {
            // an instance of HelloActivity is already scheduled or running. Do nothing, another
            // task will be scheduled once the activity completes, fails or times out
        }
    }

    System.out.println("Exiting the decision task with the decisions " + decisions);

    swf.respondDecisionTaskCompleted(
            new RespondDecisionTaskCompletedRequest().withTaskToken(taskToken).withDecisions(decisions));
}

From source file:org.apache.camel.component.aws.swf.CamelActivityImplementationFactory.java

License:Apache License

@Override
public Iterable<ActivityType> getActivityTypesToRegister() {
    ArrayList<ActivityType> activityTypes = new ArrayList<ActivityType>(1);
    ActivityType activityType = new ActivityType();
    activityType.setName(configuration.getEventName());
    activityType.setVersion(configuration.getVersion());
    activityTypes.add(activityType);//from w  w  w  .  j ava  2s .c o  m
    return activityTypes;
}

From source file:org.apache.camel.component.aws.swf.CamelSWFActivityClient.java

License:Apache License

public Object scheduleActivity(String eventName, String version, Object input) {
    ActivityType activity = new ActivityType();
    activity.setName(eventName);// ww  w  .  j a va 2s  .  co m
    activity.setVersion(version);

    Promise[] promises = asPromiseArray(input);
    Promise<?> promise = dynamicActivitiesClient.scheduleActivity(activity, promises,
            configuration.getActivitySchedulingOptions(), Object.class, null);
    return promise;
}