JXTA

net.jxta.impl.cm
Class SrdiIndex

java.lang.Object
  extended by net.jxta.impl.cm.SrdiIndex
All Implemented Interfaces:
Runnable

public class SrdiIndex
extends Object
implements Runnable

SrdiIndex


Nested Class Summary
static class SrdiIndex.Entry
          An entry in the index tables.
static class SrdiIndex.SrdiIndexRecord
          an SrdiIndexRecord wrapper
 
Constructor Summary
SrdiIndex(PeerGroup group, String indexName)
          Constructor for the SrdiIndex
SrdiIndex(PeerGroup group, String indexName, long interval)
          Construct a SrdiIndex and starts a GC thread which runs every "interval" milliseconds
 
Method Summary
 void add(String primaryKey, String attribute, String value, PeerID pid, long expiration)
          add an index entry
 void clear()
          Empties the index completely.
static void clearSrdi(PeerGroup group)
          Flushes the Srdi directory for a specified group this method should only be called before initialization of a given group calling this method on a running group would have undefined results
 void garbageCollect()
          Garbage Collect expired entries
 String getIndexName()
          Returns the name of this srdi index.
 List<SrdiIndex.Entry> getRecord(String pkey, String skey, String value)
          retrieves a record
 List<PeerID> query(String primaryKey)
          Query SrdiIndex
 List<PeerID> query(String primaryKey, String attribute, String value, int threshold)
          Query SrdiIndex
static SrdiIndex.SrdiIndexRecord readRecord(Record record)
          Reads the content of a record into List
 void remove(PeerID pid)
          remove entries pointing to peer id from cache
 void run()
          

Periodic thread for GC

protected  void startGC(PeerGroup group, String indexName, long interval)
          Start the GC thread
 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
 

Constructor Detail

SrdiIndex

public SrdiIndex(PeerGroup group,
                 String indexName)
Constructor for the SrdiIndex

Parameters:
group - group
indexName - the index name

SrdiIndex

public SrdiIndex(PeerGroup group,
                 String indexName,
                 long interval)
Construct a SrdiIndex and starts a GC thread which runs every "interval" milliseconds

Parameters:
interval - the interval at which the gc will run in milliseconds
group - group context
indexName - SrdiIndex name
Method Detail

startGC

protected void startGC(PeerGroup group,
                       String indexName,
                       long interval)
Start the GC thread

Parameters:
group - the PeerGroup
indexName - index name
interval - interval in milliseconds

getIndexName

public String getIndexName()
Returns the name of this srdi index.

Returns:
index name.

add

public void add(String primaryKey,
                String attribute,
                String value,
                PeerID pid,
                long expiration)
add an index entry

Parameters:
primaryKey - primary key
attribute - Attribute String to query on
value - value of the attribute string
expiration - expiration associated with this entry relative time in milliseconds
pid - peerid reference

getRecord

public List<SrdiIndex.Entry> getRecord(String pkey,
                                       String skey,
                                       String value)
retrieves a record

Parameters:
pkey - primary key
skey - secondary key
value - value
Returns:
List of Entry objects

remove

public void remove(PeerID pid)
remove entries pointing to peer id from cache

Parameters:
pid - peer id to remove

query

public List<PeerID> query(String primaryKey,
                          String attribute,
                          String value,
                          int threshold)
Query SrdiIndex

Parameters:
attribute - Attribute String to query on
value - value of the attribute string
primaryKey - primary key
threshold - max number of results
Returns:
an enumeration of canonical paths

query

public List<PeerID> query(String primaryKey)
Query SrdiIndex

Parameters:
primaryKey - primary key
Returns:
A list of Peer IDs.

readRecord

public static SrdiIndex.SrdiIndexRecord readRecord(Record record)
Reads the content of a record into List

Parameters:
record - Btree Record
Returns:
List of entries

clear

public void clear()
Empties the index completely. The entries are abandoned to the GC.


garbageCollect

public void garbageCollect()
Garbage Collect expired entries


stop

public void stop()
stop the current running thread


run

public void run()

Periodic thread for GC

Specified by:
run in interface Runnable

clearSrdi

public static void clearSrdi(PeerGroup group)
Flushes the Srdi directory for a specified group this method should only be called before initialization of a given group calling this method on a running group would have undefined results

Parameters:
group - group context

JXSE