DODS 7.3 API

org.enhydra.dods.cache.complete
Class DODSHashMapCache

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.enhydra.dods.cache.complete.DODSHashMapCache
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, DODSCache, CacheStatistics

public class DODSHashMapCache
extends java.util.HashMap
implements DODSCache

DODSHashMapCache class implements HashMap cache (for storing data objects (or DataStruct objects), or simple queries, or complex queries), and provides query statistics about the cache (query number, cache hits number, their get/set/increment methods, percents of used cache, cache hits,...).

Version:
1.0 11.06.2006.
Author:
Tanja Jovanovic
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  int cacheAccessNum
          Total number of times the cache was accessed.
protected  int cacheHitsNum
          Number of queries performed on the cache successfully.
 
Method Summary
 java.lang.Object add(java.lang.Object key, java.lang.Object value)
          Adds a pair (key, value) to the cache.
 void clearStatistics()
          Clears statistics.
 int getCacheAccessNum()
          Returns total number of times the cache was accessed.
 int getCacheHitsNum()
          Returns number of queries performed on the cache successfully.
 double getCacheHitsPercents()
          Returns how much queries performed on the cache were successful.
 int getMaxEntries()
          Returns maximal number of objects in DODSHashMapCache.
 double getUsedPercents()
          Returns how much cache is currently used.
 void incrementCacheAccessNum(int num)
          Increases total number of times the cache was accessed.
 void incrementCacheHitsNum(int num)
          Increases number of queries performed on the cache successfully for one.
 boolean isNeedToSynchronize()
           
 void setCacheAccessNum(int num)
          Sets total number of times the cache was accessed.
 void setCacheHitsNum(int cacheHitsNum)
          Sets number of queries performed on the cache successfully.
 void setMaxEntries(int max)
          Sets maximal number of objects in DODSHashMapCache (if the number is negative).
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

cacheAccessNum

protected int cacheAccessNum
Total number of times the cache was accessed.


cacheHitsNum

protected int cacheHitsNum
Number of queries performed on the cache successfully.

Method Detail

add

public java.lang.Object add(java.lang.Object key,
                            java.lang.Object value)
Adds a pair (key, value) to the cache. If key already exists, the method returns previous value asociated with this key. If maximum number of objects is achieved, the eldest entry will be removed and returned (this cache is unbounded, so the maximum number is never achieved).

Specified by:
add in interface DODSCache
Parameters:
key - Key asociated with the value.
value - Value that will be added to the cache.
Returns:
Previous value asociated with this key, if the key already exists, otherwise null.

getMaxEntries

public int getMaxEntries()
Returns maximal number of objects in DODSHashMapCache. Since this cache is always unbounded, the method always returns negative value.

Specified by:
getMaxEntries in interface DODSCache
Returns:
maximal number of objects in DODSHashMapCache.

setMaxEntries

public void setMaxEntries(int max)
Sets maximal number of objects in DODSHashMapCache (if the number is negative).

Specified by:
setMaxEntries in interface DODSCache
Parameters:
max - New value of maximal number of objects in DODSHashMapCache.

isNeedToSynchronize

public boolean isNeedToSynchronize()
Specified by:
isNeedToSynchronize in interface DODSCache

getCacheAccessNum

public int getCacheAccessNum()
Returns total number of times the cache was accessed.

Specified by:
getCacheAccessNum in interface CacheStatistics
Returns:
total number of times the cache was accessed.

setCacheAccessNum

public void setCacheAccessNum(int num)
Sets total number of times the cache was accessed.

Specified by:
setCacheAccessNum in interface CacheStatistics
Parameters:
num - Total number of times the cache was accessed.

incrementCacheAccessNum

public void incrementCacheAccessNum(int num)
Increases total number of times the cache was accessed.

Specified by:
incrementCacheAccessNum in interface CacheStatistics

getCacheHitsNum

public int getCacheHitsNum()
Returns number of queries performed on the cache successfully.

Specified by:
getCacheHitsNum in interface CacheStatistics
Returns:
Number of queries performed on the cache successfully.

setCacheHitsNum

public void setCacheHitsNum(int cacheHitsNum)
Sets number of queries performed on the cache successfully.

Specified by:
setCacheHitsNum in interface CacheStatistics
Parameters:
cacheHitsNum - Number of queries performed on the cache successfully.

incrementCacheHitsNum

public void incrementCacheHitsNum(int num)
Increases number of queries performed on the cache successfully for one.

Specified by:
incrementCacheHitsNum in interface CacheStatistics

getUsedPercents

public double getUsedPercents()
Returns how much cache is currently used. This value is given in percents. Since this cache is always unbounded, the method always returns 100%.

Specified by:
getUsedPercents in interface CacheStatistics
Returns:
Percents - how much cache is currently used.

getCacheHitsPercents

public double getCacheHitsPercents()
Returns how much queries performed on the cache were successful. This value is given in percents.

Specified by:
getCacheHitsPercents in interface CacheStatistics
Returns:
Percents - how much queries performed on the cache were successful.

clearStatistics

public void clearStatistics()
Clears statistics.

Specified by:
clearStatistics in interface CacheStatistics

DODS 7.3 API