WalletAppKit: simplify blocking startup
* Use `startAsync()` for the blocking case, too. Since we were already
waiting on `downloadListner.await()`
* Make sure `installShutdownHook()` is called in both cases (bug fix)
* Add more comments
@@ -378,16 +378,11 @@ public class WalletAppKit extends AbstractIdleService {
}
vChain.addWallet(vWallet);
vPeerGroup.addWallet(vWallet);
- onSetupCompleted();
- if (blockingStartup) {
- vPeerGroup.start();
- // Make sure we shut down cleanly.
- installShutdownHook();
+ // vChain, vWallet, and vPeerGroup all initialized; allow subclass (if any) a chance to adjust configuration
+ onSetupCompleted();
- vPeerGroup.startBlockChainDownload(downloadListener);
- downloadListener.await();
- } else {
+ // Start the PeerGroup (asynchronously) and start downloading the blockchain (asynchronously)
vPeerGroup.startAsync().whenComplete((result, t) -> {
if (t == null) {
vPeerGroup.startBlockChainDownload(downloadListener);
@@ -395,6 +390,12 @@ public class WalletAppKit extends AbstractIdleService {
throw new RuntimeException(t);
}
});
+
+ // Make sure we shut down cleanly.
+ installShutdownHook();
+
+ if (blockingStartup) {
+ downloadListener.await(); // Wait for the blockchain to download
}
}
