Java 类com.amazonaws.services.simpleworkflow.model.ActivityTask 实例源码

项目:Camel    文件:CamelSWFActivityConsumerTest.java   
@Test
public void receivesDecisionTask() throws Exception {
    result.expectedMinimumMessageCount(1);
    result.expectedMessagesMatches(new Predicate() {
        public boolean matches(Exchange exchange) {
            return exchange.getIn().getHeader(SWFConstants.ACTION).equals(SWFConstants.EXECUTE_ACTION)
                    && exchange.getIn().getBody(Object[].class)[0].equals("test");
        }
    });

    ActivityTask activityTask = new ActivityTask();
    activityTask.setTaskToken("token");
    activityTask.setInput("[\"[Ljava.lang.Object;\",[\"test\"]]");
    when(amazonSWClient.pollForActivityTask(any(PollForActivityTaskRequest.class))).thenReturn(activityTask);

    context.start();

    assertMockEndpointsSatisfied();
    verify(amazonSWClient, atLeastOnce()).pollForActivityTask(any(PollForActivityTaskRequest.class));
}
项目:WaterFlow    文件:ActivityPoller.java   
@Override
protected ActivityTask poll() {
    ActivityTask task = swf().pollForActivityTask(createPollForActivityTask(domain(), taskList(), name()));
    if (task == null || task.getTaskToken() == null) {
        return null;
    }
    return task;
}
项目:WaterFlow    文件:ActivityInvoker.java   
/**
 * Given a {@link ActivityTask} execute matching {@link ActivityMethod}
 * The input of the ActivityTask must be a Object[]
 * @return The result of the {@link ActivityMethod} serialized
 */
public String invoke(ActivityTask task) {
    final ImmutableActivityContext context =
            ImmutableActivityContext.builder().task(task).service(service()).build();
    String name = task.getActivityType().getName();
    Object[] input = dataConverter().fromData(task.getInput(), Object[].class);
    try {
        instance().activityContext(context);
        Object result = method().invoke(instance(), input);
        return dataConverter().toData(result);
    } catch (Throwable e) {
        throw new IllegalStateException(format("error: '%s' '%s' '%s'", task.getActivityId(), name, task.getInput()), e);
    }
}
项目:aws-flow-maven-eclipse-samples    文件:CronExampleActivitiesImpl.java   
/**
 * Fail in 20% of invocations to demonstrate retry logic
 */
@Override
public void doSomeWork(String parameter) {
    Random r = new Random();
    if (r.nextInt(100) < 20) {
        throw new RuntimeException("simulated exception to force retry");
    }
    ActivityExecutionContext context = contextProvider.getActivityExecutionContext();
    ActivityTask task = context.getTask();
    String taskid = task.getActivityId();
    System.out.println("Processed activity task with id: " + taskid);
}
项目:aws-flow-maven-eclipse-samples    文件:CronExampleActivitiesImpl.java   
/**
 * 
 */
@Override
public void doSomeWork(String parameter) {
    ActivityExecutionContext context = contextProvider.getActivityExecutionContext();
    ActivityTask task = context.getTask();
    String taskid = task.getActivityId();
    System.out.println("Processed activity task with id: " + taskid);
}
项目:WaterFlow    文件:ActivityPoller.java   
public static RespondActivityTaskCompletedRequest createRespondActivityCompleted(ActivityTask task, String result) {
    return new RespondActivityTaskCompletedRequest()
            .withTaskToken(task.getTaskToken())
            .withResult(trimToMaxLength(result, MAX_RESULT_LENGTH));
}
项目:aws-doc-sdk-examples    文件:ActivityWorkerWithGracefulShutdown.java   
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;
            }

            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()));
            }
        }
    }
}
项目:WaterFlow    文件:ActivityContext.java   
public abstract ActivityTask task();