JXTA

net.jxta.impl.rendezvous
Class StdRendezVousService

java.lang.Object
  extended by net.jxta.impl.rendezvous.RendezVousServiceProvider
      extended by net.jxta.impl.rendezvous.StdRendezVousService
All Implemented Interfaces:
EndpointListener
Direct Known Subclasses:
EdgePeerRdvService, RdvPeerRdvService

public abstract class StdRendezVousService
extends RendezVousServiceProvider

Base class for providers which implement the JXTA Standard Rendezvous Protocol.

See Also:
JXTA Protocols Specification : Rendezvous Protocol

Nested Class Summary
protected static interface StdRendezVousService.StdRdvProtocolListener
          Interface for listeners to : <assignedID>/
 
Field Summary
static String ConnectedLeaseReply
           
static String ConnectedPeerReply
           
static String ConnectedRdvAdvReply
           
static String ConnectRequest
           
protected static int DEFAULT_MAX_TTL
          Default Maximum TTL.
static String DisconnectRequest
           
protected  String pName
           
protected  String pParam
           
protected  Timer timer
           
 
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
protected StdRendezVousService(PeerGroup group, RendezVousServiceImpl rdvService)
          Constructor
 
Method Summary
abstract  PeerConnection getPeerConnection(ID id)
          Returns the peer connection or null if not present.
protected abstract  PeerConnection[] getPeerConnections()
          Returns an array of the current peer connections.
 void processReceivedMessage(Message message, RendezVousPropagateMessage propHdr, EndpointAddress srcAddr, EndpointAddress dstAddr)
          Process a propagated message.
 void propagate(Enumeration<? extends ID> destPeerIDs, Message msg, String serviceName, String serviceParam, int initialTTL)
          Propagates a message onto as many peers on the local network as possible.
 void propagateToNeighbors(Message msg, String serviceName, String serviceParam, int initialTTL)
          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  void sendDisconnect(ID peerid, PeerAdvertisement padv)
          Sends a disconnect message to the specified peer.
protected  void sendDisconnect(PeerConnection pConn)
          Sends a disconnect message to the specified peer.
protected  int sendToEachConnection(Message msg, RendezVousPropagateMessage propHdr)
          Sends to all connected peers.
protected  int startApp(String[] argv, StdRendezVousService.StdRdvProtocolListener handler)
          
 void stopApp()
          Ask this service to stop.
 
Methods inherited from class net.jxta.impl.rendezvous.RendezVousServiceProvider
challengeRendezVous, checkPropHeader, connectToRendezVous, disconnectFromRendezVous, getConnectedPeerIDs, getPeerAdvertisementDoc, getPropHeader, isConnectedToRendezVous, mkAddress, mkAddress, processIncomingMessage, propagate, propagateInGroup, sendToNetwork, setRendezvousServiceMonitor, startApp, updatePropHeader, walk, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ConnectRequest

public static final String ConnectRequest
See Also:
Constant Field Values

DisconnectRequest

public static final String DisconnectRequest
See Also:
Constant Field Values

ConnectedPeerReply

public static final String ConnectedPeerReply
See Also:
Constant Field Values

ConnectedLeaseReply

public static final String ConnectedLeaseReply
See Also:
Constant Field Values

ConnectedRdvAdvReply

public static final String ConnectedRdvAdvReply
See Also:
Constant Field Values

DEFAULT_MAX_TTL

protected static final int DEFAULT_MAX_TTL
Default Maximum TTL.

See Also:
Constant Field Values

pName

protected final String pName

pParam

protected final String pParam

timer

protected final Timer timer
Constructor Detail

StdRendezVousService

protected StdRendezVousService(PeerGroup group,
                               RendezVousServiceImpl rdvService)
Constructor

Parameters:
group - the PeerGroup
rdvService - the parent rendezvous service
Method Detail

startApp

protected int startApp(String[] argv,
                       StdRendezVousService.StdRdvProtocolListener handler)


stopApp

public void stopApp()
Ask this service to stop.

Overrides:
stopApp in class RendezVousServiceProvider

processReceivedMessage

public void processReceivedMessage(Message message,
                                   RendezVousPropagateMessage propHdr,
                                   EndpointAddress srcAddr,
                                   EndpointAddress dstAddr)
Process a propagated message.

Overrides:
processReceivedMessage in class RendezVousServiceProvider
Parameters:
message - the message received
propHdr - the message header
srcAddr - the source address
dstAddr - the message destination addreess

propagate

public void propagate(Enumeration<? extends ID> destPeerIDs,
                      Message msg,
                      String serviceName,
                      String serviceParam,
                      int initialTTL)
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
initialTTL - 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 initialTTL)
                          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
initialTTL - 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

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.

getPeerConnection

public abstract PeerConnection getPeerConnection(ID id)
Returns the peer connection or null if not present.

Parameters:
id - the node ID
Returns:
PeerConnection the peer connection or null if not present.

getPeerConnections

protected abstract PeerConnection[] getPeerConnections()
Returns an array of the current peer connections.

Returns:
An array of the current peer connections.

sendToEachConnection

protected int sendToEachConnection(Message msg,
                                   RendezVousPropagateMessage propHdr)
Sends to all connected peers.

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

Parameters:
msg - The message to be sent.
propHdr - The propagation header associated with the message.
Returns:
the number of nodes the message was sent to

sendDisconnect

protected void sendDisconnect(ID peerid,
                              PeerAdvertisement padv)
Sends a disconnect message to the specified peer.

Parameters:
peerid - The peer to be disconnected.
padv - The peer to be disconnected.

sendDisconnect

protected void sendDisconnect(PeerConnection pConn)
Sends a disconnect message to the specified peer.

Parameters:
pConn - The peer to be disconnected.

JXSE