Project JXTA

net.jxta.impl.cm
Class Cm

java.lang.Object
  extended bynet.jxta.impl.cm.Cm
All Implemented Interfaces:
Runnable

public final class Cm
extends Object
implements Runnable

This class implements a limited document caching mechanism intended to provide cache for services that have a need for cache to search and exchange jxta documents. Only Core Services are intended to use this mechanism.


Field Summary
static long DEFAULT_GC_MAX_INTERVAL
           
protected  File rootDir
          file descriptor for the root of the cm
static File ROOTDIRBASE
          the name we will use for the base directory
 
Constructor Summary
Cm(String areaName, boolean enableOptimize)
          Constructor for cm
Cm(ThreadGroup threads, String areaName, boolean enableOptimize, long gcinterval, boolean trackDeltas)
          Constructor for cm
 
Method Summary
static String createTmpName(StructuredDocument doc)
          Generates a random file name using doc hashcode
 void garbageCollect()
           
 Vector getDeltas(String dn)
          returns all entries that are added since this method was last called
 Vector getEntries(String dn, boolean clearDeltas)
          returns all entries that are cached
 long getExpirationtime(String dn, String fn)
          Returns the maximum duration in milliseconds for which this document should cached by those other than the publisher.
protected static IndexQuery getIndexQuery(String value)
           
 InputStream getInputStream(String dn, String fn)
          Returns the inputStream of a specified file, in a specified dir
 long getLifetime(String dn, String fn)
          Returns the relative time in milliseconds at which the file will expire.
 Vector getRecords(String dn, int threshold, Vector values, Vector expirations)
          Gets the list of all the files into the given folder
 Vector getRecords(String dn, int threshold, Vector values, Vector expirations, boolean purge)
           
 void remove(String dn, String fn)
          Remove a file
 StructuredDocument restore(String dn, String fn)
          Restore a saved StructuredDocument.
 byte[] restoreBytes(String dn, String fn)
          Restore an advetisement into a byte array.
 void run()
          
 void save(String dn, String fn, Advertisement adv)
          Stores a StructuredDocument in specified dir, and file name
 void save(String dn, String fn, Advertisement adv, long lifetime, long expiration)
          Stores a StructuredDocument in specified dir, and file name, and associated doc timeouts
 void save(String dn, String fn, byte[] data, long lifetime, long expiration)
          Store some bytes in specified dir, and file name, and associated doc timeouts
 Vector search(String dn, String attribute, String value, int threshold, Vector expirations)
          Search and recovers documents that contains at least a macthing pair of tag/value.
 void setTrackDeltas(boolean trackDeltas)
           
 void stop()
          stop the cm
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOTDIRBASE

public static final File ROOTDIRBASE
the name we will use for the base directory


DEFAULT_GC_MAX_INTERVAL

public static final long DEFAULT_GC_MAX_INTERVAL
See Also:
Constant Field Values

rootDir

protected File rootDir
file descriptor for the root of the cm

Constructor Detail

Cm

public Cm(String areaName,
          boolean enableOptimize)
Constructor for cm

Parameters:
areaName - the name of the cm sub-dir to create
enableOptimize - whether to enable indexing NOTE: Default garbage interval once an hour

Cm

public Cm(ThreadGroup threads,
          String areaName,
          boolean enableOptimize,
          long gcinterval,
          boolean trackDeltas)
Constructor for cm

Parameters:
areaName - the name of the cm sub-dir to create
enableOptimize - whether to enable indexing
gcinterval - garbage collect max interval
trackDeltas - when true deltas are tracked
Method Detail

toString

public String toString()

createTmpName

public static String createTmpName(StructuredDocument doc)
Generates a random file name using doc hashcode

Parameters:
doc - to hash to generate a unique name
Returns:
String a random file name

getRecords

public Vector getRecords(String dn,
                         int threshold,
                         Vector values,
                         Vector expirations)
Gets the list of all the files into the given folder

Parameters:
dn - contains the name of the folder
Returns:
Vector Strings containing the name of the files

getRecords

public Vector getRecords(String dn,
                         int threshold,
                         Vector values,
                         Vector expirations,
                         boolean purge)

garbageCollect

public void garbageCollect()

getLifetime

public long getLifetime(String dn,
                        String fn)
Returns the relative time in milliseconds at which the file will expire.

Parameters:
dn - contains the name of the folder
fn - contains the name of the file
Returns:
the absolute time in milliseconds at which this document will expire. -1 is returned if the file is not recognized or already expired.

getExpirationtime

public long getExpirationtime(String dn,
                              String fn)
Returns the maximum duration in milliseconds for which this document should cached by those other than the publisher. This value is either the cache lifetime or the remaining lifetime of the document, whichever is less.

Parameters:
dn - contains the name of the folder
fn - contains the name of the file
Returns:
number of milliseconds until the file expires or -1 if the file is not recognized or already expired.

getInputStream

public InputStream getInputStream(String dn,
                                  String fn)
                           throws IOException
Returns the inputStream of a specified file, in a specified dir

Parameters:
dn - directory name
fn - file name
Returns:
The inputStream value
Throws:
IOException - if an I/O error occurs

remove

public void remove(String dn,
                   String fn)
            throws IOException
Remove a file

Parameters:
dn - directory name
fn - file name
Throws:
IOException - if an I/O error occurs

restore

public StructuredDocument restore(String dn,
                                  String fn)
                           throws IOException
Restore a saved StructuredDocument.

Parameters:
dn - directory name
fn - file name
Returns:
StructuredDocument containing the file
Throws:
IOException - if an I/O error occurs was not possible.

restoreBytes

public byte[] restoreBytes(String dn,
                           String fn)
                    throws IOException
Restore an advetisement into a byte array.

Parameters:
dn - directory name
fn - file name
Returns:
byte [] containing the file
Throws:
IOException - if an I/O error occurs

save

public void save(String dn,
                 String fn,
                 Advertisement adv)
          throws IOException
Stores a StructuredDocument in specified dir, and file name

Parameters:
dn - directory name
fn - file name
adv - Advertisement to store
Throws:
IOException - if an I/O error occurs

save

public void save(String dn,
                 String fn,
                 Advertisement adv,
                 long lifetime,
                 long expiration)
          throws IOException
Stores a StructuredDocument in specified dir, and file name, and associated doc timeouts

Parameters:
dn - directory name
fn - file name
adv - Advertisement to save
expiration - document expiration time in ms
lifetime - document lifetime in ms
Throws:
IOException - if an I/O error occurs

save

public void save(String dn,
                 String fn,
                 byte[] data,
                 long lifetime,
                 long expiration)
          throws IOException
Store some bytes in specified dir, and file name, and associated doc timeouts

Parameters:
dn - directory name
fn - file name
data - byte array to save
expiration - document expiration time in ms
lifetime - document lifetime in ms
Throws:
IOException - if an I/O error occurs

getIndexQuery

protected static IndexQuery getIndexQuery(String value)

search

public Vector search(String dn,
                     String attribute,
                     String value,
                     int threshold,
                     Vector expirations)
Search and recovers documents that contains at least a macthing pair of tag/value.

Parameters:
dn - contains the name of the folder on which to perform the search
value - contains the value to search on.
attribute - attribute to search on
threshold - threshold
Returns:
Enumeration containing of all the documents names

getEntries

public Vector getEntries(String dn,
                         boolean clearDeltas)
returns all entries that are cached

Parameters:
dn - the relative dir name
Returns:
SrdiMessage.Entries

getDeltas

public Vector getDeltas(String dn)
returns all entries that are added since this method was last called

Parameters:
dn - the relative dir name
Returns:
SrdiMessage.Entries

setTrackDeltas

public void setTrackDeltas(boolean trackDeltas)

stop

public void stop()
stop the cm


run

public void run()

Specified by:
run in interface Runnable

JXTA J2SE