mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-21 12:22:18 +02:00
Refactor: Reduce number of invocations of Stream#collect()
Change-Id: Idde16505cbe0a1e56e2b651678a0169df0d06bf7
This commit is contained in:
parent
4ce97ffbf9
commit
38a4798ea0
@ -54,6 +54,7 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static java.util.concurrent.Executors.newFixedThreadPool;
|
import static java.util.concurrent.Executors.newFixedThreadPool;
|
||||||
@ -339,26 +340,24 @@ public class IntentManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CompletableFuture<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) {
|
private Stream<CompletableFuture<FinalIntentProcessPhase>> createIntentUpdates(Collection<IntentData> data) {
|
||||||
return data.stream()
|
return data.stream()
|
||||||
.map(IntentManager.this::submitIntentData)
|
.map(IntentManager.this::submitIntentData);
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FinalIntentProcessPhase> waitForFutures(List<CompletableFuture<FinalIntentProcessPhase>> futures) {
|
private Stream<FinalIntentProcessPhase> waitForFutures(Stream<CompletableFuture<FinalIntentProcessPhase>> futures) {
|
||||||
return futures.stream()
|
return futures
|
||||||
.map(x -> x.exceptionally(e -> {
|
.map(x -> x.exceptionally(e -> {
|
||||||
//FIXME
|
//FIXME
|
||||||
log.warn("Future failed: {}", e);
|
log.warn("Future failed: {}", e);
|
||||||
return null;
|
return null;
|
||||||
}))
|
}))
|
||||||
.map(CompletableFuture::join)
|
.map(CompletableFuture::join)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull);
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void submitUpdates(List<FinalIntentProcessPhase> updates) {
|
private void submitUpdates(Stream<FinalIntentProcessPhase> updates) {
|
||||||
store.batchWrite(updates.stream()
|
store.batchWrite(updates
|
||||||
.map(FinalIntentProcessPhase::data)
|
.map(FinalIntentProcessPhase::data)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user