sg.edu.nus.peer.management
Class PeerMaintainer

java.lang.Object
  extended by sg.edu.nus.peer.management.PeerMaintainer

public class PeerMaintainer
extends java.lang.Object

The PeerMaintainer is a singleton class. Its responsiblity is to maintain a list of all online peers for the purpose of monitoring the dynamic behavior of every online peer.

The original OnlinePeerManager is replaced by this class for the reason of efficiency.

Version:
1.0 2006-10-10
Author:
Xu Linhao

Method Summary
 boolean containsKey(PeerInfo info)
          Returns true if the key of a given PeerInfo can be found.
 boolean containsKey(java.lang.String key)
          Returns true if a given search key can be found.
 boolean containsValue(PeerInfo info)
          Returns true if a given PeerInfo instance can be found.
 PeerInfo getClient(java.lang.String key)
          Returns a PeerInfo instance whose type is client peer and key is equal to the search key.
 PeerInfo[] getClients()
          Returns a collection view of the value stored in the map that is responsible for keeping the information of all client peers.
static PeerMaintainer getInstance()
          Returns the reference of the PeerMaintainer.
 PeerInfo getServer(java.lang.String key)
          Returns a PeerInfo instance whose type is super peer and key is equal to the search key.
 PeerInfo[] getServers()
          Returns a collection view of the value stored in the map that is responsible for keeping the information of all super peers.
 boolean hasClient()
          Returns true if the map used for keeping client peers is not empty.
 boolean hasServer()
          Returns true if the map used for keeping server peers is not empty.
 void put(PeerInfo info)
          Puts a PeerInfo instance into the corresponding map.
 void put(java.lang.String key, PeerInfo info)
          Puts a PeerInfo instance into the corresponding map with specified key.
 PeerInfo remove(PeerInfo info)
          Removes a PeerInfo instance from the map.
 void removeAll()
          Removes all elements in the map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static PeerMaintainer getInstance()
Returns the reference of the PeerMaintainer.

Returns:
the reference of the PeerMaintainer

containsKey

public boolean containsKey(java.lang.String key)
Returns true if a given search key can be found.

Parameters:
key - the search key
Returns:
true if a given search key can be found; otherwise, return false

containsKey

public boolean containsKey(PeerInfo info)
Returns true if the key of a given PeerInfo can be found.

Parameters:
info - a PeerInfo instance
Returns:
true if the key of a given PeerInfo can be found; otherwise, return false

containsValue

public boolean containsValue(PeerInfo info)
Returns true if a given PeerInfo instance can be found.

Parameters:
info - a PeerInfo instance
Returns:
true if a given PeerInfo instance can be found; otherwise, return false

put

public void put(PeerInfo info)
Puts a PeerInfo instance into the corresponding map.

Parameters:
info - a PeerInfo instance

put

public void put(java.lang.String key,
                PeerInfo info)
Puts a PeerInfo instance into the corresponding map with specified key.

Parameters:
key - the key to identify the PeerInfo instance
info - the PeerInfo instance

getClient

public PeerInfo getClient(java.lang.String key)
Returns a PeerInfo instance whose type is client peer and key is equal to the search key.

Parameters:
key - the search key
Returns:
a PeerInfo instance whose key is equal to the search key; null if cannot find the key

getClients

public PeerInfo[] getClients()
Returns a collection view of the value stored in the map that is responsible for keeping the information of all client peers.

Returns:
a PeerInfo array whose values are the view of the map that stores the information of all client peers

getServer

public PeerInfo getServer(java.lang.String key)
Returns a PeerInfo instance whose type is super peer and key is equal to the search key.

Parameters:
key - the search key
Returns:
a PeerInfo instance whose key is equal to the search key; null if cannot find the key

getServers

public PeerInfo[] getServers()
Returns a collection view of the value stored in the map that is responsible for keeping the information of all super peers.

Returns:
a PeerInfo array whose values are the view of the map that stores the information of all super peers

hasClient

public boolean hasClient()
Returns true if the map used for keeping client peers is not empty.

Returns:
true if the map used for keeping client peers is not empty; otherwise, return false

hasServer

public boolean hasServer()
Returns true if the map used for keeping server peers is not empty.

Returns:
true if the map used for keeping server peers is not empty; otherwise, return false

remove

public PeerInfo remove(PeerInfo info)
Removes a PeerInfo instance from the map.

Parameters:
info - the PeerInfo instance

removeAll

public void removeAll()
Removes all elements in the map.