TunnelManager: Enumerate running tunnels only once

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland 2018-01-06 05:09:53 -06:00
parent df7d18fb5d
commit 2315a699fb

View File

@ -87,13 +87,11 @@ public final class TunnelManager {
public void onCreate() { public void onCreate() {
Log.v(TAG, "onCreate triggered"); Log.v(TAG, "onCreate triggered");
configStore.enumerate() configStore.enumerate().thenAcceptBoth(backend.enumerate(), (names, running) -> {
.thenApply(names -> StreamSupport.stream(names) for (final String name : names) {
.map(this::add) add(name, null, running.contains(name) ? State.UP : State.DOWN);
.map(Tunnel::getStateAsync) }
.toArray(CompletableFuture[]::new)) }).whenComplete(ExceptionLoggers.D);
.thenCompose(CompletableFuture::allOf)
.whenComplete(ExceptionLoggers.E);
} }
public CompletionStage<Void> restoreState() { public CompletionStage<Void> restoreState() {