model: Remove confusing uses of completion chaining
This looks like the builder pattern, but isn't. Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
77fdd7c883
commit
e70b242c01
@ -95,24 +95,21 @@ public class Tunnel extends BaseObservable implements Keyed<String> {
|
||||
return CompletableFuture.completedFuture(statistics);
|
||||
}
|
||||
|
||||
Config onConfigChanged(final Config config) {
|
||||
void onConfigChanged(final Config config) {
|
||||
this.config = config;
|
||||
notifyPropertyChanged(BR.config);
|
||||
return config;
|
||||
}
|
||||
|
||||
State onStateChanged(final State state) {
|
||||
void onStateChanged(final State state) {
|
||||
if (state != State.UP)
|
||||
onStatisticsChanged(null);
|
||||
this.state = state;
|
||||
notifyPropertyChanged(BR.state);
|
||||
return state;
|
||||
}
|
||||
|
||||
Statistics onStatisticsChanged(final Statistics statistics) {
|
||||
void onStatisticsChanged(final Statistics statistics) {
|
||||
this.statistics = statistics;
|
||||
notifyPropertyChanged(BR.statistics);
|
||||
return statistics;
|
||||
}
|
||||
|
||||
public CompletionStage<Config> setConfig(@NonNull final Config config) {
|
||||
|
@ -85,18 +85,24 @@ public final class TunnelManager {
|
||||
}
|
||||
|
||||
CompletionStage<Config> getTunnelConfig(final Tunnel tunnel) {
|
||||
return asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName()))
|
||||
.thenApply(tunnel::onConfigChanged);
|
||||
final CompletionStage<Config> completion =
|
||||
asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName()));
|
||||
completion.thenAccept(tunnel::onConfigChanged);
|
||||
return completion;
|
||||
}
|
||||
|
||||
CompletionStage<State> getTunnelState(final Tunnel tunnel) {
|
||||
return asyncWorker.supplyAsync(() -> backend.getState(tunnel))
|
||||
.thenApply(tunnel::onStateChanged);
|
||||
final CompletionStage<State> completion =
|
||||
asyncWorker.supplyAsync(() -> backend.getState(tunnel));
|
||||
completion.thenAccept(tunnel::onStateChanged);
|
||||
return completion;
|
||||
}
|
||||
|
||||
CompletionStage<Statistics> getTunnelStatistics(final Tunnel tunnel) {
|
||||
return asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel))
|
||||
.thenApply(tunnel::onStatisticsChanged);
|
||||
final CompletionStage<Statistics> completion =
|
||||
asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel));
|
||||
completion.thenAccept(tunnel::onStatisticsChanged);
|
||||
return completion;
|
||||
}
|
||||
|
||||
public ObservableKeyedList<String, Tunnel> getTunnels() {
|
||||
@ -136,14 +142,18 @@ public final class TunnelManager {
|
||||
}
|
||||
|
||||
CompletionStage<Config> setTunnelConfig(final Tunnel tunnel, final Config config) {
|
||||
return asyncWorker.supplyAsync(() -> {
|
||||
final CompletionStage<Config> completion = asyncWorker.supplyAsync(() -> {
|
||||
final Config appliedConfig = backend.applyConfig(tunnel, config);
|
||||
return configStore.save(tunnel.getName(), appliedConfig);
|
||||
}).thenApply(tunnel::onConfigChanged);
|
||||
});
|
||||
completion.thenAccept(tunnel::onConfigChanged);
|
||||
return completion;
|
||||
}
|
||||
|
||||
CompletionStage<State> setTunnelState(final Tunnel tunnel, final State state) {
|
||||
return asyncWorker.supplyAsync(() -> backend.setState(tunnel, state))
|
||||
.thenApply(tunnel::onStateChanged);
|
||||
final CompletionStage<State> completion =
|
||||
asyncWorker.supplyAsync(() -> backend.setState(tunnel, state));
|
||||
completion.thenAccept(tunnel::onStateChanged);
|
||||
return completion;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user