public class DownloadListener 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 |
---|
DownloadListener() |
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.
|
void |
onBlocksDownloaded(Peer peer,
Block block,
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, 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, int blocksLeft)
PeerEventListener
The block may have transactions or may be a header only once getheaders is implemented.
onBlocksDownloaded
in interface PeerEventListener
onBlocksDownloaded
in class AbstractPeerEventListener
peer
- the peer receiving the blockblock
- the downloaded blockblocksLeft
- 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
Copyright © 2014. All rights reserved.