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.
|
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, onTransaction
public void onChainDownloadStarted(Peer peer, int blocksLeft)
PeerEventListener
onChainDownloadStarted
in interface PeerEventListener
onChainDownloadStarted
in class AbstractPeerEventListener
peer
- the peer receiving the blockblocksLeft
- the number of blocks left to downloadpublic void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft)
PeerEventListener
Called 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 PeerEventListener
onBlocksDownloaded
in class AbstractPeerEventListener
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 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
InterruptedException
public ListenableFuture<Long> getFuture()
Copyright © 2016. All rights reserved.