Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2015 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.test;
 
 import java.util.Map;
 
 
 public class TestGenericActivityClient implements GenericActivityClient {
 
     private final class TestActivityExecutionContext extends ActivityExecutionContext {
 
         private final ActivityTask activityTask;
 
         private final WorkflowExecution workflowExecution;
 
         private TestActivityExecutionContext(ActivityTask activityTaskWorkflowExecution workflowExecution) {
             this. = activityTask;
             this. = workflowExecution;
         }
 
         @Override
         public void recordActivityHeartbeat(String detailsthrows AmazonServiceExceptionAmazonClientException {
             //TODO: timeouts
         }
 
         @Override
         public ActivityTask getTask() {
             return ;
         }
 
         @Override
         public AmazonSimpleWorkflow getService() {
             throw new UnsupportedOperationException("not implemented");
         }
 
         @Override
         public String getTaskToken() {
             return .getTaskToken();
         }
 
         @Override
         public WorkflowExecution getWorkflowExecution() {
             return ;
         }
 
         @Override
         public String getDomain() {
             return "dummyTestDomain";
         }
         
     }

    
Key is TaskList
 
 
 
     protected final Map<ActivityTypeStringworkerTaskLists = new HashMap<ActivityTypeString>();
 
 
     public TestGenericActivityClient(DecisionContextProvider decisionContextProvider) {
         this. = decisionContextProvider;
     }
    public TestGenericActivityClient() {
        this(new DecisionContextProviderImpl());
    }
    public void addFactory(String taskListToListenActivityImplementationFactory factory) {
        .put(taskListToListenfactory);
        Iterable<ActivityTypetypesToRegister = factory.getActivityTypesToRegister();
        for (ActivityType activityType : typesToRegister) {
            ActivityImplementation implementation = factory.getActivityImplementation(activityType);
            ActivityTypeRegistrationOptions ro = implementation.getRegistrationOptions();
            .put(activityTypero);
            .put(activityTypetaskListToListen);
        }
    }
    @Override
    public Promise<StringscheduleActivityTask(final ExecuteActivityParameters parameters) {
        final ActivityType activityType = parameters.getActivityType();
        final Settable<Stringresult = new Settable<String>();
        final ActivityTask activityTask = new ActivityTask();
        String activityId = parameters.getActivityId();
        if (activityId == null) {
        }
        activityTask.setActivityId(activityId);
        activityTask.setActivityType(activityType);
        activityTask.setInput(parameters.getInput());
        activityTask.setStartedEventId(0L);
        activityTask.setTaskToken("dummyTaskToken");
        DecisionContext decisionContext = .getDecisionContext();
        final WorkflowExecution workflowExecution = decisionContext.getWorkflowContext().getWorkflowExecution();
        activityTask.setWorkflowExecution(workflowExecution);
        String taskList = parameters.getTaskList();
        if (taskList == null) {
            ActivityTypeRegistrationOptions ro = .get(activityType);
            if (ro == null) {
                throw new ScheduleActivityTaskFailedException(0, activityTypeactivityIdcause);
            }
            taskList = ro.getDefaultTaskList();
            if (..equals(taskList)) {
                throw new ScheduleActivityTaskFailedException(0, activityTypeactivityIdcause);
            }
            else if (taskList == null) {
                taskList = .get(activityType);
            }
        }
        ActivityImplementationFactory factory = .get(taskList);
        // Nobody listens on the specified task list. So in case of a real service it causes 
        // ScheduleToStart timeout.
        //TODO: Activity heartbeats and passing details to the exception.
        if (factory == null) {
            String timeoutType = ..toString();
            throw new ActivityTaskTimedOutException(0, activityTypeactivityIdtimeoutTypenull);
        }
        final ActivityImplementation impl = factory.getActivityImplementation(activityType);
        if (impl == null) {
            throw new ScheduleActivityTaskFailedException(0, activityTypeactivityIdcause);
        }
        ActivityExecutionContext executionContext = new TestActivityExecutionContext(activityTaskworkflowExecution);
        try {
            String activityResult = impl.execute(executionContext);
            result.set(activityResult);
        }
        catch (Throwable e) {
            if (e instanceof ActivityFailureException) {
                ActivityFailureException falure = (ActivityFailureExceptione;
                throw new ActivityTaskFailedException(0, activityTypeparameters.getActivityId(), falure.getReason(),
                        falure.getDetails());
            }
            // Unless there is problem in the framework or generic activity implementation this shouldn't be executed
            ActivityTaskFailedException failure = new ActivityTaskFailedException(0, activityTypeparameters.getActivityId(),
                    e.getMessage(), null);
            failure.initCause(e);
            throw failure;
        }
        return result;
    }
    @Override
    public Promise<StringscheduleActivityTask(String activityString versionString input) {
        ExecuteActivityParameters parameters = new ExecuteActivityParameters();
        ActivityType activityType = new ActivityType();
        activityType.setName(activity);
        activityType.setVersion(version);
        parameters.setActivityType(activityType);
        parameters.setInput(input);
        return scheduleActivityTask(parameters);
    }
    @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;
    }
New to GrepCode? Check out our FAQ X