org.apache.cocoon.components.store
Class MRUMemoryStore

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.components.store.MRUMemoryStore
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.parameters.Parameterizable, Store, org.apache.avalon.framework.thread.ThreadSafe

public final class MRUMemoryStore
extends org.apache.avalon.framework.logger.AbstractLoggable
implements Store, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.thread.ThreadSafe

This class provides a cache algorithm for the requested documents. It combines a HashMap and a LinkedList to create a so called MRU (Most Recently Used) cache. The idea was taken from the "Writing Advanced Application Tutorial" from javasoft. Many thanx to the writers!

Version:
CVS $Id: MRUMemoryStore.java,v 1.14 2002/03/08 04:09:59 vgritsenko Exp $
Author:
Gerhard Froehlich, Davanum Srinivas, Vadim Gritsenko

Fields inherited from interface org.apache.cocoon.components.store.Store
PERSISTENT_CACHE, ROLE, TRANSIENT_CACHE
 
Constructor Summary
MRUMemoryStore()
           
 
Method Summary
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
          Get components of the ComponentManager
 boolean containsKey(java.lang.Object key)
          Indicates if the given key is associated to a contained object.
 void dispose()
          Dispose the component
 void free()
          Frees some of the fast memory used by this store.
 java.lang.Object get(java.lang.Object key)
          Get the object associated to the given unique key.
 void hold(java.lang.Object key, java.lang.Object value)
          This method holds the requested object in a HashMap combined with a LinkedList to create the MRU.
 java.util.Enumeration keys()
          Returns the list of used keys as an Enumeration.
 void parameterize(org.apache.avalon.framework.parameters.Parameters params)
          Initialize the MRUMemoryStore.
 void remove(java.lang.Object key)
          Remove the object associated to the given key.
 int size()
          Returns count of the objects in the store, or -1 if could not be obtained.
 void store(java.lang.Object key, java.lang.Object value)
          Store the given object in a persistent state.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MRUMemoryStore

public MRUMemoryStore()
Method Detail

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
             throws org.apache.avalon.framework.component.ComponentException
Get components of the ComponentManager
Specified by:
compose in interface org.apache.avalon.framework.component.Composable
Parameters:
manager - The ComponentManager

parameterize

public void parameterize(org.apache.avalon.framework.parameters.Parameters params)
                  throws org.apache.avalon.framework.parameters.ParameterException
Initialize the MRUMemoryStore. A few options can be used:
Specified by:
parameterize in interface org.apache.avalon.framework.parameters.Parameterizable
Parameters:
params - Store parameters
Throws:
org.apache.avalon.framework.parameters.ParameterException -  

dispose

public void dispose()
Dispose the component
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

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
Parameters:
key - The key for the object to store
value - The object to store

hold

public void hold(java.lang.Object key,
                 java.lang.Object value)
This method holds the requested object in a HashMap combined with a LinkedList to create the MRU. It also stores objects onto the filesystem if configured.
Specified by:
hold in interface Store
Parameters:
key - The key of the object to be stored
value - The object to be stored

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
Parameters:
key - The key of the requested object
Returns:
the requested object

remove

public void remove(java.lang.Object key)
Remove the object associated to the given key.
Specified by:
remove in interface Store
Parameters:
key - The key of to be removed object

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
Parameters:
key - The key of the object
Returns:
true if the key exists

keys

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

size

public int size()
Returns count of the objects in the store, or -1 if could not be obtained.
Specified by:
size in interface Store

free

public void free()
Frees some of the fast memory used by this store. It removes the last element in the store.
Specified by:
free in interface Store


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.