org.apache.cocoon.store
Class MemoryStore

java.lang.Object
  |
  +--org.apache.cocoon.framework.AbstractActor
        |
        +--org.apache.cocoon.store.MemoryStore

public class MemoryStore
extends AbstractActor
implements Store, Configurable, Status

This class implements a memory-managed hashtable wrapper that uses a weighted mix of LRU and LFU to keep track of object importance. NOTE: this class is _HIGHLY_ un-optimized and this class is _CRITICAL_ for a fast performance of the whole system. So, if you find any better way to implement this class (clever data models, smart update algorithms, etc...), please, consider patching this implementation or sending a note about a method to do it.

Version:
$Revision: 1.2 $ $Date: 1999/10/19 21:38:54 $
Author:
Stefano Mazzocchi

Inner Class Summary
(package private)  class MemoryStore.Container
           
 
Field Summary
private static long factor
          Indicates the factor of LFU compared to LRU.
private  java.util.Hashtable hashtable
           
private  java.lang.Runtime jvm
           
private  int memory
           
 
Fields inherited from class org.apache.cocoon.framework.AbstractActor
director
 
Constructor Summary
MemoryStore()
           
 
Method Summary
 boolean containsKey(java.lang.Object key)
          Indicates if the given key is associated to a contained object.
private  long evaluate(MemoryStore.Container c, long time)
          This method evaluates every contained object and is a function of LRU (last recently used) and LFU (last frequenly used) paradigms.
 java.lang.Object get(java.lang.Object key)
          Get the object associated to the given unique key.
 java.lang.String getStatus()
          Returns the signature of this store implementation
private  java.lang.Object getWorst()
          This method returns the key to the worst object included.
 void hold(java.lang.Object key, java.lang.Object object)
          Holds the given object in a volatile state.
 void init(Configurations confs)
          Initialize the class by passing its configurations.
 java.util.Enumeration list()
          Returns the list of used keys.
 void remove(java.lang.Object key)
          Remove the object associated to the given key and returns the object associated to the given key or null if not found.
 void store(java.lang.Object key, java.lang.Object value)
          Store the given object in a persistent state.
 
Methods inherited from class org.apache.cocoon.framework.AbstractActor
init
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

jvm

private java.lang.Runtime jvm

memory

private int memory

hashtable

private java.util.Hashtable hashtable

factor

private static final long factor
Indicates the factor of LFU compared to LRU. See code for more details.
Constructor Detail

MemoryStore

public MemoryStore()
Method Detail

init

public void init(Configurations confs)
          throws InitializationException
Description copied from interface: Configurable
Initialize the class by passing its configurations.
Specified by:
init in interface Configurable

store

public void store(java.lang.Object key,
                  java.lang.Object value)
Store the given object in a persistent state. It is up to the caller to ensure that the key has a persistent state across different JVM executions.
Specified by:
store in interface Store

hold

public void hold(java.lang.Object key,
                 java.lang.Object object)
Holds the given object in a volatile state. This means the object store will discard held objects if the virtual machine is restarted or some error happens.
Specified by:
hold in interface Store

get

public java.lang.Object get(java.lang.Object key)
Get the object associated to the given unique key.
Specified by:
get in interface Store

remove

public void remove(java.lang.Object key)
Remove the object associated to the given key and returns the object associated to the given key or null if not found.
Specified by:
remove in interface Store

containsKey

public boolean containsKey(java.lang.Object key)
Indicates if the given key is associated to a contained object.
Specified by:
containsKey in interface Store

list

public java.util.Enumeration list()
Returns the list of used keys.
Specified by:
list in interface Store

getWorst

private java.lang.Object getWorst()
This method returns the key to the worst object included. NOTE: this is a very un-optimized method. A better data model using b-trees as side indexes could reduce the work done at this point. This method is an hotspot since it may be called more than once per each insert method in the cache and its complexity is currently linear with the cache size.

evaluate

private long evaluate(MemoryStore.Container c,
                      long time)
This method evaluates every contained object and is a function of LRU (last recently used) and LFU (last frequenly used) paradigms. NOTE: this evaluation system may be rendered pluggable if different paradigms are found better for different situations. At this point, I'm not sure this counts that much.

getStatus

public java.lang.String getStatus()
Returns the signature of this store implementation
Specified by:
getStatus in interface Status


Copyright 1999 Java Apache Project. All Rights Reserved.