P-Grid v2.0a2 API Specification

p2p.basic
Interface P2P


public interface P2P

Defines the operations the peer-to-peer layer supports. These include initialization and shutdown requests as well as several ways to use the distributed indexing structure to locate peers and message them.


Method Summary
 void addP2PListener(P2PListener listener)
          Register an object to be notified of new messages.
 Peer getLocalPeer()
          Get information on the local peer.
 Peer[] getNeighbors()
          Get information on the neighbors known to this peer.
 void init(Properties properties)
          Initializes the P2P facility with the given properties.
 boolean isLocalPeerResponsible(Key key)
          Checks if the local peer is responsible for the given key.
 void join(Peer peer)
          Initialize the local routing table after connecting to network.
 void leave()
          Prepare for shutdown by announcing departure from network.
 Peer lookup(Key key, long timeout)
          Get information on a peer.
 void removeP2PListener(P2PListener listener)
          Remove registration of a current listener of new messages.
 void route(Key[] keys, Message[] message)
          Send a message to peers based on several keys.
 void route(Key key, Message message)
          Send a message to a peer.
 void route(KeyRange range, Message message)
          Send a message to a set of peers responsible for a range of keys.
 void routeToReplicas(Message message)
          Send a message to peers responsible for the same part of the keyspace as the local node.
 void send(Peer peer, Message message)
          Send a message directly to a peer (no routing is done)
 void shutdown()
          Shutdown the P2P.
 

Method Detail

addP2PListener

void addP2PListener(P2PListener listener)
Register an object to be notified of new messages.

Parameters:
listener - the P2PListener implementation to register

getLocalPeer

Peer getLocalPeer()
Get information on the local peer.

Returns:
the local peer

getNeighbors

Peer[] getNeighbors()
Get information on the neighbors known to this peer.

Returns:
an array of neighboring peers

init

void init(Properties properties)
Initializes the P2P facility with the given properties.

Parameters:
properties - further initialization properties.

isLocalPeerResponsible

boolean isLocalPeerResponsible(Key key)
Checks if the local peer is responsible for the given key.

Parameters:
key - the key to check.
Returns:
true if the local peer is responsible, false otherwise.

join

void join(Peer peer)
Initialize the local routing table after connecting to network.

Parameters:
peer - a bootstrap peer to contact

leave

void leave()
Prepare for shutdown by announcing departure from network.


shutdown

void shutdown()
Shutdown the P2P.


lookup

Peer lookup(Key key,
            long timeout)
Get information on a peer.

Parameters:
key - a key that the distant peer is responsible for
timeout - for the reply to arrive
Returns:
a Peer instance

removeP2PListener

void removeP2PListener(P2PListener listener)
Remove registration of a current listener of new messages.

Parameters:
listener - the P2PListener implementation to unregister

route

void route(Key key,
           Message message)
Send a message to a peer. Peer-to-peer layer is responsible for routing the message across as many peers as necessary. Message delivry is subject to the existance of a path between the origin and the destination. Confirmation receipt is not provided.

Parameters:
key - a key that the distant peer is reponsible for
message - the message to send

route

void route(Key[] keys,
           Message[] message)
Send a message to peers based on several keys. In some cases only one peer will be the destination if all keys are under its responsiblity.

Parameters:
keys - an array of destination keys
message - the message to send

route

void route(KeyRange range,
           Message message)
Send a message to a set of peers responsible for a range of keys.

Parameters:
range - the range of keys
message - the message to send

routeToReplicas

void routeToReplicas(Message message)
Send a message to peers responsible for the same part of the keyspace as the local node. This operation might not be supported by all implementations.

Parameters:
message - the message to send

send

void send(Peer peer,
          Message message)
Send a message directly to a peer (no routing is done)

Parameters:
peer - the peer
message - the message to send

P-Grid v2.0a2 API Specification

This is open source software distributed under the terms of the GNU General Public License, a copy of which is included in the file LICENSE. If not you can find the GPL at http://www.gnu.org/copyleft/gpl.txt