FileDocCategorySizeDatePackage
Peer.javaAPI DocExample2610Sat Sep 26 09:40:54 BST 1998jdc.patterns.peer

Peer

public abstract class Peer extends Object

Fields Summary
protected Hashtable
mPeers
Table of currently connected Peers.
protected Identity
mIdentity
The networked identity of this peer. Subclasses implementing this abstract class will need to provide a means for initializing this identity, such that the identity is unique in the distributed context.
Constructors Summary
public Peer()
Default constructor. Leave identity uninitialized, to indicate no identity.


               
    
Methods Summary
public voidaddPeer(jdc.patterns.peer.Peer p)
Add a peer to our list.

    mPeers.put(p.getIdentity(), p);
  
public booleanbroadcast(Message msg)
Broadcast the message to all currently connected peers.

    boolean success = true;
    Enumeration pEnum = getPeers();
    while (pEnum.hasMoreElements()) {
      Peer p = (Peer)pEnum.nextElement();
      if (!send(msg, p.getIdentity())) {
	success = false;
      }
    }
    return success;
  
public abstract booleanconnect(java.util.Properties connProps)
Connect to a peer given the connection properties. The requirements on these properties will depend on the implementation. A socket-based peer will need to have the host name and port on which the peer is listening. An RMI-based peer will need the host and registry name of the remote peer object. The peer will need to initialize the Identity of the remote based on data gleaned from the connection process.

public abstract booleanconnect(java.util.Properties connProps, Identity peerID)
Connect to a peer given the connection properties and identity of the peer. Subclasses can choose to implement this using both arguments, or ignoring one in favor of the other (connection properties vs. properties pulled from the remote peer identifier).

public IdentitygetIdentity()

    return mIdentity;
  
public jdc.patterns.peer.PeergetPeer(Identity i)
Get the peer identified by the given identity.

    return (Peer)mPeers.get(i);
  
public java.util.EnumerationgetPeers()
Get list of Peers

    return mPeers.elements();
  
public abstract voidhandle(Message m)
Handle an incoming message.

public abstract booleansend(Message msg, Identity peer)
Send the message to the identified peer.

public voidsetIdentity(Identity i)

    mIdentity = i;