org.apache.excalibur.store.impl
Class MRUMemoryStore

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.excalibur.store.impl.MRUMemoryStore
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.thread.ThreadSafe, org.apache.excalibur.instrument.Instrumentable, Store

public class MRUMemoryStore
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements Store, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.thread.ThreadSafe, org.apache.excalibur.instrument.Instrumentable, org.apache.avalon.framework.component.Component

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.
 org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
           
 java.lang.String getInstrumentableName()
           
 org.apache.excalibur.instrument.Instrument[] getInstruments()
           
 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.
 void service(org.apache.avalon.framework.service.ServiceManager manager)
          Get components of the ComponentLocator
 void setInstrumentableName(java.lang.String name)
           
 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(org.apache.avalon.framework.service.ServiceManager manager)
             throws org.apache.avalon.framework.service.ServiceException
Get components of the ComponentLocator

Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Parameters:
manager - The ComponentLocator
Throws:
org.apache.avalon.framework.service.ServiceException

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.

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)
Specified by:
setInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable

getInstrumentableName

public java.lang.String getInstrumentableName()
Specified by:
getInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable

getInstruments

public org.apache.excalibur.instrument.Instrument[] getInstruments()
Specified by:
getInstruments in interface org.apache.excalibur.instrument.Instrumentable

getChildInstrumentables

public org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
Specified by:
getChildInstrumentables in interface org.apache.excalibur.instrument.Instrumentable


Copyright © 1997-2008 Apache Software Foundation. All Rights Reserved.