Java 类com.amazonaws.services.simpleworkflow.flow.ActivityExecutionContext 实例源码

项目:Camel    文件:CamelActivityImplementation.java   
@Override
protected String execute(String input, ActivityExecutionContext context) throws ActivityFailureException, CancellationException {
    Object[] inputParameters = converter.fromData(input, Object[].class);
    CurrentActivityExecutionContext.set(context);
    Object result = null;

    ActivityExecutionContext executionContext = contextProvider.getActivityExecutionContext();
    String taskToken = executionContext.getTaskToken();

    try {
        result = swfWorkflowConsumer.processActivity(inputParameters, taskToken);
    } catch (InvocationTargetException invocationException) {
        throwActivityFailureException(invocationException.getTargetException() != null ? invocationException.getTargetException() : invocationException);
    } catch (IllegalArgumentException illegalArgumentException) {
        throwActivityFailureException(illegalArgumentException);
    } catch (IllegalAccessException illegalAccessException) {
        throwActivityFailureException(illegalAccessException);
    } catch (Exception e) {
        throwActivityFailureException(e);
    } finally {
        CurrentActivityExecutionContext.unset();
    }
    String resultSerialized = converter.toData(result);
    return resultSerialized;
}
项目:aws-flow-maven-eclipse-samples    文件:CommonRecipeActivitiesImpl.java   
@Override
public void delayActivity(long time) {
    calls.add("delayActivity");
    ActivityExecutionContextProvider provider = new ActivityExecutionContextProviderImpl();
    ActivityExecutionContext context = provider.getActivityExecutionContext();
    try {
        while (true) {
            Thread.sleep(time * 1000);
            context.recordActivityHeartbeat(null);
        }
    }
    catch (InterruptedException e) {

    }

}
项目:swf-starter    文件:S3StorageActivities.java   
/**
 * Heartbeat every 5 minutes. It is not a good idea to heartbeat too
 * frequently as each noteActivityProgress event ends up eating history
 * events count.
 *
 * @return time of the last heartbeat
 */
private long heartbeat(long lastHeartbeatTime, int progress) {
  if (System.currentTimeMillis() - lastHeartbeatTime > HEARTBEAT_INTERVAL) {
    ActivityExecutionContext context = contextProvider.getActivityExecutionContext();
    context.recordActivityHeartbeat(Integer.toString((progress)));
    lastHeartbeatTime = System.currentTimeMillis();
  }
  return lastHeartbeatTime;
}
项目:aws-flow-maven-eclipse-samples    文件:HumanTaskActivitiesImpl.java   
@Override
@ManualActivityCompletion
public String humanActivity() {
    ActivityExecutionContext executionContext = contextProvider.getActivityExecutionContext();
    String taskToken = executionContext.getTaskToken();
    System.out.println("Task received, completion token: " + taskToken);
    //This will not be returned to the caller
    return null;
}
项目: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    文件:SimpleStoreActivitiesS3Impl.java   
/**
 * Heartbeat every 5 minutes. It is not a good idea to heartbeat too
 * frequently as each noteActivityProgress event ends up eating history
 * events count.
 * 
 * @return time of the last heartbeat
 */
private long heartbeat(long lastHeartbeatTime, int progress) {
    if (System.currentTimeMillis() - lastHeartbeatTime > HEARTBEAT_INTERVAL) {
        ActivityExecutionContext context = contextProvider.getActivityExecutionContext();
        context.recordActivityHeartbeat(Integer.toString((progress)));
        lastHeartbeatTime = System.currentTimeMillis();
    }
    return lastHeartbeatTime;
}
项目: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);
}
项目:aws-flow-maven-eclipse-samples    文件:CronWithRetryWorkflowTest.java   
@Override
public void doSomeWork(String parameter) {
    // Reset counter on the new run which changes when workflow continues as new
    ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext();
    WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution();
    String runId = workflowExecution.getRunId();
    if (this.runId == null || !runId.equals(this.runId)) {
        runCount++;
    }
    this.runId = runId;
    workCount++;
    if (workCount % 2 != 0) {
        throw new RuntimeException("simulated failure to cause retry");
    }
}
项目:aws-flow-maven-eclipse-samples    文件:CronWorkflowTest.java   
@Override
public void doSomeWork(String parameter) {
    // Reset counter on the new run which changes when workflow continues as new
    ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext();
    WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution();
    String runId = workflowExecution.getRunId();
    if (this.runId == null || !runId.equals(this.runId)) {
        runCount++;
    }
    this.runId = runId;
    workCount++;
}
项目:aws-flow-maven-eclipse-samples    文件:PeriodicWorkflowTest.java   
@Override
public void doSomeWork(String parameter) {
    // Reset counter on the new run which changes when workflow continues as new
    ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext();
    WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution();
    String runId = workflowExecution.getRunId();
    if (this.runId != null && !runId.equals(this.runId)) {
        currentRunWorkCount = 0;
    }
    this.runId = runId;
    workCount++;
    currentRunWorkCount++;
}