Committed by
Gerrit Code Review
Refactor: Use Tools.allOf() to wait until all tasks become completed
Change-Id: I2f032e4d8dd525c4dd40d7ad954dca8c5d33b159
Showing
1 changed file
with
5 additions
and
3 deletions
... | @@ -21,6 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -21,6 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate; |
21 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | import org.apache.felix.scr.annotations.Service; | 23 | import org.apache.felix.scr.annotations.Service; |
24 | +import org.onlab.util.Tools; | ||
24 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
25 | import org.onosproject.core.IdGenerator; | 26 | import org.onosproject.core.IdGenerator; |
26 | import org.onosproject.event.AbstractListenerManager; | 27 | import org.onosproject.event.AbstractListenerManager; |
... | @@ -322,16 +323,17 @@ public class IntentManager | ... | @@ -322,16 +323,17 @@ public class IntentManager |
322 | 3. accumulate results and submit batch write of IntentData to store | 323 | 3. accumulate results and submit batch write of IntentData to store |
323 | (we can also try to update these individually) | 324 | (we can also try to update these individually) |
324 | */ | 325 | */ |
325 | - store.batchWrite(operations.stream() | 326 | + List<CompletableFuture<IntentData>> futures = operations.stream() |
326 | .map(IntentManager.this::submitIntentData) | 327 | .map(IntentManager.this::submitIntentData) |
328 | + .map(x -> x.thenApply(FinalIntentProcessPhase::data)) | ||
327 | .map(x -> x.exceptionally(e -> { | 329 | .map(x -> x.exceptionally(e -> { |
328 | //FIXME | 330 | //FIXME |
329 | log.warn("Future failed: {}", e); | 331 | log.warn("Future failed: {}", e); |
330 | return null; | 332 | return null; |
331 | })) | 333 | })) |
332 | - .map(CompletableFuture::join) | 334 | + .collect(Collectors.toList()); |
335 | + store.batchWrite(Tools.allOf(futures).join().stream() | ||
333 | .filter(Objects::nonNull) | 336 | .filter(Objects::nonNull) |
334 | - .map(FinalIntentProcessPhase::data) | ||
335 | .collect(Collectors.toList())); | 337 | .collect(Collectors.toList())); |
336 | } catch (Exception e) { | 338 | } catch (Exception e) { |
337 | log.error("Error submitting batches:", e); | 339 | log.error("Error submitting batches:", e); | ... | ... |
-
Please register or login to post a comment