DODS 6.5 API

org.enhydra.dods.cache
Class DataStructCacheImpl

java.lang.Object
  extended byorg.enhydra.dods.cache.ConfigurationAdministration
      extended byorg.enhydra.dods.cache.DataStructCache
          extended byorg.enhydra.dods.cache.DataStructCacheImpl

public class DataStructCacheImpl
extends DataStructCache

This class contains data and mechanisms needed for caching data objects (or DataStruct objects) by their OIDs and provides cache configuration and administration.

Version:
2.0 15.06.2003.
Author:
Tanja Jovanovic, Nenad Vico, Zorica Suvajdzin

Field Summary
protected  DODSCache cache
          LRU cache for storing data (or DataStruct) objects.
protected  CacheAdministration cacheAdministration
          cacheAdministration attribute handles configuration settings about data (or DataStruct) object cache.
protected  double cachePercentage
           
protected  boolean fullCachingOn
          This attribute is true if the cache is full, otherwise false.
protected  java.lang.String initialQueryCache
          Initial query statement.
protected  boolean multi
          This attribute contains information if multi databases are used.
protected  java.util.HashMap nonVisibleList
          List of objects that are unvisible in the cache at the moment.
protected  double reserveFactor
          Reserve factor used in in query caching.
protected  Statistics statistics
          Table and cache statictics.
protected  TableConfiguration tableConf
          TableConfiguration attribute handles configuration settings about table of this cache.
 
Constructor Summary
DataStructCacheImpl()
          Constructor().
DataStructCacheImpl(int maxCSize)
          Constructor(int).
 
Method Summary
 CoreDataStruct addDataStruct(CoreDataStruct newDS)
          Adds DataStruct object to the cache.
 void checkFull()
          Returns information if data object (or DataStruct object) cache if "full".
 CoreDataStruct deleteDataStruct(CoreDataStruct data)
          Deletes DataStruct object from the cache.
 CacheAdministration getCacheAdministration(int cacheType)
          Returns CacheAdministration for data (or DataStruct) object cache.
 java.util.Map getCacheContent()
          Returns cache (data or DataStruct) content.
 double getCachePercentage()
          Read cache configuration from application's configuration file.
 java.lang.String getCacheType()
          Returns data object (or DataStruct object) cache type.
 CoreDataStruct getDataStructByHandle(java.lang.String handle)
          Returns DataStruct object whose String representation of OID is parameter handle.
 int getInitialCacheFetchSize()
           
 int getInitialDSCacheSize()
           
 java.lang.String getInitialQueryCache()
          Returns initialQueryCache.
 int getLevelOfCaching()
          Returns caching level.
 double getReserveFactor()
          Returns reserveFactor.
 Statistics getStatistics()
          Returns statistics of used table and cache.
 TableConfiguration getTableConfiguration()
          Returns TableConfiguration.
protected  void init()
          Creates cacheAdministration object for data (or DataStruct) object cache.
 boolean isDisabled()
          Returns information whether the cache is disabled.
 boolean isFull()
          Returns information if data object (or DataStruct object) cache if "full".
 boolean isMulti()
          Returns information if multi databases are supported.
 void makeInvisible(java.lang.String cacheHandle)
           
 void makeVisible(java.lang.String cacheHandle)
           
 DataStructCache newInstance()
          Creates DataStructCacheImpl instance.
 void readConfiguration(com.lutris.util.Config tableConfig, com.lutris.util.Config cacheConfig, java.lang.String dbName)
          Reads table and cache configuration from application's configuration file.
 void refreshStatistics()
          Refreshes statistics.
 CoreDataStruct removeDataStruct(CoreDataStruct data)
          Removes DataStruct object from the cache.
 CoreDataStruct removeDataStruct(java.lang.String handle)
          Removes DataStruct object from the cache.
protected  void setCachePercentage(double percent)
           
 void setInitialCacheFetchSize(int i)
           
 void setInitialDSCacheSize(int i)
           
protected  void setInitialQueryCache(java.lang.String initQ)
          Sets initialQueryCache attribute.
protected  void setReserveFactor(double res)
          Sets reserveFactor.
 void show()
          Shows content of this class.
 boolean toReconfigure()
          Checks wheather cache reconfiguration needs to be done.
 java.lang.String toString()
          Shows content of this class.
 CoreDataStruct updateDataStruct(CoreDataStruct data)
          Updates cached DataStruct object, or inserts it in the cache if it didn't exist in the cache.
 
Methods inherited from class org.enhydra.dods.cache.DataStructCache
isLocked
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cache

protected DODSCache cache
LRU cache for storing data (or DataStruct) objects. LRU cache keys are cache handles (String "."), and LRU cache values are data (or DataStruct) objects.


cacheAdministration

protected CacheAdministration cacheAdministration
cacheAdministration attribute handles configuration settings about data (or DataStruct) object cache.


tableConf

protected TableConfiguration tableConf
TableConfiguration attribute handles configuration settings about table of this cache.


initialQueryCache

protected java.lang.String initialQueryCache
Initial query statement. This attribute contains "where" clause which is used during data (or DataStruct) object cache initialization. If this attribute is set to "*", all rows from the table (in database) will be put in the cache.


multi

protected boolean multi
This attribute contains information if multi databases are used.


fullCachingOn

protected boolean fullCachingOn
This attribute is true if the cache is full, otherwise false.


statistics

protected Statistics statistics
Table and cache statictics.


nonVisibleList

protected java.util.HashMap nonVisibleList
List of objects that are unvisible in the cache at the moment. Keys of this map sre cache handles (String "."), and values are counters of how many transactions have made object with that cache handle invisible.


reserveFactor

protected double reserveFactor
Reserve factor used in in query caching. Since there is only data object (or DataStruct object) cache, without query caches, this parameter is not used.


cachePercentage

protected double cachePercentage
Constructor Detail

DataStructCacheImpl

public DataStructCacheImpl(int maxCSize)
                    throws CacheObjectException
Constructor(int). Creates data (or DataStruct) object cache with maximal size maxCSize.

Parameters:
maxCSize - maximal data (or DataStruct) object cache size.

DataStructCacheImpl

public DataStructCacheImpl()
                    throws CacheObjectException
Constructor(). Creates data (or DataStruct) object cache with its default maximal size (the value of CacheConstants.DEFAULT_MAX_CACHE_SIZE is 10000).

Method Detail

getCacheAdministration

public CacheAdministration getCacheAdministration(int cacheType)
Returns CacheAdministration for data (or DataStruct) object cache. Parameter cacheType can have one of these values: 0 - for CacheAdministration of data (or DataStruct) object cache 1 - for CacheAdministration of simple query cache 2 - for CacheAdministration of complex query cache There is only one cache (data (or DataStruct) object), so there is only one CacheAdministration. This method always returns this CacheAdministration, no matter what value does parameter cacheType have.

Specified by:
getCacheAdministration in class ConfigurationAdministration
Parameters:
cacheType - Type of caching. In this case, it is 0, but, since there is only one cache (data (or DataStruct) object), parameter is not checked, always is the same CacheAdministration object returned.
Returns:
CacheAdministration for data (or DataStruct) object cache.

getInitialQueryCache

public java.lang.String getInitialQueryCache()
Returns initialQueryCache. This attribute contains "where" clause which is used during data object (or DataStruct object) cache initialization.

Specified by:
getInitialQueryCache in class ConfigurationAdministration
Returns:
initialQueryCache.

setInitialQueryCache

protected void setInitialQueryCache(java.lang.String initQ)
Sets initialQueryCache attribute. This attribute contains "where" clause which is used during data object (or DataStruct object) cache initialization.

Specified by:
setInitialQueryCache in class ConfigurationAdministration
Parameters:
initQ - New value of initialQueryCache attribute.

makeInvisible

public void makeInvisible(java.lang.String cacheHandle)

makeVisible

public void makeVisible(java.lang.String cacheHandle)

getStatistics

public Statistics getStatistics()
Returns statistics of used table and cache.

Specified by:
getStatistics in class ConfigurationAdministration
Returns:
statistics of used table and cache.

refreshStatistics

public void refreshStatistics()
Refreshes statistics.

Specified by:
refreshStatistics in class ConfigurationAdministration

checkFull

public void checkFull()
Returns information if data object (or DataStruct object) cache if "full". "Full" cache contains all data objects (or DataStruct objects) from the table. The cache is "full", if data (or DataStruct) object cache is unbounded, if the cached table is read-only, and if initialQueryCache attribute is set to "*".

Specified by:
checkFull in class ConfigurationAdministration
Returns:
true if data object (or DataStruct object) cache if "full", otherwise false.

isFull

public boolean isFull()
Returns information if data object (or DataStruct object) cache if "full". "Full" cache contains all data objects (or DataStruct objects) from the table. The cache is "full", if data (or DataStruct) object cache is unbounded, and if initialQueryCache attribute is set to "*".

Specified by:
isFull in class ConfigurationAdministration
Returns:
true if data object (or DataStruct object) cache if "full", otherwise false.

getCacheType

public java.lang.String getCacheType()
Returns data object (or DataStruct object) cache type. Possible values are: "none" - no caching available "lru" - cache with LRU (least-recently used) algorithm "full" - special case of LRU cache - the whole table is cached

Specified by:
getCacheType in class ConfigurationAdministration
Returns:
data object (or DataStruct object) cache type.

getLevelOfCaching

public int getLevelOfCaching()
Returns caching level. Possible values: org.enhydra.dods.cache.CacheConstants.DATA_CACHING (value 1) for data (or DataStruct) object caching without query caching, and org.enhydra.dods.cache.CacheConstants.QUERY_CACHING (value 2) for data (or DataStruct) object caching with query caching. This is data (or DataStruct) object cache without query caching, so this method returns CacheConstants.DATA_CACHING (value 1).

Specified by:
getLevelOfCaching in class ConfigurationAdministration
Returns:
value 1 (org.enhydra.dods.cache.CacheConstants.DATA_CACHING).

getTableConfiguration

public TableConfiguration getTableConfiguration()
Returns TableConfiguration.

Specified by:
getTableConfiguration in class ConfigurationAdministration
Returns:
TableConfiguration attribute.

getReserveFactor

public double getReserveFactor()
Returns reserveFactor. Reserve factor used in in query caching. Since there is only data object (or DataStruct object) cache, without query caches, this method returns 0.

Specified by:
getReserveFactor in class ConfigurationAdministration
Returns:
value 0.

setReserveFactor

protected void setReserveFactor(double res)
Sets reserveFactor. Reserve factor used in in query caching. Since there is only data object (or DataStruct object) cache, without query caches, this method does not do anything.

Specified by:
setReserveFactor in class ConfigurationAdministration
Parameters:
res - New reserveFactor.

setCachePercentage

protected void setCachePercentage(double percent)
Specified by:
setCachePercentage in class ConfigurationAdministration

getCachePercentage

public double getCachePercentage()
Description copied from class: ConfigurationAdministration
Read cache configuration from application's configuration file.

Specified by:
getCachePercentage in class ConfigurationAdministration

isDisabled

public boolean isDisabled()
Returns information whether the cache is disabled.

Specified by:
isDisabled in class ConfigurationAdministration
Returns:
true is the cache is disabled, otherwise false.

readConfiguration

public void readConfiguration(com.lutris.util.Config tableConfig,
                              com.lutris.util.Config cacheConfig,
                              java.lang.String dbName)
                       throws CacheObjectException
Reads table and cache configuration from application's configuration file.

Specified by:
readConfiguration in class ConfigurationAdministration
Parameters:
tableConfig - configuration for table of this cache.
cacheConfig - configuration for this cache.
Throws:
CacheObjectException

newInstance

public DataStructCache newInstance()
                            throws CacheObjectException
Creates DataStructCacheImpl instance.

Specified by:
newInstance in class DataStructCache
Returns:
created DataStructCacheImpl instance as DataStructCache.
Throws:
CacheObjectException

init

protected void init()
Creates cacheAdministration object for data (or DataStruct) object cache.


getCacheContent

public java.util.Map getCacheContent()
Returns cache (data or DataStruct) content.

Specified by:
getCacheContent in class DataStructCache
Returns:
Cache content as Map of data (or DataStruct) object.

isMulti

public boolean isMulti()
Returns information if multi databases are supported.

Specified by:
isMulti in class DataStructCache
Returns:
true if multi databases are used, otherwise false.

toReconfigure

public boolean toReconfigure()
Checks wheather cache reconfiguration needs to be done.

Specified by:
toReconfigure in class DataStructCache
Returns:
true if cache reconfiguration needs to be done, otherwise false.

addDataStruct

public CoreDataStruct addDataStruct(CoreDataStruct newDS)
Adds DataStruct object to the cache.

Specified by:
addDataStruct in class DataStructCache
Parameters:
newDS - DataStruct object that will be added to the cache.
Returns:
Added DataStruct object.

removeDataStruct

public CoreDataStruct removeDataStruct(CoreDataStruct data)
Removes DataStruct object from the cache.

Specified by:
removeDataStruct in class DataStructCache
Parameters:
data - DataStruct object that will be removed from the cache.
Returns:
Removed DataStruct object, or null if there was no object removed from the cache.

removeDataStruct

public CoreDataStruct removeDataStruct(java.lang.String handle)
Removes DataStruct object from the cache.

Specified by:
removeDataStruct in class DataStructCache
Parameters:
handle - Cache handle of DataStruct object that will be removed from the cache. The form of cache handle is: ".".
Returns:
Removed DataStruct object, or null if there was no object removed from the cache.

updateDataStruct

public CoreDataStruct updateDataStruct(CoreDataStruct data)
Updates cached DataStruct object, or inserts it in the cache if it didn't exist in the cache.

Specified by:
updateDataStruct in class DataStructCache
Parameters:
data - DataStruct object that will be updated (or inserted if didn't exist in the cache).
Returns:
Updated or inserted DataStruct object.

deleteDataStruct

public CoreDataStruct deleteDataStruct(CoreDataStruct data)
Deletes DataStruct object from the cache.

Specified by:
deleteDataStruct in class DataStructCache
Parameters:
data - DataStruct object that will be deleted from the cache.
Returns:
Deleted DataStruct object, or null if there was no object deleted from the cache.

getDataStructByHandle

public CoreDataStruct getDataStructByHandle(java.lang.String handle)
Returns DataStruct object whose String representation of OID is parameter handle.

Specified by:
getDataStructByHandle in class DataStructCache
Parameters:
handle - String representation of OID of DataStruct object that is being searched in the cache.
Returns:
DataStruct object whose String representation of OID is handle.

show

public void show()
Shows content of this class. Can be used for debugging.


toString

public java.lang.String toString()
Shows content of this class. Can be used for debugging.


getInitialCacheFetchSize

public int getInitialCacheFetchSize()
Specified by:
getInitialCacheFetchSize in class ConfigurationAdministration
Returns:

getInitialDSCacheSize

public int getInitialDSCacheSize()
Specified by:
getInitialDSCacheSize in class ConfigurationAdministration
Returns:

setInitialCacheFetchSize

public void setInitialCacheFetchSize(int i)
Specified by:
setInitialCacheFetchSize in class ConfigurationAdministration
Parameters:
i -

setInitialDSCacheSize

public void setInitialDSCacheSize(int i)
Specified by:
setInitialDSCacheSize in class ConfigurationAdministration
Parameters:
i -

DODS 6.5 API