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
Showing
1 changed file
with
11 additions
and
23 deletions
... | @@ -301,16 +301,14 @@ public class IntentManager | ... | @@ -301,16 +301,14 @@ public class IntentManager |
301 | }); | 301 | }); |
302 | } | 302 | } |
303 | 303 | ||
304 | - private class IntentBatchProcess implements Runnable { | 304 | + private class InternalBatchDelegate implements IntentBatchDelegate { |
305 | - | ||
306 | - protected final Collection<IntentData> data; | ||
307 | - | ||
308 | - IntentBatchProcess(Collection<IntentData> data) { | ||
309 | - this.data = checkNotNull(data); | ||
310 | - } | ||
311 | - | ||
312 | @Override | 305 | @Override |
313 | - public void run() { | 306 | + public void execute(Collection<IntentData> operations) { |
307 | + log.debug("Execute {} operation(s).", operations.size()); | ||
308 | + log.trace("Execute operations: {}", operations); | ||
309 | + | ||
310 | + // batchExecutor is single-threaded, so only one batch is in flight at a time | ||
311 | + batchExecutor.execute(() -> { | ||
314 | try { | 312 | try { |
315 | /* | 313 | /* |
316 | 1. wrap each intentdata in a runnable and submit | 314 | 1. wrap each intentdata in a runnable and submit |
... | @@ -318,7 +316,7 @@ public class IntentManager | ... | @@ -318,7 +316,7 @@ public class IntentManager |
318 | 3. accumulate results and submit batch write of IntentData to store | 316 | 3. accumulate results and submit batch write of IntentData to store |
319 | (we can also try to update these individually) | 317 | (we can also try to update these individually) |
320 | */ | 318 | */ |
321 | - submitUpdates(waitForFutures(createIntentUpdates())); | 319 | + submitUpdates(waitForFutures(createIntentUpdates(operations))); |
322 | } catch (Exception e) { | 320 | } catch (Exception e) { |
323 | log.error("Error submitting batches:", e); | 321 | log.error("Error submitting batches:", e); |
324 | // FIXME incomplete Intents should be cleaned up | 322 | // FIXME incomplete Intents should be cleaned up |
... | @@ -331,9 +329,11 @@ public class IntentManager | ... | @@ -331,9 +329,11 @@ public class IntentManager |
331 | // batchService.removeIntentOperations(data); | 329 | // batchService.removeIntentOperations(data); |
332 | } | 330 | } |
333 | accumulator.ready(); | 331 | accumulator.ready(); |
332 | + }); | ||
333 | + } | ||
334 | } | 334 | } |
335 | 335 | ||
336 | - private List<Future<FinalIntentProcessPhase>> createIntentUpdates() { | 336 | + private List<Future<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) { |
337 | return data.stream() | 337 | return data.stream() |
338 | .map(IntentManager.this::submitIntentData) | 338 | .map(IntentManager.this::submitIntentData) |
339 | .collect(Collectors.toList()); | 339 | .collect(Collectors.toList()); |
... | @@ -357,18 +357,6 @@ public class IntentManager | ... | @@ -357,18 +357,6 @@ public class IntentManager |
357 | .map(FinalIntentProcessPhase::data) | 357 | .map(FinalIntentProcessPhase::data) |
358 | .collect(Collectors.toList())); | 358 | .collect(Collectors.toList())); |
359 | } | 359 | } |
360 | - } | ||
361 | - | ||
362 | - private class InternalBatchDelegate implements IntentBatchDelegate { | ||
363 | - @Override | ||
364 | - public void execute(Collection<IntentData> operations) { | ||
365 | - log.debug("Execute {} operation(s).", operations.size()); | ||
366 | - log.trace("Execute operations: {}", operations); | ||
367 | - | ||
368 | - // batchExecutor is single-threaded, so only one batch is in flight at a time | ||
369 | - batchExecutor.execute(new IntentBatchProcess(operations)); | ||
370 | - } | ||
371 | - } | ||
372 | 360 | ||
373 | private class InternalIntentProcessor implements IntentProcessor { | 361 | private class InternalIntentProcessor implements IntentProcessor { |
374 | @Override | 362 | @Override | ... | ... |
-
Please register or login to post a comment