public class DownloadProgressTracker extends AbstractPeerEventListener
An implementation of 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.
| Constructor and Description |
|---|
DownloadProgressTracker() |
| Modifier and Type | Method and Description |
|---|---|
void |
await()
Wait for the chain to be downloaded.
|
protected void |
doneDownload()
Called when we are done downloading the block chain.
|
com.google.common.util.concurrent.ListenableFuture<Long> |
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.
|
void |
onBlocksDownloaded(Peer peer,
Block block,
FilteredBlock filteredBlock,
int blocksLeft)
Called on a Peer thread when a block is received.
|
void |
onChainDownloadStarted(Peer peer,
int blocksLeft)
Called when a download is started with the initial number of blocks to be downloaded.
|
protected void |
progress(double pct,
int blocksSoFar,
Date date)
Called when download progress is made.
|
protected void |
startDownload(int blocks)
Called when download is initiated.
|
getData, onPeerConnected, onPeerDisconnected, onPeersDiscovered, onPreMessageReceived, onTransactionpublic void onChainDownloadStarted(Peer peer, int blocksLeft)
PeerEventListeneronChainDownloadStarted in interface PeerEventListeneronChainDownloadStarted in class AbstractPeerEventListenerpeer - the peer receiving the blockblocksLeft - the number of blocks left to downloadpublic void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft)
PeerEventListenerCalled 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.
onBlocksDownloaded in interface PeerEventListeneronBlocksDownloaded in class AbstractPeerEventListenerpeer - 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 downloadprotected void progress(double pct,
int blocksSoFar,
Date date)
pct - the percentage of chain downloaded, estimateddate - the date of the last block downloadedprotected void startDownload(int blocks)
blocks - the number of blocks to download, estimatedprotected void doneDownload()
public void await()
throws InterruptedException
InterruptedExceptionpublic com.google.common.util.concurrent.ListenableFuture<Long> getFuture()
Copyright © 2015. All rights reserved.