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

java.lang.Object
  extended by org.apache.jcs.engine.memory.MockMemoryCache<K,V>
All Implemented Interfaces:
IMemoryCache<K,V>

public class MockMemoryCache<K extends Serializable,V extends Serializable>
extends Object
implements IMemoryCache<K,V>

Mock implementation of a memory cache for testing things like the memory shrinker.

Author:
Aaron Smuts

Field Summary
 int lastNumberOfFreedElements
          The number passed to the last call of free elements.
 int waterfallCallCount
          The number of times waterfall was called.
 
Constructor Summary
MockMemoryCache()
           
 
Method Summary
 void dispose()
          Destroy the memory cache
 int freeElements(int numberToFree)
           
 ICacheElement<K,V> get(K key)
           
 ICompositeCacheAttributes getCacheAttributes()
           
 CompositeCache<K,V> getCompositeCache()
           
 Set<K> getGroupKeys(String group)
           
 Set<String> getGroupNames()
           
 Iterator<Map.Entry<K,MemoryElementDescriptor<K,V>>> getIterator()
           
 Set<K> getKeySet()
           
 Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
           
 ICacheElement<K,V> getQuiet(K key)
           
 int getSize()
           
 IStats getStatistics()
           
 void initialize(CompositeCache<K,V> cache)
          Does nothing
 boolean remove(K key)
           
 void removeAll()
           
 void setCacheAttributes(ICompositeCacheAttributes cattr)
           
 void update(ICacheElement<K,V> ce)
           
 void waterfal(ICacheElement<K,V> ce)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

waterfallCallCount

public int waterfallCallCount
The number of times waterfall was called.


lastNumberOfFreedElements

public int lastNumberOfFreedElements
The number passed to the last call of free elements.

Constructor Detail

MockMemoryCache

public MockMemoryCache()
Method Detail

initialize

public void initialize(CompositeCache<K,V> cache)
Does nothing

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

dispose

public void dispose()
             throws IOException
Destroy the memory cache

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

getSize

public int getSize()
Specified by:
getSize in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
size

getStatistics

public IStats getStatistics()
Specified by:
getStatistics in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
stats

getIterator

public Iterator<Map.Entry<K,MemoryElementDescriptor<K,V>>> getIterator()
Specified by:
getIterator in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
null

getKeySet

public Set<K> getKeySet()
Specified by:
getKeySet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
map.keySet().toArray(

remove

public boolean remove(K key)
               throws IOException
Specified by:
remove in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
map.remove( key ) != null
Throws:
IOException

removeAll

public void removeAll()
               throws IOException
Specified by:
removeAll in interface IMemoryCache<K extends Serializable,V extends Serializable>
Throws:
IOException

get

public ICacheElement<K,V> get(K key)
                                                                 throws IOException
Specified by:
get in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
(ICacheElement) map.get( key )
Throws:
IOException

getMultiple

public Map<K,ICacheElement<K,V>> getMultiple(Set<K> keys)
                                                                                                     throws IOException
Specified by:
getMultiple in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
keys -
Returns:
elements
Throws:
IOException

getQuiet

public ICacheElement<K,V> getQuiet(K key)
                                                                      throws IOException
Specified by:
getQuiet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
(ICacheElement) map.get( key )
Throws:
IOException

waterfal

public void waterfal(ICacheElement<K,V> ce)
              throws IOException
Specified by:
waterfal in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
ce -
Throws:
IOException

update

public void update(ICacheElement<K,V> ce)
            throws IOException
Specified by:
update in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
ce -
Throws:
IOException

getCacheAttributes

public ICompositeCacheAttributes getCacheAttributes()
Specified by:
getCacheAttributes in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
ICompositeCacheAttributes

setCacheAttributes

public void setCacheAttributes(ICompositeCacheAttributes cattr)
Specified by:
setCacheAttributes in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
cattr -

getCompositeCache

public CompositeCache<K,V> getCompositeCache()
Specified by:
getCompositeCache in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
null

getGroupKeys

public Set<K> getGroupKeys(String group)
Specified by:
getGroupKeys in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
group -
Returns:
null

getGroupNames

public Set<String> getGroupNames()
Specified by:
getGroupNames in interface IMemoryCache<K extends Serializable,V extends Serializable>
Returns:
null

freeElements

public int freeElements(int numberToFree)
                 throws IOException
Specified by:
freeElements in interface IMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
numberToFree -
Returns:
0
Throws:
IOException


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