Example usage for com.amazonaws.services.simpleworkflow.model ActivityTask getTaskToken

List of usage examples for com.amazonaws.services.simpleworkflow.model ActivityTask getTaskToken

Introduction

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

Prototype


public String getTaskToken() 

Source Link

Document

The opaque string used as a handle on the task.

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;// w  w  w .j a  v  a2  s.  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;/*from www. j  av a  2  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()));
            }
        }
    }
}