Project JXTA

net.jxta.impl.rendezvous.rpv
Class PeerView

java.lang.Object
  extended bynet.jxta.impl.rendezvous.rpv.PeerView
All Implemented Interfaces:
EndpointListener, EventListener, RendezvousListener

public final class PeerView
extends Object
implements EndpointListener, RendezvousListener

This class models a Rendezvous Peer View (RPV): ordered collection of all other Rendezvous Peers visible to this Peer.

Presently this class implements a random "diffusion" algorithm where each Peer periodically selects a randomly selected peer advertisement from its view and sends it over to a randomly selected peer from its view. Over time, this causes every peer to learn about every other peer, resulting in a "consistent" peer view.

This diffusion process is bootstrapped by every peer sending their own peer advertisements to some well-known, stable, "seed" peers on startup.


Field Summary
protected  AccessList acl
           
protected  File aclFile
           
protected  long aclFileLastModified
           
(package private) static MessageElement CACHED_RADV_ELEMENT
           
(package private) static String CACHED_RADV_ELEMENT_NAME
          Element name that specifies by its presence whether the enclosed RdvAdvertisement is a hint (cached), or is known to be active.
(package private) static MessageElement EDGE_ELEMENT
           
(package private) static String EDGE_ELEMENT_NAME
          Element name that specifies by its presence whether the sender is configured as an edge peer.
(package private) static MessageElement FAILURE_ELEMENT
           
(package private) static String FAILURE_ELEMENT_NAME
          Element name that specifies by its presence whether the enclosed RdvAdvertisement is about a failure.
(package private) static String MESSAGE_ELEMENT_NAME
          Element name of outgoing messages.
(package private) static String MESSAGE_NAMESPACE
          Namespace used for rdv message elements.
(package private) static String RESPONSE_ELEMENT_NAME
          Element name of responses.
(package private) static String SERVICE_NAME
          Our service name
(package private) static String SRCROUTEADV_ELEMENT_NAME
          (optional) Element name that specifies the route advertisement of the source of the message.
 
Constructor Summary
PeerView(PeerGroup group, PeerGroup advertisingGroup, RendezVousServiceImpl rdvService, String name)
          Get an instance of PeerView for the specified PeerGroup and Service.
 
Method Summary
 boolean addListener(PeerViewListener listener)
          Add a listener for PeerViewEvent
 void addSeed(URI seed)
          Adds the specified URI to the list of seeds.
protected  void addTask(TimerTask task, long delay, long interval)
           
 PeerViewElement getDownPeer()
          Get the down peer from the local peer.
 PeerViewElement getPeerViewElement(ID pid)
          Get from the local view, the PeerViewElement for the given PeerID, if one exists.
 PeerViewElement getPeerViewElement(PeerViewDestination wanted)
          Return from the local view, the PeerViewElement that is equal to the given PeerViewDestination, if one exists or null if it is not present.
 PeerViewElement getSelf()
          Get the local peer.
 PeerViewElement getUpPeer()
          Get the up peer from the local peer.
 SortedSet getView()
          Get a copy of the PeerView for this group.
(package private) static URI[] loadSeeds(URI seedingURI)
           
 void notifyFailure(PeerID pid, boolean propagate)
          Invoked by anyone in order to inform the PeerView of a failure of one of its rendezvous peer.
(package private)  void notifyFailure(PeerViewElement pve, boolean propagateFailure)
          Invoked by a PeerViewElement when a rendezvous peer becomes unreachable.
 boolean probeAddress(EndpointAddress address, Object hint)
          Probe the specified peer immediately.
 void processIncomingMessage(Message msg, EndpointAddress srcAddr, EndpointAddress dstAddr)
           Listener for "PeerView"/ and propagate pipes.
 boolean removeListener(PeerViewListener listener)
          Removes a PeerViewEvent Listener previously added with addListener.
protected  void removeTask(TimerTask task)
           
 void rendezvousEvent(RendezvousEvent event)
          
 void seed()
          Send our own advertisement to all of the seed rendezvous.
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVICE_NAME

static final String SERVICE_NAME
Our service name

See Also:
Constant Field Values

MESSAGE_NAMESPACE

static final String MESSAGE_NAMESPACE
Namespace used for rdv message elements.

See Also:
Constant Field Values

MESSAGE_ELEMENT_NAME

static final String MESSAGE_ELEMENT_NAME
Element name of outgoing messages.

See Also:
Constant Field Values

RESPONSE_ELEMENT_NAME

static final String RESPONSE_ELEMENT_NAME
Element name of responses.

See Also:
Constant Field Values

CACHED_RADV_ELEMENT_NAME

static final String CACHED_RADV_ELEMENT_NAME
Element name that specifies by its presence whether the enclosed RdvAdvertisement is a hint (cached), or is known to be active. In practice, when sending its own RdvAdvertisement,a peer does not set this element, but when sending another peer's RdvAdvertisement, this element is set.

See Also:
Constant Field Values

CACHED_RADV_ELEMENT

static final MessageElement CACHED_RADV_ELEMENT

SRCROUTEADV_ELEMENT_NAME

static final String SRCROUTEADV_ELEMENT_NAME
(optional) Element name that specifies the route advertisement of the source of the message.

See Also:
Constant Field Values

EDGE_ELEMENT_NAME

static final String EDGE_ELEMENT_NAME
Element name that specifies by its presence whether the sender is configured as an edge peer. Edge peers do not become part of any peer's view.

See Also:
Constant Field Values

EDGE_ELEMENT

static final MessageElement EDGE_ELEMENT

FAILURE_ELEMENT_NAME

static final String FAILURE_ELEMENT_NAME
Element name that specifies by its presence whether the enclosed RdvAdvertisement is about a failure.

See Also:
Constant Field Values

FAILURE_ELEMENT

static final MessageElement FAILURE_ELEMENT

acl

protected final AccessList acl

aclFile

protected File aclFile

aclFileLastModified

protected long aclFileLastModified
Constructor Detail

PeerView

public PeerView(PeerGroup group,
                PeerGroup advertisingGroup,
                RendezVousServiceImpl rdvService,
                String name)
Get an instance of PeerView for the specified PeerGroup and Service.

Parameters:
group - Peer Group in which this Peer View instance operates.
advertisingGroup - Peer Group in which this Peer View instance will advertise and broadcast its existance.
rdvService - The rdvService we are to use.
name - The identifying name for this Peer View instance.
Method Detail

processIncomingMessage

public void processIncomingMessage(Message msg,
                                   EndpointAddress srcAddr,
                                   EndpointAddress dstAddr)
Listener for "PeerView"/ and propagate pipes.

Specified by:
processIncomingMessage in interface EndpointListener

rendezvousEvent

public void rendezvousEvent(RendezvousEvent event)

Specified by:
rendezvousEvent in interface RendezvousListener

start

public void start()

stop

public void stop()

addTask

protected void addTask(TimerTask task,
                       long delay,
                       long interval)

removeTask

protected void removeTask(TimerTask task)

addSeed

public void addSeed(URI seed)
Adds the specified URI to the list of seeds. Even if useOnlySeeds is in effect, this seed may now be used, as if it was part of the initial configuration.

Parameters:
seed - the URI of the seed rendezvous.

probeAddress

public boolean probeAddress(EndpointAddress address,
                            Object hint)
Probe the specified peer immediately.

Note: If "useOnlySeeds" is in effect and the peer is not a seed, any response to this probe will be ignored.


seed

public void seed()
Send our own advertisement to all of the seed rendezvous.


notifyFailure

public void notifyFailure(PeerID pid,
                          boolean propagate)
Invoked by anyone in order to inform the PeerView of a failure of one of its rendezvous peer.


notifyFailure

void notifyFailure(PeerViewElement pve,
                   boolean propagateFailure)
Invoked by a PeerViewElement when a rendezvous peer becomes unreachable.


addListener

public boolean addListener(PeerViewListener listener)
Add a listener for PeerViewEvent

Parameters:
listener - An PeerViewListener to process the event.

removeListener

public boolean removeListener(PeerViewListener listener)
Removes a PeerViewEvent Listener previously added with addListener.

Parameters:
listener - the PeerViewListener listener remove
Returns:
whether successful or not

getView

public SortedSet getView()
Get a copy of the PeerView for this group.

Returns:
A SortedSet which is the current local view of the peerview

getPeerViewElement

public PeerViewElement getPeerViewElement(PeerViewDestination wanted)
Return from the local view, the PeerViewElement that is equal to the given PeerViewDestination, if one exists or null if it is not present. Identity is defined by PeerViewDestination#equals() which only looks at the destination address. Thus a PeerViewDestination is enough. A full PeerViewElement may be passed as well. This method does not require external synchronization.

Parameters:
wanted - PeerViewDestination matching the desired one.
Returns:
the matching PeerViewElement or null if it could not be found.

getPeerViewElement

public PeerViewElement getPeerViewElement(ID pid)
Get from the local view, the PeerViewElement for the given PeerID, if one exists. Null otherwise. This method does not require external synchronization.

Parameters:
pid - the PeerID of the desired element.
Returns:
the matching PeerViewElement null if it could not be found.

getDownPeer

public PeerViewElement getDownPeer()
Get the down peer from the local peer.

Returns:
the down PeerViewElement or null if there is no such peer.

getSelf

public PeerViewElement getSelf()
Get the local peer.

Returns:
the local PeerViewElement

getUpPeer

public PeerViewElement getUpPeer()
Get the up peer from the local peer.

Returns:
the up PeerViewElement or null if there is no such peer.

loadSeeds

static URI[] loadSeeds(URI seedingURI)
                throws IOException
Throws:
IOException

JXTA J2SE