Example usage for java.util.concurrent CancellationException printStackTrace

List of usage examples for java.util.concurrent CancellationException printStackTrace

Introduction

In this page you can find the example usage for java.util.concurrent CancellationException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller.java

protected void execute(final ActivityTask task) throws Exception {
    String output = null;//from   w  w  w  . j  a  va  2s . co m
    ActivityType activityType = task.getActivityType();
    try {
        ActivityExecutionContext context = new ActivityExecutionContextImpl(service, domain, task);
        ActivityImplementation activityImplementation = activityImplementationFactory
                .getActivityImplementation(activityType);
        if (activityImplementation == null) {
            throw new ActivityFailureException("Unknown activity type: " + activityType);
        }
        output = activityImplementation.execute(context);
        if (!activityImplementation.getExecutionOptions().isManualActivityCompletion()) {
            respondActivityTaskCompletedWithRetry(task.getTaskToken(), output);
        }
    } catch (CancellationException e) {
        respondActivityTaskCanceledWithRetry(task.getTaskToken(), null);
        return;
    } catch (ActivityFailureException e) {
        if (log.isErrorEnabled()) {
            log.error("Failure processing activity task with taskId=" + task.getStartedEventId()
                    + ", workflowGenerationId=" + task.getWorkflowExecution().getWorkflowId() + ", activity="
                    + activityType + ", activityInstanceId=" + task.getActivityId(), e);
        }
        respondActivityTaskFailedWithRetry(task.getTaskToken(), e.getReason(), e.getDetails());
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Failure processing activity task with taskId=" + task.getStartedEventId()
                    + ", workflowGenerationId=" + task.getWorkflowExecution().getWorkflowId() + ", activity="
                    + activityType + ", activityInstanceId=" + task.getActivityId(), e);
        }
        String reason = e.getMessage();
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String details = sw.toString();
        respondActivityTaskFailedWithRetry(task.getTaskToken(), reason, details);
    }
}