Goods.CacheManager Class
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.

Access: Public
Base Classes: Object
  Members Description  
    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.

 
    FreeMemoryWatermark Set new watermark for minimal size of fee memory

 
    globalCS Critical section to synchronize access to static variables of metaobject

 
    transObjects Header of l2-list of objects involved in trabsaction. Modified objects are placed at the beginning of the list (transObjects.next...), while not-modified objects involved in transaction are placed at the end of the list (transObjects.prev...) This is done to optimize sending of transaction to the storage server (no extra sort or repacking of objects is needed). If object was first included in transaction list as "non-modified" and later was modified, then it will be relinked to the beginning of the transaction list. Object are kept in the transaction list until the end of transaction to prevent GC from deallocating them before end of tranasction.

 
    lru0 Headers for two l2-lists used to implement enhanced LRU discipline for replacing objects in object cache. Head of the list contains most recently used object and tail - least recently used objects. To prevent object cache from replacing all object as a result of database serach through large number of obejct (most of which will not be used in future), standard LRU scheme was extended to more fit specific of database applications. Object cache is divided into two part: primary cache and cache for frequently used objects. First time object is accessed, it is placed in primary cache. Object will be moved to "frequently used objects" cache only when it is accessed more than twice and it is not at the head of LRU list (case of several sucessive accesses to the object). Both cache parts are managed separately: when total size of objects in the one part exceeds some limit value, least recently used objects from this part are thrown away from clients memory not affecting objects in another part of the cache.

 
    lru1 Frequesntly accessed object list (see above )

 
    cacheSize0 Total sizes of objects in the part of the cache (see explanation above) Stub objects are not placed in the cache so thier size in not included into this values. The total size occpied by persistent objects in client memory therefore can be greater than cacheSize0+cacheSize1.

 
    cacheSize1 size of frequently accessed list (see above)

 
    cacheSizeLimit0 Limits for total size of objects in both parts of the cache (see explanation above). If size of some object exceed this limit values, it will be placed in the cache in any case.

 
    cacheSizeLimit1 Limit for the frequently accessed Cache size 2Mb

 
    freeMemoryWatermark Minimal size of available free memory after reaching which object cache is cleaned to prevent hanging of thrown objects in the memory as a result of presence references to this objects. (1M)

 
    nestedTransactionCount Counter of nested transactions (or nested invocations of methods of classes derived from Persistent class). BasicMetaobject implements implicit scheme of detection transaction boundaries. Transaction is committed when no more active methods exists for the classes controlled by this metaobject (or metaobjects derived from Basicmetaobject), i.e. when nestedTransactionCount is equal to zero. It is possbile to manualy increment and decrement this count, so explictly set transaction boundaries (see methods beginNestedTransaction() and endNestedTransaction() below.

 
    forgottenObjectList Head of a L1 list to save "forgotten objects". Forgotten means they were garbage collected, they are added here in ObjectState.finalize(). Their Id's are sent back to the server, as finalizing is almost like locally deleting the object. This helps the server side garbage collection.

 
    transactionMutex Mutex used to provide exclusive access to CacheManager. By means of this mutex per-threads transactions sharing the same database connection are implemented. This mutex is used by BasicMetaobject when transaction model is PER_THREAD

 
    isolationLevel Isolation level: Database.PER_THREAD_TRANSACTION or Database.PER_PROCESS_TRANSACTION

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

 
    defaultCacheManager defaultCacheManager is the one used if the current thread, requesting the CacheManager (CahceManager.getCacheManager()) isnot attatched. In other words this is used as a "global" CacheManager.

 
    nAttached nAttached is the count of how many Threads have been attatched. If this reaches the maximum (hashCleanupPeriod = 64), the attatched threads are checked (if they are still alive).

 
    cacheManagerHash cacheManagerHash holds the threads that have attatched themselves. A thread may use new CahceManager().attatch() to do so. The keys are the threads, the values the managers

 
    hashCleanupPeriod After this many attatch calls (64) the attatch method checks that all attached threads (see cacheManagerHash) are still alive

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

 
    attach    
    detach Detach cache manager from current thread

 
    detach detach the given thread. Removes the associated cache manager from the hashtable (cacheManagerHash)

 
    linkAfter 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

 
    linkBefore linkBefore links "obj" before "before" such that obj.next == before.

 
    unlink unlink the given object so that obj.next.prev = obj.prev and obj.prev.next = obj.next

 
    objectAllocationOverhead Size of Persitent head plus size used by finilizer and object hash entry (64)

 
    removeFromCache 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.

 
    removeFromCache Remove from cache all objects from the specified database

 
    insertInCache 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.

 
    addToTransaction 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.

 
    setCacheLimits Set new limits for object cache. See description of cache management algorithm at the beggining of this file.

 
    enter This method is called by Metaobject.preDaemon to determine start of access to the database

 
    leave This method is called by Metaobject.postDaemon to determine end of access to the database

 
    forgetObject Place object in forgotten list