goodsjpi
Class CacheManager

java.lang.Object
  extended bygoodsjpi.CacheManager

public class CacheManager
extends java.lang.Object

CacheManager may be used on a per Thread basis (see attatch and detatch), or on a global basis (defaultCacheManager), to cache the objects on client side and to keep transaction list.
Two caches are kept, a last recently used and a frequesntly used. Cache and transaction list are kept as double linked lists.


Constructor Summary
CacheManager()
          Initialize all the double linked lists with empty Persistent objects.
 
Method Summary
 void addToTransaction(Persistent obj)
          Include object in transaction list.
 void attach()
          Associate cache manager with current thread.
 void detach()
          Detach cache manager from current thread
 void detach(java.lang.Thread thread)
          detach the given thread.
 void enter()
          This method is called by Metaobject.preDaemon to determine start of access to the database
 void forgetObject(Persistent obj)
          Place object in forgotten list
static CacheManager getCacheManager()
          getCacheManager the current manager.
 void insertInCache(Persistent obj)
          insertInCache insert object in one of two cache LRU lists depending on its current state.
 void leave()
          This method is called by Metaobject.postDaemon to determine end of access to the database
static void linkAfter(Persistent after, Persistent obj)
          Link the given object after the other.
static void linkBefore(Persistent before, Persistent obj)
          linkBefore links "obj" before "before" such that obj.next == before.
 void removeFromCache(Database db)
          Remove from cache all objects from the specified database
 void removeFromCache(Persistent obj)
          Exclude object from LRU list so making it not available for cached objects LRU relpacing algorithm.
 void setCacheLimits(int l0, int l1)
          Set new limits for object cache.
 void setFreeMemoryWatermark(long watermark)
          Set new watermark for minimal size of fee memory
static void unlink(Persistent obj)
          unlink the given object so that obj.next.prev = obj.prev and obj.prev.next = obj.next
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheManager

public CacheManager()
Initialize all the double linked lists with empty Persistent objects. The test whether a list is empty is thus list.next==list.prev .

Method Detail

getCacheManager

public static CacheManager getCacheManager()
getCacheManager the current manager. This is the per-thread manager that has called attatch() or the default one if attatch has never been called on the current thread.

Returns:
a CacheManager value, see above.

attach

public void attach()
Associate cache manager with current thread. If the cleanupPeriod has been exceeded, check if all attatched threads are still alive.


detach

public void detach()
Detach cache manager from current thread


detach

public void detach(java.lang.Thread thread)
detach the given thread. Removes the associated cache manager from the hashtable (cacheManagerHash)

Parameters:
thread - a Thread to detatch

linkAfter

public static void linkAfter(Persistent after,
                             Persistent obj)
Link the given object after the other. Ie, open the double linked list after "after" and insert obj into it, so that after.next = obj and the previous after.next is obj.next

Parameters:
after - a Persistent value, to link obj after
obj - a Persistent value, to link in after "after"

linkBefore

public static void linkBefore(Persistent before,
                              Persistent obj)
linkBefore links "obj" before "before" such that obj.next == before.

Parameters:
before - a Persistent value to link object before
obj - a Persistent value to link in.

unlink

public static void unlink(Persistent obj)
unlink the given object so that obj.next.prev = obj.prev and obj.prev.next = obj.next

Parameters:
obj - a Persistent value to unlink.

removeFromCache

public void removeFromCache(Persistent obj)
Exclude object from LRU list so making it not available for cached objects LRU relpacing algorithm. This method is called in two situations: 1) when object is accessed to prevent it from throwing away until it is accessed by active method. 2) when modification notification for this object was received from server and instance of deteriorated object instance is removed from clients memory.

Parameters:
obj - a Persistent value

removeFromCache

public void removeFromCache(Database db)
Remove from cache all objects from the specified database

Parameters:
db - database which objects should be removed from cache

insertInCache

public void insertInCache(Persistent obj)
insertInCache insert object in one of two cache LRU lists depending on its current state. If total size of objects in this part of the cache exceeds limit value, least recently used objects will be removed from the cache (and from client memory) until total size of objects becomes less or equal than limit.

Parameters:
obj - a Persistent value

addToTransaction

public void addToTransaction(Persistent obj)
Include object in transaction list. If object is modified it will be placed at the head of the list, otherwise at the tail of the list. If object already was included in transaction as "read-only", and later was modified, it will relinked to the head of the list.

Parameters:
obj - a Persistent value

setFreeMemoryWatermark

public void setFreeMemoryWatermark(long watermark)
Set new watermark for minimal size of fee memory

Parameters:
watermark - a long value

setCacheLimits

public void setCacheLimits(int l0,
                           int l1)
Set new limits for object cache. See description of cache management algorithm at the beggining of this file.

Parameters:
l0 - an int value
l1 - an int value

enter

public final void enter()
This method is called by Metaobject.preDaemon to determine start of access to the database


leave

public final void leave()
This method is called by Metaobject.postDaemon to determine end of access to the database


forgetObject

public void forgetObject(Persistent obj)
Place object in forgotten list