com.google.bitcoin.core
Class DownloadListener

java.lang.Object
  extended by com.google.bitcoin.core.AbstractPeerEventListener
      extended by com.google.bitcoin.core.DownloadListener
All Implemented Interfaces:
PeerEventListener

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 Summary
DownloadListener()
           
 
Method Summary
 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.
 
Methods inherited from class com.google.bitcoin.core.AbstractPeerEventListener
getData, onPeerConnected, onPeerDisconnected, onPreMessageReceived, onTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadListener

public DownloadListener()
Method Detail

onChainDownloadStarted

public void onChainDownloadStarted(Peer peer,
                                   int blocksLeft)
Description copied from interface: PeerEventListener
Called when a download is started with the initial number of blocks to be downloaded.

Specified by:
onChainDownloadStarted in interface PeerEventListener
Overrides:
onChainDownloadStarted in class AbstractPeerEventListener
Parameters:
peer - the peer receiving the block
blocksLeft - the number of blocks left to download

onBlocksDownloaded

public void onBlocksDownloaded(Peer peer,
                               Block block,
                               int blocksLeft)
Description copied from interface: PeerEventListener
Called on a Peer thread when a block is received.

The block may have transactions or may be a header only once getheaders is implemented.

Specified by:
onBlocksDownloaded in interface PeerEventListener
Overrides:
onBlocksDownloaded in class AbstractPeerEventListener
Parameters:
peer - the peer receiving the block
block - the downloaded block
blocksLeft - the number of blocks left to download

progress

protected void progress(double pct,
                        int blocksSoFar,
                        Date date)
Called when download progress is made.

Parameters:
pct - the percentage of chain downloaded, estimated
date - 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 InterruptedException
Wait for the chain to be downloaded.

Throws:
InterruptedException


Copyright © 2014. All rights reserved.