Switch Task
A task that chooses one of several tasks to run; every other one is skipped.
Register one with DagDef.Switch, then list what it can choose with SwitchRef.Case. The choice is the class of the task to run:
public class PickPath implements SwitchTask {
@Override
public Class<? extends Task> choose(Context context, Client client) {
return ((Number) client.getXCom("extract")).longValue() > 1000
? HandleLong.class
: HandleShort.class;
}
}Content copied to clipboard
The SDK runs choose and pushes the chosen task's ID as this task's return value, so execute is never called.
Only a Task class compiles as a choice. javac cannot tell whether it is a case of this switch, so a Task class that is not one compiles and fails when the task runs: the task instance is marked failed, and nothing is pushed or skipped.
Because a switch names a case by its class, two tasks that run the same class cannot both be cases of it; the second SwitchRef.Case call throws.