Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: remove an extra inner class, IntentBatchProcess

IntentBatchProcess wraps a collection of IntentData to just behave
as Runnable. It can be removed by lambda expression

Change-Id: Ic6e1ae840311faff6314a8ce9db9a5277d8595cd
......@@ -301,16 +301,14 @@ public class IntentManager
});
}
private class IntentBatchProcess implements Runnable {
protected final Collection<IntentData> data;
IntentBatchProcess(Collection<IntentData> data) {
this.data = checkNotNull(data);
}
private class InternalBatchDelegate implements IntentBatchDelegate {
@Override
public void run() {
public void execute(Collection<IntentData> operations) {
log.debug("Execute {} operation(s).", operations.size());
log.trace("Execute operations: {}", operations);
// batchExecutor is single-threaded, so only one batch is in flight at a time
batchExecutor.execute(() -> {
try {
/*
1. wrap each intentdata in a runnable and submit
......@@ -318,7 +316,7 @@ public class IntentManager
3. accumulate results and submit batch write of IntentData to store
(we can also try to update these individually)
*/
submitUpdates(waitForFutures(createIntentUpdates()));
submitUpdates(waitForFutures(createIntentUpdates(operations)));
} catch (Exception e) {
log.error("Error submitting batches:", e);
// FIXME incomplete Intents should be cleaned up
......@@ -331,9 +329,11 @@ public class IntentManager
// batchService.removeIntentOperations(data);
}
accumulator.ready();
});
}
}
private List<Future<FinalIntentProcessPhase>> createIntentUpdates() {
private List<Future<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) {
return data.stream()
.map(IntentManager.this::submitIntentData)
.collect(Collectors.toList());
......@@ -357,18 +357,6 @@ public class IntentManager
.map(FinalIntentProcessPhase::data)
.collect(Collectors.toList()));
}
}
private class InternalBatchDelegate implements IntentBatchDelegate {
@Override
public void execute(Collection<IntentData> operations) {
log.debug("Execute {} operation(s).", operations.size());
log.trace("Execute operations: {}", operations);
// batchExecutor is single-threaded, so only one batch is in flight at a time
batchExecutor.execute(new IntentBatchProcess(operations));
}
}
private class InternalIntentProcessor implements IntentProcessor {
@Override
......