Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.worker;
 
 import java.util.Map;
 
 
 
     private final class ActivityCancellationHandler implements ExternalTaskCancellationHandler {
 
         private final String activityId;
 
         private final ExternalTaskCompletionHandle handle;
 
         private ActivityCancellationHandler(String activityIdExternalTaskCompletionHandle handle) {
             this. = activityId;
             this. = handle;
         }
 
         @Override
         public void handleCancellation(Throwable cause) {
             .requestCancelActivityTask(new Runnable() {
 
                 @Override
                 public void run() {
                     OpenRequestInfo<StringActivityTypescheduled = .remove();
                     if (scheduled == null) {
                         throw new IllegalArgumentException("Activity \"" +  + "\" wasn't scheduled");
                     }
                     .complete();
                 }
             });
         }
     }
 
     private final DecisionsHelper decisions;
 
 
     public GenericActivityClientImpl(DecisionsHelper decisions) {
         this. = decisions;
     }
 
     @Override
     public Promise<StringscheduleActivityTask(final ExecuteActivityParameters parameters) {
         final OpenRequestInfo<StringActivityTypecontext = new OpenRequestInfo<StringActivityType>(
                 parameters.getActivityType());
         attributes.setActivityType(parameters.getActivityType());
         attributes.setInput(parameters.getInput());
         attributes.setHeartbeatTimeout(FlowHelpers.secondsToDuration(parameters.getHeartbeatTimeoutSeconds()));
         attributes.setScheduleToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getScheduleToCloseTimeoutSeconds()));
         attributes.setScheduleToStartTimeout(FlowHelpers.secondsToDuration(parameters.getScheduleToStartTimeoutSeconds()));
         attributes.setStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getStartToCloseTimeoutSeconds()));
         attributes.setTaskPriority(FlowHelpers.taskPriorityToString(parameters.getTaskPriority()));
         String activityId = parameters.getActivityId();
         if (activityId == null) {
             activityId = String.valueOf(.getNextId());
         }
         attributes.setActivityId(activityId);
 
         String taskList = parameters.getTaskList();
        if (taskList != null && !taskList.isEmpty()) {
            attributes.setTaskList(new TaskList().withName(taskList));
        }
        String taskName = "activityId=" + activityId + ", activityType=" + attributes.getActivityType();
        new ExternalTask() {
            @Override
            protected ExternalTaskCancellationHandler doExecute(final ExternalTaskCompletionHandle handlethrows Throwable {
                .scheduleActivityTask(attributes);
                context.setCompletionHandle(handle);
                .put(attributes.getActivityId(), context);
                return new ActivityCancellationHandler(attributes.getActivityId(), handle);
            }
        }.setName(taskName);
        context.setResultDescription("scheduleActivityTask " + taskName);
        return context.getResult();
    }
    @Override
    public Promise<StringscheduleActivityTask(final String activityfinal String versionfinal Promise<Stringinput) {
        final Settable<Stringresult = new Settable<String>();
        new Task(input) {
            @Override
            protected void doExecute() throws Throwable {
                result.chain(scheduleActivityTask(activityversioninput.get()));
            }
        };
        return result;
    }
    @Override
    public Promise<StringscheduleActivityTask(String activityString versionString input) {
        ExecuteActivityParameters parameters = new ExecuteActivityParameters();
        parameters.setActivityType(new ActivityType().withName(activity).withVersion(version));
        parameters.setInput(input);
        return scheduleActivityTask(parameters);
    }
    }
        String activityId = .getActivityId(attributes);
        if (.handleActivityTaskCanceled(event)) {
            CancellationException e = new CancellationException();
            OpenRequestInfo<StringActivityTypescheduled = .remove(activityId);
            if (scheduled != null) {
                ExternalTaskCompletionHandle completionHandle = scheduled.getCompletionHandle();
                // It is OK to fail with subclass of CancellationException when cancellation requested.
                // It allows passing information about cancellation (details in this case) to the surrounding doCatch block
                completionHandle.fail(e);
            }
        }
    }
        String activityId = attributes.getActivityId();
        OpenRequestInfo<StringActivityTypescheduled = .remove(activityId);
        if (.handleScheduleActivityTaskFailed(event)) {
            String cause = attributes.getCause();
                    attributes.getActivityType(), activityIdcause);
            ExternalTaskCompletionHandle completionHandle = scheduled.getCompletionHandle();
            completionHandle.fail(failure);
        }
    }
        String activityId = .getActivityId(attributes);
        if (.handleActivityTaskClosed(activityId)) {
            OpenRequestInfo<StringActivityTypescheduled = .remove(activityId);
            if (scheduled != null) {
                String result = attributes.getResult();
                scheduled.getResult().set(result);
                ExternalTaskCompletionHandle completionHandle = scheduled.getCompletionHandle();
                completionHandle.complete();
            }
        }
    }
    void handleActivityTaskFailed(HistoryEvent event) {
        String activityId = .getActivityId(attributes);
        if (.handleActivityTaskClosed(activityId)) {
            OpenRequestInfo<StringActivityTypescheduled = .remove(activityId);
            if (scheduled != null) {
                String reason = attributes.getReason();
                String details = attributes.getDetails();
                ActivityTaskFailedException failure = new ActivityTaskFailedException(event.getEventId(),
                        scheduled.getUserContext(), activityIdreasondetails);
                ExternalTaskCompletionHandle completionHandle = scheduled.getCompletionHandle();
                completionHandle.fail(failure);
            }
        }
    }
        String activityId = .getActivityId(attributes);
        if (.handleActivityTaskClosed(activityId)) {
            OpenRequestInfo<StringActivityTypescheduled = .remove(activityId);
            if (scheduled != null) {
                String timeoutType = attributes.getTimeoutType();
                String details = attributes.getDetails();
                ActivityTaskTimedOutException failure = new ActivityTaskTimedOutException(event.getEventId(),
                        scheduled.getUserContext(), activityIdtimeoutTypedetails);
                ExternalTaskCompletionHandle completionHandle = scheduled.getCompletionHandle();
                completionHandle.fail(failure);
            }
        }
    }
New to GrepCode? Check out our FAQ X