atg.commerce.endeca.cache
Class DimensionValueCacheTools

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.endeca.cache.DimensionValueCacheTools
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class DimensionValueCacheTools
extends GenericService

A tools class for the DimensionValueCache that contains useful and reusable methods. Some functionality must be synchronized as we use global cache components. There is one cache refresh lock per cache. When we synchronize on this object it means that different threads can execute on different caches simultaneously, however two threads cannot modify the same cache at the same time.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String DATA_DATE
          Attribute that indicates last baseline index time
static java.lang.String DEFAULT_CACHE_NAME
          Default cache name
static java.lang.String NUM_GENERATIONS
          Attribute that indicates number of partial updates
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
DimensionValueCacheTools()
           
 
Method Summary
 atg.commerce.endeca.cache.DimensionValueCache createEmptyCache()
          Creates an empty DimensionValueCache.
 void fillEmptyCache()
          Method to populate an empty cache.
 java.util.List<DimensionValueCacheObject> get(java.lang.String pRepositoryId)
          Get the dimension values that map to the repository item whose id is passed in.
protected  java.util.List<DimensionValueCacheObject> get(java.lang.String pRepositoryId, boolean pRefresh)
          Get an object from the cache.
 DimensionValueCacheObject get(java.lang.String pRepositoryId, java.util.List<java.lang.String> pAncestorIds)
          Get a specific dimension value that maps to the repository item whose id is passed in.
 java.util.List getAncestorIds(java.lang.String pRepositoryId)
          A list of ancestor ids representing the default catalog path from the repository item whose id is passed in, to the catalogs root category.
 AssemblerApplicationConfiguration getAssemblerApplicationConfiguration()
           
 AssemblerTools getAssemblerTools()
           
 atg.commerce.endeca.cache.DimensionValueCache getCache()
          Uses the currentApplicationKey on the assemblerApplicationConfiguration component to return a DimensionValueCache that corresponds to the current context.
 DimensionValueCacheObject getCachedObjectForDimval(java.lang.String pDimvalId)
          Get the cached object for the passed in dimension value id.
protected  atg.commerce.endeca.cache.DimensionValueCache getCacheFromRequest(DynamoHttpServletRequest pRequest)
          Checks the current request for a saved cache.
 java.lang.String getCacheRefreshHandlerName()
           
protected  atg.commerce.endeca.cache.DimensionValueCacheTools.CacheRefreshLock getCacheRefreshLock(java.lang.String pApplicationKey)
          Returns the CacheRefeshLock from the mCacheRefreshLocks Map.
 CatalogTools getCatalogTools()
           
 long getCheckMDEXUpdatedEveryNRequests()
           
protected  DimensionValueCacheObject getEntryWithSpecificAncestors(java.lang.String pRepositoryId, java.util.List<java.lang.String> pAncestorIds)
          Iterates over the objects in pAllResults and looks for one that has the specified ancestors pAncestorIds.
protected  atg.commerce.endeca.cache.DimensionValueCacheTools.MdexStats getMDEXStats()
          data_date represents the time of index creation (i.e.
protected  java.lang.String getMDEXStatsURL()
           
 long getMinimumCacheRefreshIntervalSecs()
           
 java.lang.String getSavedRequestCachePath()
           
 boolean isCheckMDEXUpdated()
           
 java.lang.String printCacheMap()
          Prints the contents of all caches managed by this DimensionValueCacheTools component.
 void refreshCache()
          Refreshes the cache by making a call the cache refresh handler.
protected  void saveCacheInRequest(DynamoHttpServletRequest pRequest, atg.commerce.endeca.cache.DimensionValueCache pCache)
          Saves the resolved cache in the request
 void setAssemblerApplicationConfiguration(AssemblerApplicationConfiguration pAssemblerApplicationConfiguration)
           
 void setAssemblerTools(AssemblerTools pAssemblerTools)
           
 void setCacheRefreshHandlerName(java.lang.String pCacheRefreshHandlerName)
           
 void setCatalogTools(CatalogTools pCatalogTools)
           
 void setCheckMDEXUpdated(boolean pCheckMDEXUpdated)
           
 void setCheckMDEXUpdatedEveryNRequests(long pCheckMDEXUpdatedEveryNRequests)
           
 void setMinimumCacheRefreshIntervalSecs(long pMinimumCacheRefreshIntervalSecs)
           
 void setSavedRequestCachePath(java.lang.String pSavedRequestCachePath)
           
 void swapCache(atg.commerce.endeca.cache.DimensionValueCache pOfflineCache)
          Swap in the offline cache map entry to the live one and remove the entry from the offline map.
protected  long timeSinceLastUpdateSecs(long pLastCacheUpdate)
          Number of seconds since the last cache update
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


DEFAULT_CACHE_NAME

public static final java.lang.String DEFAULT_CACHE_NAME
Default cache name

See Also:
Constant Field Values

DATA_DATE

public static final java.lang.String DATA_DATE
Attribute that indicates last baseline index time

See Also:
Constant Field Values

NUM_GENERATIONS

public static final java.lang.String NUM_GENERATIONS
Attribute that indicates number of partial updates

See Also:
Constant Field Values
Constructor Detail

DimensionValueCacheTools

public DimensionValueCacheTools()
Method Detail

getAssemblerTools

public AssemblerTools getAssemblerTools()
Returns:
the mAssemblerTools bean containing useful methods for use with the Assembler.

setAssemblerTools

public void setAssemblerTools(AssemblerTools pAssemblerTools)
Parameters:
mAssemblerTools - the mAssemblerTools to set

getCatalogTools

public CatalogTools getCatalogTools()
Returns:
the mCatalogTools

setCatalogTools

public void setCatalogTools(CatalogTools pCatalogTools)
Parameters:
mCatalogTools - the mCatalogTools to set

getCacheRefreshHandlerName

public java.lang.String getCacheRefreshHandlerName()
Returns:
the mCacheRefreshHandlerName. The name of a cartridge handler used to refresh the dimension value cache.

setCacheRefreshHandlerName

public void setCacheRefreshHandlerName(java.lang.String pCacheRefreshHandlerName)
Parameters:
mCacheRefreshHandlerName - the mCacheRefreshHandlerName to set

getMinimumCacheRefreshIntervalSecs

public long getMinimumCacheRefreshIntervalSecs()
Returns:
the mMinimumCacheRefreshIntervalSecs. The minimum time in seconds that must pass before refreshing the cache. This stops us bombarding the MDEX. Defaults to 600 seconds.

setMinimumCacheRefreshIntervalSecs

public void setMinimumCacheRefreshIntervalSecs(long pMinimumCacheRefreshIntervalSecs)
Parameters:
mMinimumCacheRefreshIntervalSecs - the mMinimumCacheRefreshIntervalSecs to set.

getAssemblerApplicationConfiguration

public AssemblerApplicationConfiguration getAssemblerApplicationConfiguration()
Returns:
the assemblerApplicationConfiguration

setAssemblerApplicationConfiguration

public void setAssemblerApplicationConfiguration(AssemblerApplicationConfiguration pAssemblerApplicationConfiguration)
Parameters:
assemblerApplicationConfiguration - the assemblerApplicationConfiguration to set

isCheckMDEXUpdated

public boolean isCheckMDEXUpdated()
Returns:
A boolean indicating whether or not we should check if the MDEX has been updated since the last cache refresh.

setCheckMDEXUpdated

public void setCheckMDEXUpdated(boolean pCheckMDEXUpdated)
Parameters:
pCheckMDEXUpdated - Set a new checkMDEXUpdated boolean that controls whether we should check and see if the MDEX has been updated since the last cache refresh.

getCheckMDEXUpdatedEveryNRequests

public long getCheckMDEXUpdatedEveryNRequests()
Returns:
The number of requests that must occur before we check if the MDEX and cache are out of date. This involved contacting the MDEX for a index details so may impact performance. Defaults to 100.

setCheckMDEXUpdatedEveryNRequests

public void setCheckMDEXUpdatedEveryNRequests(long pCheckMDEXUpdatedEveryNRequests)
Parameters:
pCheckMDEXUpdatedEveryNCacheRequests - Set the number of cache requests before we compare the timestamp on the MDEX to that on the cache.

getSavedRequestCachePath

public java.lang.String getSavedRequestCachePath()
Returns:
The cache for this request will be stored as an attribute in the request with this key.

setSavedRequestCachePath

public void setSavedRequestCachePath(java.lang.String pSavedRequestCachePath)
Parameters:
pSavedRequestCachePath - Set a new savedRequestCachePath.

getCache

public atg.commerce.endeca.cache.DimensionValueCache getCache()
Uses the currentApplicationKey on the assemblerApplicationConfiguration component to return a DimensionValueCache that corresponds to the current context.

Returns:
A DimensionValueCache.

getAncestorIds

public java.util.List getAncestorIds(java.lang.String pRepositoryId)
A list of ancestor ids representing the default catalog path from the repository item whose id is passed in, to the catalogs root category. The item whose repository id is passed in is not included in the returned list.

Returns:
A list of ancestor ids representing the catalog default path from the repository id item to the catalog root category.

getCachedObjectForDimval

public DimensionValueCacheObject getCachedObjectForDimval(java.lang.String pDimvalId)
Get the cached object for the passed in dimension value id. If this object does not exist in the cache a cache refresh will occur if the time since the last refresh has exceeded the value for the minimum time between cache refreshes.

Parameters:
pDimvalId - A dimension value id.
Returns:
The cache entry corresponding to this dimension value id.

get

public java.util.List<DimensionValueCacheObject> get(java.lang.String pRepositoryId)
Get the dimension values that map to the repository item whose id is passed in. If the passed in ID does not exist in the cache a cache refresh will occur if the minimum time since the last refresh has been exceeded, a refresh of this cache is not currently in progress and the MDEX has been updated since the last successful refresh (if checkMDEXUpdated is true).

Parameters:
pRepositoryId - A repository id
Returns:
A cache value

get

protected java.util.List<DimensionValueCacheObject> get(java.lang.String pRepositoryId,
                                                        boolean pRefresh)
Get an object from the cache. If it doesn't exist we perform an optional refresh.

Parameters:
pRepositoryId - The item to get from that cache with this repository id.
pRefresh - If the item does not exist we perform an option refresh and try to retrieve it again.
Returns:

get

public DimensionValueCacheObject get(java.lang.String pRepositoryId,
                                     java.util.List<java.lang.String> pAncestorIds)
Get a specific dimension value that maps to the repository item whose id is passed in. The ancestor ids this repository item must also be passed in as some repository items (such as categories) can be multi-parented.

Parameters:
pRepositoryId - A repository id
pAncestorIds - A list of ancestor ids. Can be null or empty to indicate a top level parent item.
Returns:
A DimensionValueCacheObject that corresponds to this repository id

getEntryWithSpecificAncestors

protected DimensionValueCacheObject getEntryWithSpecificAncestors(java.lang.String pRepositoryId,
                                                                  java.util.List<java.lang.String> pAncestorIds)
Iterates over the objects in pAllResults and looks for one that has the specified ancestors pAncestorIds.

Parameters:
pRepositoryId -
pAncestorIds -
pAllObjects -
Returns:

refreshCache

public void refreshCache()
Refreshes the cache by making a call the cache refresh handler. The cache refresh handler makes a call to the MDEX to retrieve a list of dimension values (such as those that represent categories) and adds these to the cache.


swapCache

public void swapCache(atg.commerce.endeca.cache.DimensionValueCache pOfflineCache)
Swap in the offline cache map entry to the live one and remove the entry from the offline map. The cache key is determined from the assemblerApplicationConfiguration beans currentApplicationKey property.

Parameters:
pOfflineCache - The cache that will go live.

fillEmptyCache

public void fillEmptyCache()
Method to populate an empty cache. The cache key is determined from the assemblerApplicationConfiguration beans currentApplicationKey property.


createEmptyCache

public atg.commerce.endeca.cache.DimensionValueCache createEmptyCache()
Creates an empty DimensionValueCache.

Returns:
An Empty DimensionValueCache.

getCacheRefreshLock

protected atg.commerce.endeca.cache.DimensionValueCacheTools.CacheRefreshLock getCacheRefreshLock(java.lang.String pApplicationKey)
Returns the CacheRefeshLock from the mCacheRefreshLocks Map. If a CacheRefreshLock does not exist for the current application key we create one.

Parameters:
pApplicationKey -
Returns:

printCacheMap

public java.lang.String printCacheMap()
Prints the contents of all caches managed by this DimensionValueCacheTools component.

Returns:
A formatted string representing the contents of the caches managed by this class.

timeSinceLastUpdateSecs

protected long timeSinceLastUpdateSecs(long pLastCacheUpdate)
Number of seconds since the last cache update

Parameters:
pLastCacheUpdate -
Returns:

getMDEXStatsURL

protected java.lang.String getMDEXStatsURL()
Returns:
URL to query for the MDEX statistics page

getMDEXStats

protected atg.commerce.endeca.cache.DimensionValueCacheTools.MdexStats getMDEXStats()
data_date represents the time of index creation (i.e. the time of baseline indexing). num_generations represents the number of partial updates since a baseline data_date = Date (of format EEE MMM d HH:mm:ss yyyy) num_generations = String

Returns:
An Object containing data from the MDEX stats page

getCacheFromRequest

protected atg.commerce.endeca.cache.DimensionValueCache getCacheFromRequest(DynamoHttpServletRequest pRequest)
Checks the current request for a saved cache.

Returns:

saveCacheInRequest

protected void saveCacheInRequest(DynamoHttpServletRequest pRequest,
                                  atg.commerce.endeca.cache.DimensionValueCache pCache)
Saves the resolved cache in the request