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

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

Introduction

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

Prototype

TaskList

Source Link

Usage

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

License:Apache License

public static void main(String[] args) {
    while (true) {
        System.out.println("Polling for an activity task from the tasklist '" + HelloTypes.TASKLIST
                + "' in the domain '" + HelloTypes.DOMAIN + "'.");

        ActivityTask task = swf.pollForActivityTask(new PollForActivityTaskRequest()
                .withDomain(HelloTypes.DOMAIN).withTaskList(new TaskList().withName(HelloTypes.TASKLIST)));

        String task_token = task.getTaskToken();

        if (task_token != null) {
            String result = null;
            Throwable error = null;

            try {
                System.out.println("Executing the activity task with input '" + task.getInput() + "'.");
                result = sayHello(task.getInput());
            } catch (Throwable th) {
                error = th;/* ww  w .  j a  v a 2s.  c o m*/
            }

            if (error == null) {
                System.out.println("The activity task succeeded with result '" + result + "'.");
                swf.respondActivityTaskCompleted(
                        new RespondActivityTaskCompletedRequest().withTaskToken(task_token).withResult(result));
            } else {
                System.out.println(
                        "The activity task failed with the error '" + error.getClass().getSimpleName() + "'.");
                swf.respondActivityTaskFailed(new RespondActivityTaskFailedRequest().withTaskToken(task_token)
                        .withReason(error.getClass().getSimpleName()).withDetails(error.getMessage()));
            }
        }
    }
}

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

License:Apache License

public static void pollAndExecute() {
    while (!terminate) {
        System.out.println("Polling for an activity task from the tasklist '" + HelloTypes.TASKLIST
                + "' in the domain '" + HelloTypes.DOMAIN + "'.");

        ActivityTask task = swf.pollForActivityTask(new PollForActivityTaskRequest()
                .withDomain(HelloTypes.DOMAIN).withTaskList(new TaskList().withName(HelloTypes.TASKLIST)));

        String taskToken = task.getTaskToken();

        if (taskToken != null) {
            String result = null;
            Throwable error = null;

            try {
                System.out.println("Executing the activity task with input '" + task.getInput() + "'.");
                result = executeActivityTask(task.getInput());
            } catch (Throwable th) {
                error = th;// w ww.  j  a  v  a2  s  .  c om
            }

            if (error == null) {
                System.out.println("The activity task succeeded with result '" + result + "'.");
                swf.respondActivityTaskCompleted(
                        new RespondActivityTaskCompletedRequest().withTaskToken(taskToken).withResult(result));
            } else {
                System.out.println(
                        "The activity task failed with the error '" + error.getClass().getSimpleName() + "'.");
                swf.respondActivityTaskFailed(new RespondActivityTaskFailedRequest().withTaskToken(taskToken)
                        .withReason(error.getClass().getSimpleName()).withDetails(error.getMessage()));
            }
        }
    }
}

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

License:Apache License

public static void registerActivityType() {
    try {/* w  w w .  j  a  va2 s .c o  m*/
        System.out.println("** Registering the activity type '" + ACTIVITY + "-" + ACTIVITY_VERSION + "'.");
        swf.registerActivityType(new RegisterActivityTypeRequest().withDomain(DOMAIN).withName(ACTIVITY)
                .withVersion(ACTIVITY_VERSION).withDefaultTaskList(new TaskList().withName(TASKLIST))
                .withDefaultTaskScheduleToStartTimeout("30").withDefaultTaskStartToCloseTimeout("600")
                .withDefaultTaskScheduleToCloseTimeout("630").withDefaultTaskHeartbeatTimeout("10"));
    } catch (TypeAlreadyExistsException e) {
        System.out.println("** Activity type already exists!");
    }
}

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

License:Apache License

public static void registerWorkflowType() {
    try {// ww w.  j av a 2 s.  c o m
        System.out.println("** Registering the workflow type '" + WORKFLOW + "-" + WORKFLOW_VERSION + "'.");
        swf.registerWorkflowType(new RegisterWorkflowTypeRequest().withDomain(DOMAIN).withName(WORKFLOW)
                .withVersion(WORKFLOW_VERSION).withDefaultChildPolicy(ChildPolicy.TERMINATE)
                .withDefaultTaskList(new TaskList().withName(TASKLIST))
                .withDefaultTaskStartToCloseTimeout("30"));
    } catch (TypeAlreadyExistsException e) {
        System.out.println("** Workflow type already exists!");
    }
}

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

License:Apache License

public static void main(String[] args) {
    PollForDecisionTaskRequest task_request = new PollForDecisionTaskRequest().withDomain(HelloTypes.DOMAIN)
            .withTaskList(new TaskList().withName(HelloTypes.TASKLIST));

    while (true) {
        System.out.println("Polling for a decision task from the tasklist '" + HelloTypes.TASKLIST
                + "' in the domain '" + HelloTypes.DOMAIN + "'.");

        DecisionTask task = swf.pollForDecisionTask(task_request);

        String taskToken = task.getTaskToken();
        if (taskToken != null) {
            try {
                executeDecisionTask(taskToken, task.getEvents());
            } catch (Throwable th) {
                th.printStackTrace();//from  ww w.  j  a  v a2  s . com
            }
        }
    }
}

From source file:example.swf.hellolambda.HelloTypes.java

License:Apache License

public static void registerWorkflowType() {
    String lambda_role_arn = createLambdaRole();

    if (lambda_role_arn == null) {
        System.err.println("Could not get Lambda role ARN!");
    }/*w  w  w.  j ava 2 s  .  co  m*/

    System.out.println("** Registering the workflow type '" + WORKFLOW + "-" + WORKFLOW_VERSION + "'.");
    try {
        swf.registerWorkflowType(new RegisterWorkflowTypeRequest().withDomain(DOMAIN).withName(WORKFLOW)
                .withDefaultLambdaRole(lambda_role_arn).withVersion(WORKFLOW_VERSION)
                .withDefaultChildPolicy(ChildPolicy.TERMINATE)
                .withDefaultTaskList(new TaskList().withName(TASKLIST))
                .withDefaultTaskStartToCloseTimeout("30"));
    } catch (TypeAlreadyExistsException e) {
        System.out.println("** Workflow type already exists!");
    }
}