p2p.simulator.protocol
Class Peer

java.lang.Object
  extended by p2p.simulator.protocol.Peer
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable

public abstract class Peer
extends java.lang.Object
implements java.lang.Runnable, java.lang.Cloneable

The class Peer should be implemented by all user defined protocols. This class defines the basic peer-to-peer operations and the basic management methods.


Constructor Summary
Peer()
           
 
Method Summary
 java.lang.Object clone()
          Creates and returns an instance of class peer.
abstract  void delete(long key)
          This method is called by the simulator in order the peer to perform a key deletion.
abstract  int getNumOfKeys()
          Returns the number of keys stored in the peer.
abstract  long getPeerId()
          Returns the peer's identifier.
abstract  int getPendingQueries()
          Returns the number of pending queries.
abstract  int getRTSize()
          Returns the size of the peer's routing table.
abstract  java.lang.Thread.State getState()
          Returns the peer's state regarding its thread state.
abstract  void init(long id, long N, long K, Network Net)
          Initializes a peer.
abstract  void insert(long key)
          This method is called by the simulator in order the peer to perform a key insertion.
abstract  boolean isOnline()
          Returns true if the peer is ready to service any request, false otherwise.
abstract  void joinPeer()
          This method is called by the simulator in order to connect the peer to the overlay.
abstract  void leavePeer()
          This method is called by the simulator in order to remove the peer from the overlay.
abstract  void lookup(long key)
          This method is called by the simulator in order the peer to perform a key lookup.
abstract  void registerLogger(java.util.logging.Logger logger)
          Attaches the simulator's logger.
abstract  void run()
          Overides the method run of the Runnable interface.
abstract  void setState(java.lang.Thread.State state)
          Sets the peer's state regarding its thread state.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Peer

public Peer()
Method Detail

init

public abstract void init(long id,
                          long N,
                          long K,
                          Network Net)
Initializes a peer.

Parameters:
id - The id of the peer.
N - The total number of overlay peers.
K - The key space of the overlay.
Net - A Network instance.

run

public abstract void run()
Overides the method run of the Runnable interface.

Specified by:
run in interface java.lang.Runnable

getPeerId

public abstract long getPeerId()
Returns the peer's identifier.

Returns:
The peer's id.

getNumOfKeys

public abstract int getNumOfKeys()
Returns the number of keys stored in the peer.

Returns:
The current number of keys.

isOnline

public abstract boolean isOnline()
Returns true if the peer is ready to service any request, false otherwise.

Returns:
True if the peer is ready, false otherwise.

setState

public abstract void setState(java.lang.Thread.State state)
Sets the peer's state regarding its thread state. The simulator before invoced the peer's run method, sets the state to RUNNABLE. The implementation of the peer's run method should set its state to TERMINATED before exit.

Parameters:
state - The peer's state.

getState

public abstract java.lang.Thread.State getState()
Returns the peer's state regarding its thread state.

Returns:
The peer's state.

joinPeer

public abstract void joinPeer()
This method is called by the simulator in order to connect the peer to the overlay.


leavePeer

public abstract void leavePeer()
This method is called by the simulator in order to remove the peer from the overlay.


lookup

public abstract void lookup(long key)
This method is called by the simulator in order the peer to perform a key lookup.

Parameters:
key - The key is being searched.

insert

public abstract void insert(long key)
This method is called by the simulator in order the peer to perform a key insertion.

Parameters:
key - The key is being inserted.

delete

public abstract void delete(long key)
This method is called by the simulator in order the peer to perform a key deletion.

Parameters:
key - The key is being deleted.

registerLogger

public abstract void registerLogger(java.util.logging.Logger logger)
Attaches the simulator's logger.

Parameters:
logger - The simulator's logger.

getRTSize

public abstract int getRTSize()
Returns the size of the peer's routing table.

Returns:
The size of the routing table.

getPendingQueries

public abstract int getPendingQueries()
Returns the number of pending queries.

Returns:

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns an instance of class peer.

Overrides:
clone in class java.lang.Object
Returns:
An instance of class Peer.
Throws:
java.lang.CloneNotSupportedException