JXTA

net.jxta.impl.rendezvous.adhoc
Class AdhocPeerRdvService

java.lang.Object
  extended by net.jxta.impl.rendezvous.RendezVousServiceProvider
      extended by net.jxta.impl.rendezvous.adhoc.AdhocPeerRdvService
All Implemented Interfaces:
EndpointListener

public class AdhocPeerRdvService
extends RendezVousServiceProvider

A JXTA RendezVousService implementation which implements the ad hoc portion of the standard JXTA Rendezvous Protocol (RVP).

See Also:
RendezVousService, JXTA Protocols Specification : Rendezvous Protocol

Field Summary
 
Fields inherited from class net.jxta.impl.rendezvous.RendezVousServiceProvider
closed, group, MAX_TTL, PROP_HDR_ELEMENT_NAME, PropPName, PropSName, RDV_MSG_NAMESPACE_NAME, rdvService, rendezvousMeter, rendezvousServiceMonitor
 
Constructor Summary
AdhocPeerRdvService(PeerGroup g, RendezVousServiceImpl rdvService)
          Constructor
 
Method Summary
 void challengeRendezVous(ID peer, long delay)
          Resets the local idea of the lease to the specified value.
 void connectToRendezVous(EndpointAddress addr, Object hint)
          Attempt to connect to the specified rendezvous peer.
 void disconnectFromRendezVous(ID peerId)
          Remove a RendezVousService point.
 Vector<ID> getConnectedPeerIDs()
          Returns the peers that are currently connected to this peer.
 boolean isConnectedToRendezVous()
          Return true if connected to a rendezvous.
 void propagate(Enumeration<? extends ID> destPeerIDs, Message msg, String serviceName, String serviceParam, int ttl)
          Propagates a message onto as many peers on the local network as possible.
 void propagate(Message msg, String serviceName, String serviceParam, int ttl)
          Propagates a message onto as many peers on the local network as possible.
 void propagateInGroup(Message msg, String serviceName, String serviceParam, int ttl)
          
 void propagateToNeighbors(Message msg, String serviceName, String serviceParam, int ttl)
          Propagates a message onto as many peers on the local network as possible.
protected  void repropagate(Message msg, RendezVousPropagateMessage propHdr, String serviceName, String serviceParam)
          Responsible for forwarding received messages to the rest of the network as appropriate.
protected  int startApp(String[] arg)
          Supply arguments and starts this service if it hadn't started by itself.
 void stopApp()
          Ask this service to stop.
 void walk(Message msg, String serviceName, String serviceParam, int ttl)
          Walk a message through the rendezvous peers of the network: only rendezvous peers will receive the message.
 void walk(Vector<? extends ID> destPeerIDs, Message msg, String serviceName, String serviceParam, int ttl)
          Walk a message through the rendezvous peers of the network: only rendezvous peers will receive the message.
 
Methods inherited from class net.jxta.impl.rendezvous.RendezVousServiceProvider
checkPropHeader, getPeerAdvertisementDoc, getPropHeader, mkAddress, mkAddress, processIncomingMessage, processReceivedMessage, sendToNetwork, setRendezvousServiceMonitor, updatePropHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdhocPeerRdvService

public AdhocPeerRdvService(PeerGroup g,
                           RendezVousServiceImpl rdvService)
Constructor

Parameters:
g - the peergroup
rdvService - the rendezvous service
Method Detail

startApp

protected int startApp(String[] arg)
Supply arguments and starts this service if it hadn't started by itself.

Currently this service starts by itself and does not expect arguments.

Overrides:
startApp in class RendezVousServiceProvider
Parameters:
arg - argument params
Returns:
0 if successful

stopApp

public void stopApp()
Ask this service to stop.

Overrides:
stopApp in class RendezVousServiceProvider

getConnectedPeerIDs

public Vector<ID> getConnectedPeerIDs()
Returns the peers that are currently connected to this peer.

Specified by:
getConnectedPeerIDs in class RendezVousServiceProvider
Returns:
The peers that are currently connected to this peer.

isConnectedToRendezVous

public boolean isConnectedToRendezVous()
Return true if connected to a rendezvous.

Specified by:
isConnectedToRendezVous in class RendezVousServiceProvider
Returns:
true if connected to a rendezvous, false otherwise

connectToRendezVous

public void connectToRendezVous(EndpointAddress addr,
                                Object hint)
                         throws IOException
Attempt to connect to the specified rendezvous peer.

Specified by:
connectToRendezVous in class RendezVousServiceProvider
Parameters:
addr - The endpoint address of the rendezvous peer.
hint - An optional hint which may be null.
Throws:
IOException - If no connection could be made to the specified peer.

challengeRendezVous

public void challengeRendezVous(ID peer,
                                long delay)
Resets the local idea of the lease to the specified value. As a result a lease response must be sought and obtained within the new specified delay or the rdv is considered disconnected.

Specified by:
challengeRendezVous in class RendezVousServiceProvider
Parameters:
peer - The peer to be challenged
delay - The delay

disconnectFromRendezVous

public void disconnectFromRendezVous(ID peerId)
Remove a RendezVousService point.

Specified by:
disconnectFromRendezVous in class RendezVousServiceProvider
Parameters:
peerId - the PeerId of the RendezVous to disconnect from.

propagate

public void propagate(Message msg,
                      String serviceName,
                      String serviceParam,
                      int ttl)
               throws IOException
Propagates a message onto as many peers on the local network as possible. Typically the message will go to all the peers to which at least one endpoint transport can address without using the router.

This method sends the message to all peers, rendezvous peers and edge peer. This method of propagation is very expensive and should not be frequently used. When rendezvous peers are used in order to cache index of data, it is more efficient to use the walk() method.

Only a single HOP at a time is performed. Messages are always delivered to the destination handler on arrival. This handler is responsible for repropagating further, if deemed appropriate.

Loop and TTL control are performed automatically.

Messages can be propagated via this method for the first time or can be re-propagated by re-using a message that came in via propagation. In the later case, the TTL and loop detection parameters CANNOT be re-initialized. If one wants to "re-propagate" a message with a new TTL and blank gateways list one must generate a completely new message. This limits the risk of accidental propagation storms, although they can always be engineered deliberately.

Note: The original msg is not modified and may be reused upon return.

Specified by:
propagate in class RendezVousServiceProvider
Parameters:
msg - is the message to propagate.
serviceName - is the name of the service
serviceParam - is the parameter of the service
ttl - is the maximum TTL of the message (note that the Rendezvous Service implementation is free to decrease that value.
Throws:
IOException - if an io error occurs

propagateInGroup

public void propagateInGroup(Message msg,
                             String serviceName,
                             String serviceParam,
                             int ttl)
                      throws IOException

Specified by:
propagateInGroup in class RendezVousServiceProvider
Throws:
IOException

propagate

public void propagate(Enumeration<? extends ID> destPeerIDs,
                      Message msg,
                      String serviceName,
                      String serviceParam,
                      int ttl)
Propagates a message onto as many peers on the local network as possible. Typically the message will go to all the peers to which at least one endpoint transport can address without using the router.

This method sends the message to all peers, rendezvous peers and edge peer. This method of propagation is very expensive and should not be frequently used. When rendezvous peers are used in order to cache index of data, it is more efficient to use the walk() method.

Only a single HOP at a time is performed. Messages are always delivered to the destination handler on arrival. This handler is responsible for repropagating further, if deemed appropriate.

Loop and TTL control are performed automatically.

Messages can be propagated via this method for the first time or can be re-propagated by re-using a message that came in via propagation. In the later case, the TTL and loop detection parameters CANNOT be re-initialized. If one wants to "re-propagate" a message with a new TTL and blank gateways list one must generate a completely new message. This limits the risk of accidental propagation storms, although they can always be engineered deliberately.

Note: The original msg is not modified and may be reused upon return.

Specified by:
propagate in class RendezVousServiceProvider
Parameters:
destPeerIDs - An enumeration of the peers that are recipients of the propagated message.
msg - is the message to propagate.
serviceName - is the name of the service
serviceParam - is the parameter of the service
ttl - is the maximum TTL of the message (note that the Rendezvous Service implementation is free to decrease that value.

propagateToNeighbors

public void propagateToNeighbors(Message msg,
                                 String serviceName,
                                 String serviceParam,
                                 int ttl)
                          throws IOException
Propagates a message onto as many peers on the local network as possible. Typically the message will go to all the peers to which at least one endpoint transport can address without using the router.

Only a single HOP at a time is performed. Messages are always delivered to the destination handler on arrival. This handler is responsible for repropagating further, if deemed appropriate.

Loop and TTL control are performed automatically.

Messages can be propagated via this method for the first time or can be re-propagated by re-using a message that came in via propagation. In the later case, the TTL and loop detection parameters CANNOT be re-initialized. If one wants to "re-propagate" a message with a new TTL and blank gateways list one must generate a completely new message. This limits the risk of accidental propagation storms, although they can always be engineered deliberately.

Note: The original msg is not modified and may be reused upon return.

Specified by:
propagateToNeighbors in class RendezVousServiceProvider
Parameters:
msg - is the message to propagate.
serviceName - is the name of the service
serviceParam - is the parameter of the service
ttl - is the maximum TTL of the message (note that the Rendezvous Service implementation is free to decrease that value.
Throws:
IOException - if an io error occurs

walk

public void walk(Message msg,
                 String serviceName,
                 String serviceParam,
                 int ttl)
          throws IOException
Walk a message through the rendezvous peers of the network: only rendezvous peers will receive the message.

Only a single HOP at a time is performed. Messages are always delivered to the destination handler on arrival. This handler is responsible for repropagating further, if deemed appropriate.

Loop and TTL control are performed automatically.

Messages can be propagated via this method for the first time or can be re-propagated by re-using a message that came in via propagation. In the later case, the TTL and loop detection parameters CANNOT be re-initialized. If one wants to "re-propagate" a message with a new TTL and blank gateways list one must generate a completely new message. This limits the risk of accidental propagation storms, although they can always be engineered deliberately.

Note: The original msg is not modified and may be reused upon return.

The definition of walk says that we should forward the message to the most appropriate peer. Since we don't make any effort keep track of other peers we don't have anywhere to send the message.

Specified by:
walk in class RendezVousServiceProvider
Parameters:
msg - is the message to walk.
serviceName - is the name of the service
serviceParam - is the parameter of the service
ttl - is the maximum TTL of the message (note that the Rendezvous Service implementation is free to decrease that value.
Throws:
IOException - when walking the message is impossible (network failure)

walk

public void walk(Vector<? extends ID> destPeerIDs,
                 Message msg,
                 String serviceName,
                 String serviceParam,
                 int ttl)
          throws IOException
Walk a message through the rendezvous peers of the network: only rendezvous peers will receive the message.

Only a single HOP at a time is performed. Messages are always delivered to the destination handler on arrival. This handler is responsible for repropagating further, if deemed appropriate.

Loop and TTL control are performed automatically.

Messages can be propagated via this method for the first time or can be re-propagated by re-using a message that came in via propagation. In the later case, the TTL and loop detection parameters CANNOT be re-initialized. If one wants to "re-propagate" a message with a new TTL and blank gateways list one must generate a completely new message. This limits the risk of accidental propagation storms, although they can always be engineered deliberately.

Note: The original msg is not modified and may be reused upon return.

Unlike the undirected walk we are told where to send the message so we deliver it as requested.

Specified by:
walk in class RendezVousServiceProvider
Parameters:
destPeerIDs - is a Vector of PeerID of the peers which are receiving first the walker. Note that each entry in the Vector will create its own walker.
msg - is the message to walk.
serviceName - is the name of the service
serviceParam - is the parameter of the service
ttl - is the maximum TTL of the message (note that the Rendezvous Service implementation is free to decrease that value.
Throws:
IOException - when walking the message is impossible (network failure)

repropagate

protected void repropagate(Message msg,
                           RendezVousPropagateMessage propHdr,
                           String serviceName,
                           String serviceParam)
Responsible for forwarding received messages to the rest of the network as appropriate. This generally only makes sense for multicast or broadcast scenarios.

Specified by:
repropagate in class RendezVousServiceProvider
Parameters:
msg - the message to be repropagated.
propHdr - It's current propagation header.
serviceName - The destination service.
serviceParam - The destination service parameter.

JXSE