mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
DownloadProgressTracker: convert to CompletableFuture
This commit is contained in:
parent
eb56d71f8f
commit
5f69f769d6
1 changed files with 5 additions and 6 deletions
|
@ -21,8 +21,7 @@ import org.bitcoinj.core.Block;
|
|||
import org.bitcoinj.core.FilteredBlock;
|
||||
import org.bitcoinj.core.Peer;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import org.bitcoinj.utils.ListenableCompletableFuture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -40,7 +39,7 @@ public class DownloadProgressTracker extends AbstractPeerDataEventListener {
|
|||
private static final Logger log = LoggerFactory.getLogger(DownloadProgressTracker.class);
|
||||
private int originalBlocksLeft = -1;
|
||||
private int lastPercent = 0;
|
||||
private SettableFuture<Long> future = SettableFuture.create();
|
||||
private final ListenableCompletableFuture<Long> future = new ListenableCompletableFuture<>();
|
||||
private boolean caughtUp = false;
|
||||
|
||||
@Override
|
||||
|
@ -55,7 +54,7 @@ public class DownloadProgressTracker extends AbstractPeerDataEventListener {
|
|||
log.info("Chain download switched to {}", peer);
|
||||
if (blocksLeft == 0) {
|
||||
doneDownload();
|
||||
future.set(peer.getBestHeight());
|
||||
future.complete(peer.getBestHeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +70,7 @@ public class DownloadProgressTracker extends AbstractPeerDataEventListener {
|
|||
progress(lastPercent, blocksLeft, new Date(block.getTimeSeconds() * 1000));
|
||||
}
|
||||
doneDownload();
|
||||
future.set(peer.getBestHeight());
|
||||
future.complete(peer.getBestHeight());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -127,7 +126,7 @@ public class DownloadProgressTracker extends AbstractPeerDataEventListener {
|
|||
* Returns a listenable future that completes with the height of the best chain (as reported by the peer) once chain
|
||||
* download seems to be finished.
|
||||
*/
|
||||
public ListenableFuture<Long> getFuture() {
|
||||
public ListenableCompletableFuture<Long> getFuture() {
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue