IMC Epclient 5.0.3

at.spardat.enterprise.cache
Class TransparentCacheDescriptor

java.lang.Object
  extended byat.spardat.enterprise.cache.ICacheDescriptor
      extended byat.spardat.enterprise.cache.TransparentCacheDescriptor

public abstract class TransparentCacheDescriptor
extends ICacheDescriptor

Describes a transparent cache. That is a cache, which is able to load objects on its own. Actually this is done by calling the load-method in this descriptor, which must be overwritten by an application specific subclass.

In order to create a transparent cache, first create a subclass-instance of TransparentCacheDescripor and register this object with the CacheManager.


Field Summary
 
Fields inherited from class at.spardat.enterprise.cache.ICacheDescriptor
MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND
 
Constructor Summary
TransparentCacheDescriptor(java.lang.String name, int maxSize, int maxAgeMillis)
          Defines the properties of a transparent cache.
 
Method Summary
 long getMaxAgeMillis()
          Returns the maximum time in milliseconds a cache entry should be accessible in the chache.
 int getMaxAgeSpreadPct()
          If the value provided by this method is not zero, the time a cache entry resides in the cache before it is beeing evicted is spread to a percentage around getMaxAgeMillis().
 int getMaxSize()
          Returns the maximum number of cached entries in the described cache.
 java.lang.String getName()
          Returns the name of the described cache.
 boolean isTransparent()
          Returns true if the described cache is a transparent cache, which can load objects by the load method of this descriptor
abstract  java.lang.Object load(java.lang.Object key)
          This is the load method of a transparent cache.
 void setMaxAgeSpreadPct(int pct)
          Sets the spread of cache entry duration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransparentCacheDescriptor

public TransparentCacheDescriptor(java.lang.String name,
                                  int maxSize,
                                  int maxAgeMillis)
Defines the properties of a transparent cache.

Parameters:
name - the name of the cache
maxSize - maximum number of entries in the cache. If less equal zero, the cache has unlimited size.
maxAgeMillis - the time in milliseconds denoting how long a entry may reside in the cache before beeing evicted. If less equal zero, there is no age limitation. If greater than zero, this value must not be less than 1000.
Throws:
java.lang.IllegalArgumentException - if maxAgeMillis greater than zero and less than 1000.
Method Detail

getName

public java.lang.String getName()
Description copied from class: ICacheDescriptor
Returns the name of the described cache.

Specified by:
getName in class ICacheDescriptor
See Also:
ICacheDescriptor.getName()

isTransparent

public boolean isTransparent()
Description copied from class: ICacheDescriptor
Returns true if the described cache is a transparent cache, which can load objects by the load method of this descriptor

Specified by:
isTransparent in class ICacheDescriptor
See Also:
ICacheDescriptor.isTransparent()

load

public abstract java.lang.Object load(java.lang.Object key)
Description copied from class: ICacheDescriptor
This is the load method of a transparent cache. If the cache user calls lookup and the key isn't in the cache, this method is called to get the cacheable object for the key.

This method may be called in parallel from many threads. You must not access instance variables in this method.

Specified by:
load in class ICacheDescriptor
Parameters:
key - the key for which a value should be loaded.
Returns:
the loaded object. Must not be null. If there are exceptions in the course of the load procedure, you must throw a RuntimeException.
See Also:
ICacheDescriptor.load(Object)

getMaxAgeMillis

public long getMaxAgeMillis()
Description copied from class: ICacheDescriptor
Returns the maximum time in milliseconds a cache entry should be accessible in the chache. If this value is less than or equal to zero, there is no age limitation.

Specified by:
getMaxAgeMillis in class ICacheDescriptor
See Also:
ICacheDescriptor.getMaxAgeMillis()

getMaxSize

public int getMaxSize()
Description copied from class: ICacheDescriptor
Returns the maximum number of cached entries in the described cache. If this value is less than or equal to zero, the described cache does not have a size limitation.

Specified by:
getMaxSize in class ICacheDescriptor
See Also:
ICacheDescriptor.getMaxSize()

getMaxAgeSpreadPct

public int getMaxAgeSpreadPct()
Description copied from class: ICacheDescriptor
If the value provided by this method is not zero, the time a cache entry resides in the cache before it is beeing evicted is spread to a percentage around getMaxAgeMillis(). Suppose, getMaxAgeMillis() provides 3600000 (one hour). Then a getMaxAgeSpreadPct-value of 10 percent denotes that the actual validity-duration of an entry is randomly choosen in the range [3600000-360000 ... 360000+360000]. Or more readable, the duration is equally distributed between 54 and 66 minutes.

The default implementation of this method is no spread at all.

Overrides:
getMaxAgeSpreadPct in class ICacheDescriptor
Returns:
Spread in percents.
See Also:
ICacheDescriptor.getMaxAgeSpreadPct()

setMaxAgeSpreadPct

public void setMaxAgeSpreadPct(int pct)
Sets the spread of cache entry duration.

See Also:
ICacheDescriptor.getMaxAgeSpreadPct()

IMC Epclient 5.0.3