Rename DownloadListener to DownloadProgressTracker

This commit is contained in:
Mike Hearn 2014-12-18 13:37:05 +01:00
parent 36850b1d0e
commit b25899de58
7 changed files with 14 additions and 17 deletions

View File

@ -23,15 +23,13 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.concurrent.Semaphore;
// TODO: Rename this to DownloadProgressTracker or something more appropriate.
/**
* <p>An implementation of {@link AbstractPeerEventListener} that listens to chain download events and tracks progress
* as a percentage. The default implementation prints progress to stdout, but you can subclass it and override the
* progress method to update a GUI instead.</p>
*/
public class DownloadListener extends AbstractPeerEventListener {
private static final Logger log = LoggerFactory.getLogger(DownloadListener.class);
public class DownloadProgressTracker extends AbstractPeerEventListener {
private static final Logger log = LoggerFactory.getLogger(DownloadProgressTracker.class);
private int originalBlocksLeft = -1;
private int lastPercent = 0;
private Semaphore done = new Semaphore(0);

View File

@ -18,7 +18,6 @@
package org.bitcoinj.core;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
@ -1221,13 +1220,13 @@ public class PeerGroup implements TransactionBroadcaster {
}
/**
* Download the blockchain from peers. Convenience that uses a {@link DownloadListener} for you.<p>
* Download the blockchain from peers. Convenience that uses a {@link DownloadProgressTracker} for you.<p>
*
* This method waits until the download is complete. "Complete" is defined as downloading
* from at least one peer all the blocks that are in that peer's inventory.
*/
public void downloadBlockChain() {
DownloadListener listener = new DownloadListener();
DownloadProgressTracker listener = new DownloadProgressTracker();
startBlockChainDownload(listener);
try {
listener.await();

View File

@ -129,7 +129,7 @@ public class WalletAppKit extends AbstractIdleService {
/**
* If you want to learn about the sync process, you can provide a listener here. For instance, a
* {@link DownloadListener} is a good choice. This has no effect unless setBlockingStartup(false) has been called
* {@link org.bitcoinj.core.DownloadProgressTracker} is a good choice. This has no effect unless setBlockingStartup(false) has been called
* too, due to some missing implementation code.
*/
public WalletAppKit setDownloadListener(PeerEventListener listener) {
@ -305,7 +305,7 @@ public class WalletAppKit extends AbstractIdleService {
completeExtensionInitiations(vPeerGroup);
// TODO: Be able to use the provided download listener when doing a blocking startup.
final DownloadListener listener = new DownloadListener();
final DownloadProgressTracker listener = new DownloadProgressTracker();
vPeerGroup.startBlockChainDownload(listener);
listener.await();
} else {
@ -313,7 +313,7 @@ public class WalletAppKit extends AbstractIdleService {
@Override
public void onSuccess(@Nullable Object result) {
completeExtensionInitiations(vPeerGroup);
final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
final PeerEventListener l = downloadListener == null ? new DownloadProgressTracker() : downloadListener;
vPeerGroup.startBlockChainDownload(l);
}

View File

@ -50,7 +50,7 @@ public class RestoreFromSeed {
chain.addWallet(wallet);
peers.addWallet(wallet);
DownloadListener bListener = new DownloadListener() {
DownloadProgressTracker bListener = new DownloadProgressTracker() {
@Override
public void doneDownload() {
System.out.println("blockchain downloaded");

View File

@ -860,7 +860,7 @@ public class WalletTool {
try {
setup();
int startTransactions = wallet.getTransactions(true).size();
DownloadListener listener = new DownloadListener();
DownloadProgressTracker listener = new DownloadProgressTracker();
peers.start();
peers.startBlockChainDownload(listener);
try {

View File

@ -1,7 +1,7 @@
package wallettemplate;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.DownloadListener;
import org.bitcoinj.core.DownloadProgressTracker;
import org.bitcoinj.utils.MonetaryFormat;
import com.subgraph.orchid.TorClient;
import com.subgraph.orchid.TorInitializationListener;
@ -121,7 +121,7 @@ public class MainController {
group.play();
}
public DownloadListener progressBarUpdater() {
return model.getDownloadListener();
public DownloadProgressTracker progressBarUpdater() {
return model.getDownloadProgressTracker();
}
}

View File

@ -41,7 +41,7 @@ public class BitcoinUIModel {
address.set(wallet.currentReceiveAddress());
}
private class ProgressBarUpdater extends DownloadListener {
private class ProgressBarUpdater extends DownloadProgressTracker {
@Override
protected void progress(double pct, int blocksLeft, Date date) {
super.progress(pct, blocksLeft, date);
@ -55,7 +55,7 @@ public class BitcoinUIModel {
}
}
public DownloadListener getDownloadListener() { return syncProgressUpdater; }
public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; }
public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; }