Project JXTA

net.jxta.impl.cm
Class Srdi

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

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
           
 
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(Object peer, ResolverQueryMsg query)
          Forwards a Query to a specific peer hopCount is incremented to indicate this query is forwarded
 void forwardQuery(Vector peers, ResolverQueryMsg query)
          Forwards a Query to a list of peers hopCount is incremented to indicate this query is forwarded
 void forwardQuery(Vector 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 forwardSrdiMessage(PeerID peerid, PeerID srcPid, String primaryKey, String secondarykey, String value, long expiration)
          forward srdi message to another peer
 Vector 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  Vector randomResult(Vector result, int threshold)
          returns a random vector(threshold) from a given vector
 void rendezvousEvent(RendezvousEvent event)
          
 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
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(Object 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(Vector 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(Vector 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

randomResult

protected Vector randomResult(Vector result,
                              int threshold)
returns a random vector(threshold) from a given vector


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)

Specified by:
rendezvousEvent in interface RendezvousListener

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 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

JXTA J2SE