mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Rename DownloadListener to DownloadProgressTracker
This commit is contained in:
parent
36850b1d0e
commit
b25899de58
@ -23,15 +23,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.Semaphore;
|
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
|
* <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
|
* 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>
|
* progress method to update a GUI instead.</p>
|
||||||
*/
|
*/
|
||||||
public class DownloadListener extends AbstractPeerEventListener {
|
public class DownloadProgressTracker extends AbstractPeerEventListener {
|
||||||
private static final Logger log = LoggerFactory.getLogger(DownloadListener.class);
|
private static final Logger log = LoggerFactory.getLogger(DownloadProgressTracker.class);
|
||||||
private int originalBlocksLeft = -1;
|
private int originalBlocksLeft = -1;
|
||||||
private int lastPercent = 0;
|
private int lastPercent = 0;
|
||||||
private Semaphore done = new Semaphore(0);
|
private Semaphore done = new Semaphore(0);
|
@ -18,7 +18,6 @@
|
|||||||
package org.bitcoinj.core;
|
package org.bitcoinj.core;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
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
|
* 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.
|
* from at least one peer all the blocks that are in that peer's inventory.
|
||||||
*/
|
*/
|
||||||
public void downloadBlockChain() {
|
public void downloadBlockChain() {
|
||||||
DownloadListener listener = new DownloadListener();
|
DownloadProgressTracker listener = new DownloadProgressTracker();
|
||||||
startBlockChainDownload(listener);
|
startBlockChainDownload(listener);
|
||||||
try {
|
try {
|
||||||
listener.await();
|
listener.await();
|
||||||
|
@ -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
|
* 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.
|
* too, due to some missing implementation code.
|
||||||
*/
|
*/
|
||||||
public WalletAppKit setDownloadListener(PeerEventListener listener) {
|
public WalletAppKit setDownloadListener(PeerEventListener listener) {
|
||||||
@ -305,7 +305,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
completeExtensionInitiations(vPeerGroup);
|
completeExtensionInitiations(vPeerGroup);
|
||||||
|
|
||||||
// TODO: Be able to use the provided download listener when doing a blocking startup.
|
// 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);
|
vPeerGroup.startBlockChainDownload(listener);
|
||||||
listener.await();
|
listener.await();
|
||||||
} else {
|
} else {
|
||||||
@ -313,7 +313,7 @@ public class WalletAppKit extends AbstractIdleService {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(@Nullable Object result) {
|
public void onSuccess(@Nullable Object result) {
|
||||||
completeExtensionInitiations(vPeerGroup);
|
completeExtensionInitiations(vPeerGroup);
|
||||||
final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
|
final PeerEventListener l = downloadListener == null ? new DownloadProgressTracker() : downloadListener;
|
||||||
vPeerGroup.startBlockChainDownload(l);
|
vPeerGroup.startBlockChainDownload(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class RestoreFromSeed {
|
|||||||
chain.addWallet(wallet);
|
chain.addWallet(wallet);
|
||||||
peers.addWallet(wallet);
|
peers.addWallet(wallet);
|
||||||
|
|
||||||
DownloadListener bListener = new DownloadListener() {
|
DownloadProgressTracker bListener = new DownloadProgressTracker() {
|
||||||
@Override
|
@Override
|
||||||
public void doneDownload() {
|
public void doneDownload() {
|
||||||
System.out.println("blockchain downloaded");
|
System.out.println("blockchain downloaded");
|
||||||
|
@ -860,7 +860,7 @@ public class WalletTool {
|
|||||||
try {
|
try {
|
||||||
setup();
|
setup();
|
||||||
int startTransactions = wallet.getTransactions(true).size();
|
int startTransactions = wallet.getTransactions(true).size();
|
||||||
DownloadListener listener = new DownloadListener();
|
DownloadProgressTracker listener = new DownloadProgressTracker();
|
||||||
peers.start();
|
peers.start();
|
||||||
peers.startBlockChainDownload(listener);
|
peers.startBlockChainDownload(listener);
|
||||||
try {
|
try {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package wallettemplate;
|
package wallettemplate;
|
||||||
|
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.DownloadListener;
|
import org.bitcoinj.core.DownloadProgressTracker;
|
||||||
import org.bitcoinj.utils.MonetaryFormat;
|
import org.bitcoinj.utils.MonetaryFormat;
|
||||||
import com.subgraph.orchid.TorClient;
|
import com.subgraph.orchid.TorClient;
|
||||||
import com.subgraph.orchid.TorInitializationListener;
|
import com.subgraph.orchid.TorInitializationListener;
|
||||||
@ -121,7 +121,7 @@ public class MainController {
|
|||||||
group.play();
|
group.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadListener progressBarUpdater() {
|
public DownloadProgressTracker progressBarUpdater() {
|
||||||
return model.getDownloadListener();
|
return model.getDownloadProgressTracker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class BitcoinUIModel {
|
|||||||
address.set(wallet.currentReceiveAddress());
|
address.set(wallet.currentReceiveAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProgressBarUpdater extends DownloadListener {
|
private class ProgressBarUpdater extends DownloadProgressTracker {
|
||||||
@Override
|
@Override
|
||||||
protected void progress(double pct, int blocksLeft, Date date) {
|
protected void progress(double pct, int blocksLeft, Date date) {
|
||||||
super.progress(pct, blocksLeft, 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; }
|
public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user