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);
|
return CompletableFuture.completedFuture(statistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
Config onConfigChanged(final Config config) {
|
void onConfigChanged(final Config config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
notifyPropertyChanged(BR.config);
|
notifyPropertyChanged(BR.config);
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
State onStateChanged(final State state) {
|
void onStateChanged(final State state) {
|
||||||
if (state != State.UP)
|
if (state != State.UP)
|
||||||
onStatisticsChanged(null);
|
onStatisticsChanged(null);
|
||||||
this.state = state;
|
this.state = state;
|
||||||
notifyPropertyChanged(BR.state);
|
notifyPropertyChanged(BR.state);
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Statistics onStatisticsChanged(final Statistics statistics) {
|
void onStatisticsChanged(final Statistics statistics) {
|
||||||
this.statistics = statistics;
|
this.statistics = statistics;
|
||||||
notifyPropertyChanged(BR.statistics);
|
notifyPropertyChanged(BR.statistics);
|
||||||
return statistics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletionStage<Config> setConfig(@NonNull final Config config) {
|
public CompletionStage<Config> setConfig(@NonNull final Config config) {
|
||||||
|
@ -85,18 +85,24 @@ public final class TunnelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompletionStage<Config> getTunnelConfig(final Tunnel tunnel) {
|
CompletionStage<Config> getTunnelConfig(final Tunnel tunnel) {
|
||||||
return asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName()))
|
final CompletionStage<Config> completion =
|
||||||
.thenApply(tunnel::onConfigChanged);
|
asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName()));
|
||||||
|
completion.thenAccept(tunnel::onConfigChanged);
|
||||||
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionStage<State> getTunnelState(final Tunnel tunnel) {
|
CompletionStage<State> getTunnelState(final Tunnel tunnel) {
|
||||||
return asyncWorker.supplyAsync(() -> backend.getState(tunnel))
|
final CompletionStage<State> completion =
|
||||||
.thenApply(tunnel::onStateChanged);
|
asyncWorker.supplyAsync(() -> backend.getState(tunnel));
|
||||||
|
completion.thenAccept(tunnel::onStateChanged);
|
||||||
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionStage<Statistics> getTunnelStatistics(final Tunnel tunnel) {
|
CompletionStage<Statistics> getTunnelStatistics(final Tunnel tunnel) {
|
||||||
return asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel))
|
final CompletionStage<Statistics> completion =
|
||||||
.thenApply(tunnel::onStatisticsChanged);
|
asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel));
|
||||||
|
completion.thenAccept(tunnel::onStatisticsChanged);
|
||||||
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableKeyedList<String, Tunnel> getTunnels() {
|
public ObservableKeyedList<String, Tunnel> getTunnels() {
|
||||||
@ -136,14 +142,18 @@ public final class TunnelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompletionStage<Config> setTunnelConfig(final Tunnel tunnel, final Config config) {
|
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);
|
final Config appliedConfig = backend.applyConfig(tunnel, config);
|
||||||
return configStore.save(tunnel.getName(), appliedConfig);
|
return configStore.save(tunnel.getName(), appliedConfig);
|
||||||
}).thenApply(tunnel::onConfigChanged);
|
});
|
||||||
|
completion.thenAccept(tunnel::onConfigChanged);
|
||||||
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionStage<State> setTunnelState(final Tunnel tunnel, final State state) {
|
CompletionStage<State> setTunnelState(final Tunnel tunnel, final State state) {
|
||||||
return asyncWorker.supplyAsync(() -> backend.setState(tunnel, state))
|
final CompletionStage<State> completion =
|
||||||
.thenApply(tunnel::onStateChanged);
|
asyncWorker.supplyAsync(() -> backend.setState(tunnel, state));
|
||||||
|
completion.thenAccept(tunnel::onStateChanged);
|
||||||
|
return completion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user