0

I am trying to schedule an activity in Amazon SWF. Initially, I used to loop through a list and schedule the activity for each value of the list. But this would invoke the activities in parallel which I did not want. So, I modified my code to do something like this:

Promise<Void> promiseArg = null;
for(Integer i : IntegerList){
   Promise<Void> nextArg = activityClient.activity1(i);
   promiseArg = nextArg;
}

Though code is working, I am not sure if this is the right way to do it. Any comments would be helpful.

coder
  • 171
  • 1
  • 5
  • It might make more sense to pass the promise to the activity itself (i.e. `promise = activityClient.activity1(i, promise)`). – Andres Riofrio Aug 06 '12 at 21:33

1 Answers1

0

What is the point of using promiseArg if it is unused?

If you want them to be dependent on prev method call, create an Asynchronous method and call that with promise variable.

//Main method of decider.
Promise<Integer> promiseArg = null;
Promise<Integer> nextArg = activityClient.activity1(i, 1);
for(Integer i : IntegerList){
    Promise<Integer> nextArg = fun(nextArg, Promise.asPromise(i));
}


@Asynchronous
public Promise<Integer> fun(Promise<int> nextArg, int i) {
    System.out.println("Testing with current value: " + Integer.toString(nextArg.get()));
    return activityClient.activity1(i, nextArg.get());
}

I haven't tested it but it should work.

Apart from this, you can also try passing prev Promise variable to activity itself with @Wait annotation in the activity declaration.

Something like this,

prevArgs = activityClient.activity1(i, prevArg));

with Activity like,

XYZ activity1(int i,@Wait Promise<int> prevArgs){
   //Please check if int should be used instead of Promise<int>
}
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85