JXTA

net.jxta.impl.cm
Class Srdi

java.lang.Object
  extended by net.jxta.impl.cm.Srdi
All Implemented Interfaces:
Runnable, EventListener, RendezvousListener

public class Srdi
extends Object
implements Runnable, RendezvousListener

Srdi is a service which provides SRDI functionalities such as :

If Srdi is started as a thread it performs periodic SRDI pushes of indices and also has the ability to respond to rendezvous events.

ResolverSrdiMessages define a ttl, to indicate to the receiving service whether to replicate such message or not.

In addition A ResolverQuery defines a hopCount to indicate how many hops a query has been forwarded. This element could be used to detect/stop a query forward loopback hopCount is checked to make ensure a query is not forwarded more than twice.

See Also:
JXTA Protocols Specification : Peer Resolver Protocol

Nested Class Summary
static interface Srdi.SrdiInterface
          Interface for pushing entries.
 
Field Summary
static int RPV_REPLICATION_THRESHOLD
          Replication threshold (minimum number of rdv's in peer view before replication)
 
Constructor Summary
Srdi(PeerGroup group, String handlername, Srdi.SrdiInterface srdiService, SrdiIndex srdiIndex, long connectPollInterval, long pushInterval)
          Starts the Srdi Service. wait for connectPollInterval prior to pushing the index if connected to a rdv, otherwise index is as soon as the Rendezvous connect occurs
 
Method Summary
 void forwardQuery(List<PeerID> peers, ResolverQueryMsg query)
          Forwards a Query to a list of peers hopCount is incremented to indicate this query is forwarded
 void forwardQuery(List<PeerID> peers, ResolverQueryMsg query, int threshold)
          Forwards a Query to a list of peers if the list of peers exceeds threshold, and random threshold is picked from peers hopCount is incremented to indicate this query is forwarded
 void forwardQuery(PeerID peer, ResolverQueryMsg query)
          Forwards a Query to a specific peer hopCount is incremented to indicate this query is forwarded
 void forwardSrdiMessage(PeerID peerid, PeerID srcPid, String primaryKey, String secondarykey, String value, long expiration)
          forward srdi message to another peer
 Vector<PeerID> getGlobalPeerView()
          get the global peerview as the rendezvous service only returns the peerview without the local RDV peer.
 PeerID getReplicaPeer(String expression)
          Given an expression return a peer from the list peers in the peerview this function is used to to give a replication point, and entry point to query on a pipe
 void pushSrdi(ID peer, SrdiMessage srdi)
          Push an SRDI message to a peer ttl is 1, and therefore services receiving this message could choose to replicate this message
protected  List<PeerID> randomResult(List<PeerID> result, int threshold)
          returns a random List(threshold) from a given list
 void rendezvousEvent(RendezvousEvent event)
          Called when an event occurs for the Rendezvous service
 void replicateEntries(SrdiMessage srdiMsg)
          Replicates a SRDI message to other rendezvous' entries are replicated by breaking out entries out of the message and sorted out into rdv distribution bins. after which smaller messages are sent to other rdv's
 void run()
          

Main processing method for the SRDI Worker thread Send all entries, wait for pushInterval, then send deltas

 void stop()
          stop the current running thread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RPV_REPLICATION_THRESHOLD

public static final int RPV_REPLICATION_THRESHOLD
Replication threshold (minimum number of rdv's in peer view before replication)

See Also:
Constant Field Values
Constructor Detail

Srdi

public Srdi(PeerGroup group,
            String handlername,
            Srdi.SrdiInterface srdiService,
            SrdiIndex srdiIndex,
            long connectPollInterval,
            long pushInterval)
Starts the Srdi Service. wait for connectPollInterval prior to pushing the index if connected to a rdv, otherwise index is as soon as the Rendezvous connect occurs

Parameters:
group - group context to operate in
handlername - the SRDI handlername
srdiService - the service utilizing this Srdi, for purposes of callback push entries on events such as rdv connect/disconnect, etc.
srdiIndex - The index instance associated with this service
connectPollInterval - initial timeout before the very first push of entries in milliseconds
pushInterval - the Interval at which the deltas are pushed in milliseconds
Method Detail

stop

public void stop()
stop the current running thread


replicateEntries

public void replicateEntries(SrdiMessage srdiMsg)
Replicates a SRDI message to other rendezvous' entries are replicated by breaking out entries out of the message and sorted out into rdv distribution bins. after which smaller messages are sent to other rdv's

Parameters:
srdiMsg - srdi message to replicate

pushSrdi

public void pushSrdi(ID peer,
                     SrdiMessage srdi)
Push an SRDI message to a peer ttl is 1, and therefore services receiving this message could choose to replicate this message

Parameters:
peer - peer to push message to, if peer is null it is the message is propagated
srdi - SRDI message to send

forwardQuery

public void forwardQuery(PeerID peer,
                         ResolverQueryMsg query)
Forwards a Query to a specific peer hopCount is incremented to indicate this query is forwarded

Parameters:
peer - peerid to forward query to
query - The query

forwardQuery

public void forwardQuery(List<PeerID> peers,
                         ResolverQueryMsg query)
Forwards a Query to a list of peers hopCount is incremented to indicate this query is forwarded

Parameters:
peers - The peerids to forward query to
query - The query

forwardQuery

public void forwardQuery(List<PeerID> peers,
                         ResolverQueryMsg query,
                         int threshold)
Forwards a Query to a list of peers if the list of peers exceeds threshold, and random threshold is picked from peers hopCount is incremented to indicate this query is forwarded

Parameters:
peers - The peerids to forward query to
query - The query
threshold - number of peers to forward the query to

randomResult

protected List<PeerID> randomResult(List<PeerID> result,
                                    int threshold)
returns a random List(threshold) from a given list

Parameters:
result - starting set
threshold - sub-set desired
Returns:
sub-list of result

getReplicaPeer

public PeerID getReplicaPeer(String expression)
Given an expression return a peer from the list peers in the peerview this function is used to to give a replication point, and entry point to query on a pipe

Parameters:
expression - expression to derive the mapping from
Returns:
The replicaPeer value

forwardSrdiMessage

public void forwardSrdiMessage(PeerID peerid,
                               PeerID srcPid,
                               String primaryKey,
                               String secondarykey,
                               String value,
                               long expiration)
forward srdi message to another peer

Parameters:
peerid - PeerID to forward query to
srcPid - The source originator
primaryKey - primary key
secondarykey - secondary key
value - value of the entry
expiration - expiration in ms

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

run

public void run()

Main processing method for the SRDI Worker thread Send all entries, wait for pushInterval, then send deltas

Specified by:
run in interface Runnable

getGlobalPeerView

public Vector<PeerID> getGlobalPeerView()
get the global peerview as the rendezvous service only returns the peerview without the local RDV peer. We need this consistent view for the SRDI index if not each RDV will have a different peerview, off setting the index even when the peerview is stable

Returns:
the sorted list

JXSE