mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 22:58:32 +01:00
WalletAppKit: make sure downloadListener is never null
This simplifies the `if (blockingStartup)` and its `else` block. This change makes way for further simplification.
This commit is contained in:
parent
4bd79448ee
commit
ff674ea605
1 changed files with 5 additions and 7 deletions
|
@ -100,7 +100,7 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
|
|
||||||
protected boolean useAutoSave = true;
|
protected boolean useAutoSave = true;
|
||||||
protected PeerAddress[] peerAddresses;
|
protected PeerAddress[] peerAddresses;
|
||||||
protected DownloadProgressTracker downloadListener;
|
protected DownloadProgressTracker downloadListener = new DownloadProgressTracker();
|
||||||
protected boolean autoStop = true;
|
protected boolean autoStop = true;
|
||||||
protected InputStream checkpoints;
|
protected InputStream checkpoints;
|
||||||
protected boolean blockingStartup = true;
|
protected boolean blockingStartup = true;
|
||||||
|
@ -179,6 +179,7 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
* too, due to some missing implementation code.
|
* too, due to some missing implementation code.
|
||||||
*/
|
*/
|
||||||
public WalletAppKit setDownloadListener(DownloadProgressTracker listener) {
|
public WalletAppKit setDownloadListener(DownloadProgressTracker listener) {
|
||||||
|
checkNotNull(listener);
|
||||||
this.downloadListener = listener;
|
this.downloadListener = listener;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -384,15 +385,12 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
// Make sure we shut down cleanly.
|
// Make sure we shut down cleanly.
|
||||||
installShutdownHook();
|
installShutdownHook();
|
||||||
|
|
||||||
// TODO: Be able to use the provided download listener when doing a blocking startup.
|
vPeerGroup.startBlockChainDownload(downloadListener);
|
||||||
final DownloadProgressTracker listener = new DownloadProgressTracker();
|
downloadListener.await();
|
||||||
vPeerGroup.startBlockChainDownload(listener);
|
|
||||||
listener.await();
|
|
||||||
} else {
|
} else {
|
||||||
vPeerGroup.startAsync().whenComplete((result, t) -> {
|
vPeerGroup.startAsync().whenComplete((result, t) -> {
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
final DownloadProgressTracker l = downloadListener == null ? new DownloadProgressTracker() : downloadListener;
|
vPeerGroup.startBlockChainDownload(downloadListener);
|
||||||
vPeerGroup.startBlockChainDownload(l);
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(t);
|
throw new RuntimeException(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue