Package org.bitcoinj.core.listeners
Class DownloadProgressTracker
java.lang.Object
org.bitcoinj.core.listeners.DownloadProgressTracker
- All Implemented Interfaces:
BlockchainDownloadEventListener,BlocksDownloadedEventListener,ChainDownloadStartedEventListener
An implementation of BlockchainDownloadEventListener 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidawait()Wait for the chain to be downloaded.protected voidCalled when we are done downloading the block chain.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.voidonBlocksDownloaded(Peer peer, Block block, FilteredBlock filteredBlock, int blocksLeft) Called on a Peer thread when a block is received.voidonChainDownloadStarted(Peer peer, int blocksLeft) Called when a download is started with the initial number of blocks to be downloaded.protected voidCalled when download progress is made.protected voidstartDownload(int blocks) Called when download is initiated.
-
Constructor Details
-
DownloadProgressTracker
public DownloadProgressTracker()
-
-
Method Details
-
onChainDownloadStarted
Description copied from interface:ChainDownloadStartedEventListenerCalled when a download is started with the initial number of blocks to be downloaded.- Specified by:
onChainDownloadStartedin interfaceChainDownloadStartedEventListener- Parameters:
peer- the peer receiving the blockblocksLeft- the number of blocks left to download
-
onBlocksDownloaded
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) Description copied from interface:BlocksDownloadedEventListenerCalled on a Peer thread when a block is received.
The block may be a Block object that contains transactions, a Block object that is only a header when fast catchup is being used. If set, filteredBlock can be used to retrieve the list of associated transactions.
- Specified by:
onBlocksDownloadedin interfaceBlocksDownloadedEventListener- Parameters:
peer- the peer receiving the blockblock- the downloaded blockfilteredBlock- if non-null, the object that wraps the block header passed as the block param.blocksLeft- the number of blocks left to download
-
progress
Called when download progress is made.- Parameters:
pct- the percentage of chain downloaded, estimatedtime- the time of the last block downloaded
-
startDownload
protected void startDownload(int blocks) Called when download is initiated.- Parameters:
blocks- the number of blocks to download, estimated
-
doneDownload
protected void doneDownload()Called when we are done downloading the block chain. -
await
Wait for the chain to be downloaded.- Throws:
InterruptedException
-
getFuture
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.
-