org.apache.excalibur.store.impl
Class MRUMemoryStore

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.store.impl.MRUMemoryStore
All Implemented Interfaces:
Component, Disposable, Instrumentable, LogEnabled, Parameterizable, Serviceable, Store, ThreadSafe

public class MRUMemoryStore
extends AbstractLogEnabled
implements Store, Parameterizable, Serviceable, Disposable, ThreadSafe, Instrumentable

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.

Version:
CVS $Id: MRUMemoryStore.java,v 1.5 2004/02/28 11:47:31 cziegeler Exp $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.excalibur.store.Store
PERSISTENT_STORE, ROLE, TRANSIENT_STORE
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
MRUMemoryStore()
           
 
Method Summary
 void clear()
          Clear the Store of all elements
 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.
 Instrumentable[] getChildInstrumentables()
          Any Object which implements Instrumentable can also make use of other Instrumentable child objects.
 java.lang.String getInstrumentableName()
          Gets the name of the Instrumentable.
 Instrument[] getInstruments()
          Obtain a reference to all the Instruments that the Instrumentable object wishes to expose.
 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(Parameters params)
          Initialize the MRUMemoryStore.
 void remove(java.lang.Object key)
          Remove the object associated to the given key.
 void service(ServiceManager manager)
          Get components of the ComponentLocator
 void setInstrumentableName(java.lang.String name)
          Sets the name for the Instrumentable.
 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.AbstractLogEnabled
enableLogging, getLogger, 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

service

public void service(ServiceManager manager)
             throws ServiceException
Get components of the ComponentLocator

Specified by:
service in interface Serviceable
Parameters:
manager - The ComponentLocator
Throws:
ServiceException - if an error occurs

parameterize

public void parameterize(Parameters params)
                  throws ParameterException
Initialize the MRUMemoryStore. A few options can be used:

Specified by:
parameterize in interface Parameterizable
Parameters:
params - Store parameters
Throws:
ParameterException

dispose

public void dispose()
Dispose the component

Specified by:
dispose in interface 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.

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

clear

public void clear()
Clear the Store of all elements

Specified by:
clear 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
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

setInstrumentableName

public void setInstrumentableName(java.lang.String name)
Description copied from interface: Instrumentable
Sets the name for the Instrumentable. The Instrumentable Name is used to uniquely identify the Instrumentable during the configuration of the InstrumentManager and to gain access to an InstrumentableDescriptor through the InstrumentManager. The value should be a string which does not contain spaces or periods.

This value may be set by a parent Instrumentable, or by the InstrumentManager using the value of the 'instrumentable' attribute in the configuration of the component.

Specified by:
setInstrumentableName in interface Instrumentable
Parameters:
name - The name used to identify a Instrumentable.

getInstrumentableName

public java.lang.String getInstrumentableName()
Description copied from interface: Instrumentable
Gets the name of the Instrumentable.

Specified by:
getInstrumentableName in interface Instrumentable
Returns:
The name used to identify a Instrumentable.

getInstruments

public Instrument[] getInstruments()
Description copied from interface: Instrumentable
Obtain a reference to all the Instruments that the Instrumentable object wishes to expose. All sampling is done directly through the Instruments as opposed to the Instrumentable interface.

Specified by:
getInstruments in interface Instrumentable
Returns:
An array of the Instruments available for profiling. Should never be null. If there are no Instruments, then EMPTY_INSTRUMENT_ARRAY can be returned. This should never be the case though unless there are child Instrumentables with Instruments.

getChildInstrumentables

public Instrumentable[] getChildInstrumentables()
Description copied from interface: Instrumentable
Any Object which implements Instrumentable can also make use of other Instrumentable child objects. This method is used to tell the InstrumentManager about them.

Specified by:
getChildInstrumentables in interface Instrumentable
Returns:
An array of child Instrumentables. This method should never return null. If there are no child Instrumentables, then EMPTY_INSTRUMENTABLE_ARRAY can be returned.


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.