Package org.bitcoinj.core.listeners
Class DownloadProgressTracker
- java.lang.Object
-
- org.bitcoinj.core.listeners.AbstractPeerDataEventListener
-
- org.bitcoinj.core.listeners.DownloadProgressTracker
-
- All Implemented Interfaces:
BlocksDownloadedEventListener
,ChainDownloadStartedEventListener
,GetDataEventListener
,PeerDataEventListener
,PreMessageReceivedEventListener
public class DownloadProgressTracker extends AbstractPeerDataEventListener
An implementation of
AbstractPeerDataEventListener
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 Constructor Description DownloadProgressTracker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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<java.lang.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, java.util.Date date)
Called when download progress is made.protected void
startDownload(int blocks)
Called when download is initiated.-
Methods inherited from class org.bitcoinj.core.listeners.AbstractPeerDataEventListener
getData, onPreMessageReceived
-
-
-
-
Method Detail
-
onChainDownloadStarted
public void onChainDownloadStarted(Peer peer, int blocksLeft)
Description copied from interface:ChainDownloadStartedEventListener
Called when a download is started with the initial number of blocks to be downloaded.- Specified by:
onChainDownloadStarted
in interfaceChainDownloadStartedEventListener
- Overrides:
onChainDownloadStarted
in classAbstractPeerDataEventListener
- 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:BlocksDownloadedEventListener
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.
- Specified by:
onBlocksDownloaded
in interfaceBlocksDownloadedEventListener
- Overrides:
onBlocksDownloaded
in classAbstractPeerDataEventListener
- 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
protected void progress(double pct, int blocksSoFar, java.util.Date date)
Called when download progress is made.- Parameters:
pct
- the percentage of chain downloaded, estimateddate
- the date 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
public void await() throws java.lang.InterruptedException
Wait for the chain to be downloaded.- Throws:
java.lang.InterruptedException
-
getFuture
public com.google.common.util.concurrent.ListenableFuture<java.lang.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.
-
-