JXTA

net.jxta.impl.rendezvous.rpv
Class PeerView

java.lang.Object
  extended by net.jxta.impl.rendezvous.rpv.PeerView
All Implemented Interfaces:
EventListener, EndpointListener, 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 "converged" 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
(package private) static MessageElement CACHED_RADV_ELEMENT
          Optional message element that specifies by its presence in a peerview message that the referenced peer is not the provider of the RdvAdvertisement and the advertisement is a "hint" or referral from the responding peer.
(package private) static String CACHED_RADV_ELEMENT_NAME
          Message element name for PeerView "Cached" Message Element
(package private) static MessageElement EDGE_ELEMENT
          Optional message element that specifies by its presence in a peerview message that the referenced peer is an edge peer and not a member of the peerview.
(package private) static String EDGE_ELEMENT_NAME
          Message element name for PeerView "Edge" Message Element
(package private) static MessageElement FAILURE_ELEMENT
          Optional message element that specifies by its presence in a peerview message that the referenced peer has either failed or is quitting.
(package private) static String FAILURE_ELEMENT_NAME
          Message element name for PeerView "Failure" Message Element
(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
          Message 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)
           
(package private) static RdvAdvertisement createRdvAdvertisement(PeerAdvertisement padv, String serviceName)
           
 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<PeerViewElement> getView()
          Get a copy of the PeerView for this group.
(package private) static PipeAdvertisement makeWirePipeAdvertisement(PeerGroup destGroup, PeerGroup group, String name)
           
 void notifyFailure(PeerID pid, boolean propagateFailure)
          Invoked by anyone in order to inform the PeerView of a failure of one of the member peers.
(package private)  void notifyFailure(PeerViewElement pve, boolean propagateFailure)
          Invoked when a peerview member peer becomes unreachable.
 boolean probeAddress(EndpointAddress address, RouteAdvertisement hint)
          Probe the specified peer immediately.
 void processIncomingMessage(Message msg, EndpointAddress srcAddr, EndpointAddress dstAddr)
          This method is invoked by the EndpointService for each incoming message which is addressed to this listener.
 boolean removeListener(PeerViewListener listener)
          Removes a PeerViewEvent Listener previously added with addListener.
protected  void removeTask(TimerTask task)
           
 void rendezvousEvent(RendezvousEvent event)
          Called when an event occurs for the Rendezvous service
 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. Note that the element contains a RdvAvertisement and not a Peer Advertisement.

See Also:
Constant Field Values

RESPONSE_ELEMENT_NAME

static final String RESPONSE_ELEMENT_NAME
Element name of responses. Note that the element contains a RdvAvertisement and not a Peer Advertisement.

See Also:
Constant Field Values

CACHED_RADV_ELEMENT_NAME

static final String CACHED_RADV_ELEMENT_NAME
Message element name for PeerView "Cached" Message Element

See Also:
Constant Field Values

CACHED_RADV_ELEMENT

static final MessageElement CACHED_RADV_ELEMENT
Optional message element that specifies by its presence in a peerview message that the referenced peer is not the provider of the RdvAdvertisement and the advertisement is a "hint" or referral from the responding peer.

In practice, when sending its own RdvAdvertisement, a peer does not include this element, but when sending another peer's RdvAdvertisement, this element is included.


SRCROUTEADV_ELEMENT_NAME

static final String SRCROUTEADV_ELEMENT_NAME
Message 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
Message element name for PeerView "Edge" Message Element

See Also:
Constant Field Values

EDGE_ELEMENT

static final MessageElement EDGE_ELEMENT
Optional message element that specifies by its presence in a peerview message that the referenced peer is an edge peer and not a member of the peerview.


FAILURE_ELEMENT_NAME

static final String FAILURE_ELEMENT_NAME
Message element name for PeerView "Failure" Message Element

See Also:
Constant Field Values

FAILURE_ELEMENT

static final MessageElement FAILURE_ELEMENT
Optional message element that specifies by its presence in a peerview message that the referenced peer has either failed or is quitting. If the "cached" element is also set then the error is being reported by a third party.

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 existence.
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)
This method is invoked by the EndpointService for each incoming message which is addressed to this listener.

Listener for "PeerView"/<peergroup-unique-id> and propagate pipes.

Specified by:
processIncomingMessage in interface EndpointListener
Parameters:
msg - Incoming message
srcAddr - Endpoint Address of the source of the message.
dstAddr - Endpoint Address of the destination of the message.

rendezvousEvent

public void rendezvousEvent(RendezvousEvent event)
Called when an event occurs for the Rendezvous service

Specified by:
rendezvousEvent in interface RendezvousListener
Parameters:
event - the rendezvous event

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,
                            RouteAdvertisement 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 propagateFailure)
Invoked by anyone in order to inform the PeerView of a failure of one of the member peers.

Parameters:
pid - ID of the peer which failed.
propagateFailure - If truethen broadcast the failure to other peers otherwise only update the local peerview.

notifyFailure

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

Parameters:
pve - The peer which failed.
propagateFailure - If true then broadcast the failure to other peers otherwise only update the local peerview.

createRdvAdvertisement

static RdvAdvertisement createRdvAdvertisement(PeerAdvertisement padv,
                                               String serviceName)

addListener

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

Parameters:
listener - An PeerViewListener to process the event.
Returns:
true if successful

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

makeWirePipeAdvertisement

static PipeAdvertisement makeWirePipeAdvertisement(PeerGroup destGroup,
                                                   PeerGroup group,
                                                   String name)

getView

public SortedSet<PeerViewElement> 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(java.lang.Object) 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.

JXSE