rabbit.cache
Class NCache

java.lang.Object
  extended byjava.lang.Thread
      extended byrabbit.cache.NCache
All Implemented Interfaces:
java.lang.Runnable

public class NCache
extends java.lang.Thread

The NCache is like a Hashtable in lookup/insert/delete The NCache is persistent over sessions (saves itself to disk). The NCache is selfcleaning, that is it removes old stuff.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NCache()
          Create a cache that uses some dir.
NCache(java.lang.String dir)
          Create a cache for the given directory.
NCache(java.lang.String dir, long maxSize)
          Create a cache for the given directory with given parameters.
NCache(java.lang.String dir, long maxSize, long cacheTime)
          Create a cachehandler.
 
Method Summary
 void addEntry(NCacheEntry ent)
          Insert a CacheEntry into the cache.
 void clear()
          Clear the Cache from files.
 void flush()
          Make sure that the cache is written to the disk.
 java.lang.String getCacheDir()
          Get the name of the directory where the cache stores its files.
 long getCacheTime()
          Get the number of miliseconds the cache stores things usually.
 long getCurrentSize()
          Get the current size of the cache
 java.util.Enumeration getEntries()
          Get the CacheEntries in the cache.
 NCacheEntry getEntry(java.lang.Object o)
          Get the CacheEntry assosiated with given object.
 long getMaxSize()
          Get the maximum size for this cache.
 long getNumberOfEntries()
          Get the current number of entries in the cache.
 NCacheEntry newEntry(java.lang.Object o)
          Reserve space for a CacheEntry with key o.
 void remove(java.lang.Object o)
          Remove the Entry with key o from the cache.
 void run()
          Loop in a cleaning loop.
 void setCacheDir(java.lang.String newDir)
          Sets the cachedir.
 void setCacheTime(long newCacheTime)
          Set the standard expiry-time for CacheEntries
 void setMaxSize(long newMaxSize)
          Set the maximum size for this cache.
 void setup(java.util.Properties config)
          Configure the cache system from the given config.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NCache

public NCache()
Create a cache that uses some dir.


NCache

public NCache(java.lang.String dir)
Create a cache for the given directory.

Parameters:
dir - the name of the directory where the cache should store its files.

NCache

public NCache(java.lang.String dir,
              long maxSize)
Create a cache for the given directory with given parameters.

Parameters:
dir - the name of the directory where the cache should store its files.
maxSize - the maximum size of the proxy.

NCache

public NCache(java.lang.String dir,
              long maxSize,
              long cacheTime)
Create a cachehandler.

Parameters:
dir - the basedir for the cachehandler.
maxSize - the maximum size of the proxy.
cacheTime - how long the proxy should keep things unless specified otherwise.
Method Detail

getCacheDir

public java.lang.String getCacheDir()
Get the name of the directory where the cache stores its files.

Returns:
the name of the cachedir

setCacheDir

public void setCacheDir(java.lang.String newDir)
Sets the cachedir. This will flush the cache and make it try to read in the cache from the new dir.

Parameters:
newDir - the name of the new directory to use.

getMaxSize

public long getMaxSize()
Get the maximum size for this cache.

Returns:
the maximum size in bytes this cache.

setMaxSize

public void setMaxSize(long newMaxSize)
Set the maximum size for this cache.

Parameters:
newMaxSize - the new maximum size for the cache.

getCacheTime

public long getCacheTime()
Get the number of miliseconds the cache stores things usually. This is the standard expiretime for objects, but you can set it for CacheEntries individially if you want to. NOTE 1: dont trust that an object will be in the cache this long. NOTE 2: dont trust that an object will be removed from the cache when it expires.

Returns:
the number of miliseconds objects are stored normally.

setCacheTime

public void setCacheTime(long newCacheTime)
Set the standard expiry-time for CacheEntries

Parameters:
newCacheTime - the number of miliseconds to keep objects normally.

getCurrentSize

public long getCurrentSize()
Get the current size of the cache

Returns:
the current size of the cache in bytes.

getNumberOfEntries

public long getNumberOfEntries()
Get the current number of entries in the cache.

Returns:
the current number of entries in the cache.

getEntry

public NCacheEntry getEntry(java.lang.Object o)
Get the CacheEntry assosiated with given object.

Parameters:
o - the key.
Returns:
the NCacheEntry or null (if not found).

newEntry

public NCacheEntry newEntry(java.lang.Object o)
Reserve space for a CacheEntry with key o.

Parameters:
o - the key for the NCacheEntry.
Returns:
a new CacheEntry initialized for the cache.

addEntry

public void addEntry(NCacheEntry ent)
Insert a CacheEntry into the cache.

Parameters:
ent - the CacheEntry to store.

remove

public void remove(java.lang.Object o)
Remove the Entry with key o from the cache.

Parameters:
o - the key for the CacheEntry.

clear

public void clear()
Clear the Cache from files.


getEntries

public java.util.Enumeration getEntries()
Get the CacheEntries in the cache.

Returns:
an Enumeration of the CacheEntries.

flush

public void flush()
Make sure that the cache is written to the disk.


run

public void run()
Loop in a cleaning loop.


setup

public void setup(java.util.Properties config)
           throws IllegalConfigurationException
Configure the cache system from the given config.

Parameters:
config - the Property describing the cache settings.
Throws:
IllegalConfigurationException - if some setting is strange.