Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Extract two methods from submitIntentData()

Change-Id: I2c75039bed836ec3695bee1c8a7664bea8779d9e
......@@ -294,18 +294,24 @@ public class IntentManager
}
private CompletableFuture<FinalIntentProcessPhase> submitIntentData(IntentData data) {
IntentProcessPhase initial = createInitialPhase(data);
return CompletableFuture.supplyAsync(() -> process(initial), workerExecutor);
}
private IntentProcessPhase createInitialPhase(IntentData data) {
IntentData current = store.getIntentData(data.key());
IntentProcessPhase initial = newInitialPhase(processor, data, current);
return CompletableFuture.supplyAsync(() -> {
Optional<IntentProcessPhase> currentPhase = Optional.of(initial);
IntentProcessPhase previousPhase = initial;
while (currentPhase.isPresent()) {
previousPhase = currentPhase.get();
currentPhase = previousPhase.execute();
}
return (FinalIntentProcessPhase) previousPhase;
}, workerExecutor);
return newInitialPhase(processor, data, current);
}
private FinalIntentProcessPhase process(IntentProcessPhase initial) {
Optional<IntentProcessPhase> currentPhase = Optional.of(initial);
IntentProcessPhase previousPhase = initial;
while (currentPhase.isPresent()) {
previousPhase = currentPhase.get();
currentPhase = previousPhase.execute();
}
return (FinalIntentProcessPhase) previousPhase;
}
private class InternalBatchDelegate implements IntentBatchDelegate {
......