DownloadProgressTracker: convert to CompletableFuture
@@ -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;
}
}
