org.apache.jcs.engine.memory
Class AbstractMemoryCache<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.engine.memory.AbstractMemoryCache<K,V>
All Implemented Interfaces:
Serializable, IRequireScheduler, IMemoryCache<K,V>
Direct Known Subclasses:
AbstractDoubleLinkedListMemoryCache, LHMLRUMemoryCache

public abstract class AbstractMemoryCache<K extends Serializable,V extends Serializable>
extends Object
implements IMemoryCache<K,V>, Serializable, IRequireScheduler

This base includes some common code for memory caches.

This keeps a static reference to a memory shrinker clock daemon. If this region is configured to use the shrinker, the clock daemon will be setup to run the shrinker on this region.

See Also:
Serialized Form

Field Summary
 CompositeCache<K,V> cache
          The cache region this store is associated with
 ICompositeCacheAttributes cacheAttributes
          Cache Attributes.
protected  String cacheName
          The region name.
protected  int chunkSize
          How many to spool at a time.
 IElementAttributes elementAttributes
          Region Elemental Attributes, used as a default and copied for each item.
 Map<K,MemoryElementDescriptor<K,V>> map
          Map where items are stored by key.
protected  CacheStatus status
          status
 
Constructor Summary
AbstractMemoryCache()
           
 
Method Summary
abstract  Map<K,MemoryElementDescriptor<K,V>> createMap()
          Children must implement this method.
 void dispose()
          Prepares for shutdown.
 void dumpMap()
          Dump the cache map for debugging.
abstract  ICacheElement<K,V> get(K key)
          Get an item from the cache
 ICompositeCacheAttributes getCacheAttributes()
          Returns the CacheAttributes.
 String getCacheName()
          Returns the cache (aka "region") name.
 CompositeCache<K,V> getCompositeCache()
          Gets the cache hub / region that the MemoryCache is used by
 Set<K> getGroupKeys(String groupName)
          Gets the set of keys of objects currently in the group.
 Set<String> getGroupNames()
          Gets the set of group names in the cache
 Iterator<Map.Entry<K,MemoryElementDescriptor<K,V>>> getIterator()
          Gets the iterator attribute of the LRUMemoryCache object
abstract  Set<K> getKeySet()
          Get a set of the keys for all elements in the memory cache
 Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
          Gets multiple items from the cache based on the given set of keys.
 ICacheElement<K,V> getQuiet(K key)
          Get an item from the cache without affecting its last access time or position.
 int getSize()
          Returns the current cache size.
 IStats getStatistics()
          Returns the historical and statistical data for a region's memory cache.
 CacheStatus getStatus()
          Returns the cache status.
 void initialize(CompositeCache<K,V> hub)
          For post reflection creation initialization
abstract  boolean remove(K key)
          Removes an item from the cache
 void removeAll()
          Removes all cached items from the cache.
 void setCacheAttributes(ICompositeCacheAttributes cattr)
          Sets the CacheAttributes.
 void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
          Inject an instance of a central ScheduledExecutorService
abstract  void update(ICacheElement<K,V> ce)
          Puts an item to the cache.
 void waterfal(ICacheElement<K,V> ce)
          Puts an item to the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jcs.engine.memory.behavior.IMemoryCache
freeElements
 

Field Detail

cacheName

protected String cacheName
The region name. This defines a namespace of sorts.


map

public Map<K extends Serializable,MemoryElementDescriptor<K extends Serializable,V extends Serializable>> map
Map where items are stored by key. This is created by the concrete child class.


elementAttributes

public IElementAttributes elementAttributes
Region Elemental Attributes, used as a default and copied for each item.


cacheAttributes

public ICompositeCacheAttributes cacheAttributes
Cache Attributes. Regions settings.


cache

public CompositeCache<K extends Serializable,V extends Serializable> cache
The cache region this store is associated with


status

protected CacheStatus status
status


chunkSize

protected int chunkSize
How many to spool at a time.

Constructor Detail

AbstractMemoryCache

public AbstractMemoryCache()
Method Detail

initialize

public void initialize(CompositeCache<K,V> hub)
For post reflection creation initialization

Specified by:
initialize in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
hub -

setScheduledExecutorService

public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
Description copied from interface: IRequireScheduler
Inject an instance of a central ScheduledExecutorService

Specified by:
setScheduledExecutorService in interface IRequireScheduler
See Also:
IRequireScheduler.setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)

createMap

public abstract Map<K,MemoryElementDescriptor<K,V>> createMap()
Children must implement this method. A FIFO implementation may use a tree map. An LRU might use a hashtable. The map returned should be threadsafe.

Returns:
a threadsafe Map

remove

public abstract boolean remove(K key)
                        throws IOException
Removes an item from the cache

Specified by:
remove in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key - Identifies item to be removed
Returns:
Description of the Return Value
Throws:
IOException - Description of the Exception

get

public abstract ICacheElement<K,V> get(K key)
                                                                          throws IOException
Get an item from the cache

Specified by:
get in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key - Description of the Parameter
Returns:
Description of the Return Value
Throws:
IOException - Description of the Exception

getMultiple

public Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
                                                                                                     throws IOException
Gets multiple items from the cache based on the given set of keys.

Specified by:
getMultiple in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
keys -
Returns:
a map of K key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
Throws:
IOException

getQuiet

public ICacheElement<K,V> getQuiet(K key)
                                                                      throws IOException
Get an item from the cache without affecting its last access time or position. Not all memory cache implementations can get quietly.

Specified by:
getQuiet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key - Identifies item to find
Returns:
Element matching key if found, or null
Throws:
IOException

update

public abstract void update(ICacheElement<K,V> ce)
                     throws IOException
Puts an item to the cache.

Specified by:
update in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
ce - Description of the Parameter
Throws:
IOException - Description of the Exception

getKeySet

public abstract Set<K> getKeySet()
Get a set of the keys for all elements in the memory cache

Specified by:
getKeySet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
A set of the key type

removeAll

public void removeAll()
               throws IOException
Removes all cached items from the cache.

Specified by:
removeAll in interface IMemoryCache<K extends Serializable,V extends Serializable>
Throws:
IOException

dispose

public void dispose()
             throws IOException
Prepares for shutdown.

Specified by:
dispose in interface IMemoryCache<K extends Serializable,V extends Serializable>
Throws:
IOException

getStatistics

public IStats getStatistics()
Description copied from interface: IMemoryCache
Returns the historical and statistical data for a region's memory cache.

Specified by:
getStatistics in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
statistics about the cache

getSize

public int getSize()
Returns the current cache size.

Specified by:
getSize in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
The size value

getStatus

public CacheStatus getStatus()
Returns the cache status.

Returns:
The status value

getCacheName

public String getCacheName()
Returns the cache (aka "region") name.

Returns:
The cacheName value

waterfal

public void waterfal(ICacheElement<K,V> ce)
              throws IOException
Puts an item to the cache.

Specified by:
waterfal in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
ce -
Throws:
IOException

getIterator

public Iterator<Map.Entry<K,MemoryElementDescriptor<K,V>>> getIterator()
Gets the iterator attribute of the LRUMemoryCache object

Specified by:
getIterator in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
The iterator value

dumpMap

public void dumpMap()
Dump the cache map for debugging.


getCacheAttributes

public ICompositeCacheAttributes getCacheAttributes()
Returns the CacheAttributes.

Specified by:
getCacheAttributes in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
The CacheAttributes value

setCacheAttributes

public void setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the CacheAttributes.

Specified by:
setCacheAttributes in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
cattr - The new CacheAttributes value

getCompositeCache

public CompositeCache<K,V> getCompositeCache()
Gets the cache hub / region that the MemoryCache is used by

Specified by:
getCompositeCache in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
The cache value

getGroupKeys

public Set<K> getGroupKeys(String groupName)
Description copied from interface: IMemoryCache
Gets the set of keys of objects currently in the group.

Specified by:
getGroupKeys in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
groupName -
Returns:
group keys

getGroupNames

public Set<String> getGroupNames()
Gets the set of group names in the cache

Specified by:
getGroupNames in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
a Set of group names.


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.