summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-07 00:41:47 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-07 00:41:47 -0600
commite70b242c016709c41a09114996806fbdef30dd80 (patch)
tree008b081cce1873dec39c1472fb15aaed0bf3d4d7 /app
parent77fdd7c883086e698c83b2a2f5e58ff62359c5ea (diff)
model: Remove confusing uses of completion chaining
This looks like the builder pattern, but isn't. Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/wireguard/android/model/Tunnel.java9
-rw-r--r--app/src/main/java/com/wireguard/android/model/TunnelManager.java30
2 files changed, 23 insertions, 16 deletions
diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java
index 9bb7406c..e61ea095 100644
--- a/app/src/main/java/com/wireguard/android/model/Tunnel.java
+++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java
@@ -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) {
diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
index e802c152..beed16fe 100644
--- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java
+++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java
@@ -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;
}
}