Project JXTA

net.jxta.impl.cm
Class SrdiCache

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

public class SrdiCache
extends Object
implements Runnable

Description of the Class


Nested Class Summary
(package private)  class SrdiCache.SrdiEntry
          Description of the Class
 
Constructor Summary
SrdiCache(long maxSize)
          Constructor for the SrdiCache object
SrdiCache(long maxSize, long interval)
          Construct a srdiObject and starts a GC thread which runs every "interval" milliseconds
 
Method Summary
 void add(String primaryKey, String attribute, String value, Object path, long expiration, boolean sticky)
          add a cache entry
 void clear()
          Empties the cache completely.
 boolean containsKey(String primaryKey, String secondaryKey)
          Determines whether this object is caching a particular key
 void garbageCollect()
           
 Enumeration getEntries(String primaryKey, String secondaryKey)
          return all entries of primary, and secondary keys
 long getMaxSize()
          returns the maxSize of the SrdiCache object
 Enumeration getPrimaryKeys()
          return all primary keys
 Enumeration getSecondaryKeys(String primaryKey)
          return all primary keys
 long getSize()
          Gets the size attribute of the SrdiCache object
 void purge(int fraction)
          Purges some of the cache.
 Enumeration query(String primaryKey, String attribute, String value)
          Query the cache
 void remove(Object path)
          remove a file entry from cache
 void removeKey(String primaryKey, String secondaryKey)
           
 void run()
           
 long setMaxSize(long maxSize)
          Sets the maxSize of the SrdiCache object only in the condition where maxSize is > size of the cache in other words we can't shrink it past the size
 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

SrdiCache

public SrdiCache(long maxSize)
Constructor for the SrdiCache object

Parameters:
maxSize - maximum number of entries in the cache

SrdiCache

public SrdiCache(long maxSize,
                 long interval)
Construct a srdiObject and starts a GC thread which runs every "interval" milliseconds

Parameters:
maxSize - maximum number of entries in the cache
interval - the interval at which the gc will run in milliseconds
Method Detail

getMaxSize

public long getMaxSize()
returns the maxSize of the SrdiCache object

Returns:
The maxSize value

setMaxSize

public long setMaxSize(long maxSize)
Sets the maxSize of the SrdiCache object only in the condition where maxSize is > size of the cache in other words we can't shrink it past the size

Parameters:
maxSize - new size
Returns:
new maxSize, if maxSize is less < size, this.maxSize is not modified.

getSize

public long getSize()
Gets the size attribute of the SrdiCache object

Returns:
The number of entries in cache

getPrimaryKeys

public Enumeration getPrimaryKeys()
return all primary keys

Returns:
Enumeration of primary keys

getSecondaryKeys

public Enumeration getSecondaryKeys(String primaryKey)
return all primary keys

Returns:
Enumeration of secondary keys

getEntries

public Enumeration getEntries(String primaryKey,
                              String secondaryKey)
return all entries of primary, and secondary keys

Returns:
Enumeration of Entries

add

public void add(String primaryKey,
                String attribute,
                String value,
                Object path,
                long expiration,
                boolean sticky)
add a cache entry

Parameters:
attribute - Attribute String to query on
value - value of the attribute string
path - in a specific path, if null specified search in all paths
expiration - expiration associated with this entry relative time in milliseconds

containsKey

public boolean containsKey(String primaryKey,
                           String secondaryKey)
Determines whether this object is caching a particular key

Parameters:
primaryKey - primary key to search for
secondaryKey - secondardy key to search for.
Returns:
true if the object is caching key

remove

public void remove(Object path)
remove a file entry from cache

Parameters:
path - relative path

query

public Enumeration query(String primaryKey,
                         String attribute,
                         String value)
Query the cache

Parameters:
attribute - Attribute String to query on
value - value of the attribute string
Returns:
an enumeration of canonical paths

purge

public void purge(int fraction)
Purges some of the cache. The entries are cleaned-up properly.

Parameters:
fraction - Description of the Parameter

clear

public void clear()
Empties the cache completely. The entries are abandonned to the GC.


garbageCollect

public void garbageCollect()

removeKey

public void removeKey(String primaryKey,
                      String secondaryKey)

stop

public void stop()
stop the current running thread


run

public void run()
Specified by:
run in interface Runnable

JXTA J2SE