com.google.bitcoin.jni
Class NativePeerEventListener

java.lang.Object
  extended by com.google.bitcoin.jni.NativePeerEventListener
All Implemented Interfaces:
PeerEventListener

public class NativePeerEventListener
extends Object
implements PeerEventListener

An event listener that relays events to a native C++ object. A pointer to that object is stored in this class using JNI on the native side, thus several instances of this can point to different actual native implementations.


Field Summary
 long ptr
           
 
Constructor Summary
NativePeerEventListener()
           
 
Method Summary
 List<Message> getData(Peer peer, GetDataMessage m)
          Called when a peer receives a getdata message, usually in response to an "inv" being broadcast.
 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.
 void onPeerConnected(Peer peer, int peerCount)
          Called when a peer is connected.
 void onPeerDisconnected(Peer peer, int peerCount)
          Called when a peer is disconnected.
 Message onPreMessageReceived(Peer peer, Message m)
          Called when a message is received by a peer, before the message is processed.
 void onTransaction(Peer peer, Transaction t)
          Called when a new transaction is broadcast over the network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ptr

public long ptr
Constructor Detail

NativePeerEventListener

public NativePeerEventListener()
Method Detail

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
Parameters:
peer - the peer receiving the block
block - the downloaded block
blocksLeft - the number of blocks left to download

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
Parameters:
peer - the peer receiving the block
blocksLeft - the number of blocks left to download

onPeerConnected

public void onPeerConnected(Peer peer,
                            int peerCount)
Description copied from interface: PeerEventListener
Called when a peer is connected. If this listener is registered to a Peer instead of a PeerGroup, peerCount will always be 1.

Specified by:
onPeerConnected in interface PeerEventListener
peerCount - the total number of connected peers

onPeerDisconnected

public void onPeerDisconnected(Peer peer,
                               int peerCount)
Description copied from interface: PeerEventListener
Called when a peer is disconnected. Note that this won't be called if the listener is registered on a PeerGroup and the group is in the process of shutting down. If this listener is registered to a Peer instead of a PeerGroup, peerCount will always be 0.

Specified by:
onPeerDisconnected in interface PeerEventListener
peerCount - the total number of connected peers

onPreMessageReceived

public Message onPreMessageReceived(Peer peer,
                                    Message m)
Description copied from interface: PeerEventListener

Called when a message is received by a peer, before the message is processed. The returned message is processed instead. Returning null will cause the message to be ignored by the Peer returning the same message object allows you to see the messages received but not change them. The result from one event listeners callback is passed as "m" to the next, forming a chain.

Note that this will never be called if registered with any executor other than Threading.SAME_THREAD

Specified by:
onPreMessageReceived in interface PeerEventListener

onTransaction

public void onTransaction(Peer peer,
                          Transaction t)
Description copied from interface: PeerEventListener
Called when a new transaction is broadcast over the network.

Specified by:
onTransaction in interface PeerEventListener

getData

public List<Message> getData(Peer peer,
                             GetDataMessage m)
Description copied from interface: PeerEventListener

Called when a peer receives a getdata message, usually in response to an "inv" being broadcast. Return as many items as possible which appear in the GetDataMessage, or null if you're not interested in responding.

Note that this will never be called if registered with any executor other than Threading.SAME_THREAD

Specified by:
getData in interface PeerEventListener


Copyright © 2014. All rights reserved.