org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class MDRCache

java.lang.Object
  extended byorg.netbeans.mdr.persistence.btreeimpl.btreestorage.MDRCache

public class MDRCache
extends java.lang.Object

An in-memory cache of MDR objects. At any given moment, there are four kinds of objects in the cache:

  1. Objects which are referenced by client code, and so cannot be collected.
  2. Objects which have been created but not yes written to disk, and so should not be collected until they are written out.
  3. Objects which have been marked dirty, and so should not be collected until they are written out.
  4. Objects which are nother referenced nor dirty, and so are eligible for collection.
The cache also keep s track of the keys of objects which have been deleted.

The creator of the cache specifies how many objects to cache in memory. Hard references are kept to the last N objects used, to enforce this. The cache keeps soft references to the other objects of the third type, so how often they are collected depends upon memory usage and the JVM's GC implementation.


Nested Class Summary
static interface MDRCache.OverflowHandler
          The cache handler is called when the number of changes in the cache reaches its threshhold.
 
Constructor Summary
MDRCache(int size)
          Create the cache
MDRCache(int size, MDRCache.OverflowHandler hndlr, int limit)
          Create the cache
 
Method Summary
 void clear()
          clear all unecessary objects from the cache
 void clearLists()
          Clear the set of new, dirty, and deleted objects, presumably after having written them all out.
 java.lang.Object get(java.lang.Object m)
          get an object from the cache
 java.util.Collection getDeleted()
          Get all of the deleted IDs
 java.util.Collection getDirty()
          Get all of the dirty objects
 java.util.Collection getNew()
          Get all of the new objects
 boolean hasChanges()
          returns true if the cache contains any changed objects
 boolean isDeleted(java.lang.Object key)
          check if the object with the given key is deleted
 boolean isNew(java.lang.Object key)
          check if the object with the given key is new
 java.util.Iterator iterateActive()
          Get an iterator over the keys of all active objects in the cache
 java.util.Iterator iterateDeleted()
          Get an iterator over the keys of deleted objects
 java.util.Iterator iterateNew()
          Get an iterator over the keys of new objects
 int numberDeleted()
          return the number of deleted objects
 int numberNew()
          return the number of new objects
 void put(java.lang.Object m, java.lang.Object o)
          add a new object to the cache
 void remove(java.lang.Object m)
          remove an object from the cache
 void replace(java.lang.Object m, java.lang.Object o)
          replace an object in the cache
 void setDirty(java.lang.Object key)
          mark that the object with the given MOF ID is dirty
 void setNew(java.lang.Object key)
          mark that the object with the given MOF ID is new
 void showStats(java.io.PrintStream strm)
          Show caching statistics
 void showStats(java.io.PrintWriter strm)
          Show caching statistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MDRCache

public MDRCache(int size,
                MDRCache.OverflowHandler hndlr,
                int limit)
Create the cache

Parameters:
size - how many objects to cache in memory
hndlr - handler to call when the cache has too many changed objects
limit - number of changed objects to allow

MDRCache

public MDRCache(int size)
Create the cache

Parameters:
size - how many objects to cache in memory
Method Detail

hasChanges

public boolean hasChanges()
returns true if the cache contains any changed objects

Returns:
true if any objects have been modified or deleted

put

public void put(java.lang.Object m,
                java.lang.Object o)
         throws StorageException
add a new object to the cache

Parameters:
m - the object's MOF ID
o - the object to add
Throws:
StorageException

get

public java.lang.Object get(java.lang.Object m)
get an object from the cache

Parameters:
m - the object's MOF ID

replace

public void replace(java.lang.Object m,
                    java.lang.Object o)
             throws StorageException
replace an object in the cache

Parameters:
m - the object's key
o - the object
Throws:
StorageException

remove

public void remove(java.lang.Object m)
remove an object from the cache

Parameters:
m - the object's MOF ID
Returns:
true if the object was found in the cache

clear

public void clear()
clear all unecessary objects from the cache


setNew

public void setNew(java.lang.Object key)
            throws StorageException
mark that the object with the given MOF ID is new

Parameters:
key - MOF ID
Throws:
StorageException

isNew

public boolean isNew(java.lang.Object key)
check if the object with the given key is new

Returns:
true if it is new

iterateActive

public java.util.Iterator iterateActive()
Get an iterator over the keys of all active objects in the cache

Returns:
the iterator

iterateDeleted

public java.util.Iterator iterateDeleted()
Get an iterator over the keys of deleted objects

Returns:
the iterator

iterateNew

public java.util.Iterator iterateNew()
Get an iterator over the keys of new objects

Returns:
the iterator

numberNew

public int numberNew()
return the number of new objects

Returns:
number of new objects

numberDeleted

public int numberDeleted()
return the number of deleted objects

Returns:
number of deleted objects

isDeleted

public boolean isDeleted(java.lang.Object key)
check if the object with the given key is deleted

Returns:
true if it is deleted

setDirty

public void setDirty(java.lang.Object key)
              throws StorageException
mark that the object with the given MOF ID is dirty

Parameters:
key - MOF ID
Throws:
StorageException

getNew

public java.util.Collection getNew()
Get all of the new objects

Returns:
the keys of the new objects

getDirty

public java.util.Collection getDirty()
Get all of the dirty objects

Returns:
the keys of the dirty objects

getDeleted

public java.util.Collection getDeleted()
Get all of the deleted IDs

Returns:
the deleted IDs

clearLists

public void clearLists()
Clear the set of new, dirty, and deleted objects, presumably after having written them all out.


showStats

public void showStats(java.io.PrintStream strm)
Show caching statistics


showStats

public void showStats(java.io.PrintWriter strm)
Show caching statistics



Copyright © 2005 Apache Software Foundation. All Rights Reserved.