Package org.alfresco.util.cache
Class AbstractAsynchronouslyRefreshedCache<T>
java.lang.Object
org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache<T>
- All Implemented Interfaces:
Callable<Void>
,AsynchronouslyRefreshedCache<T>
,RefreshableCache<T>
,RefreshableCacheListener
,TransactionListener
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.InitializingBean
public abstract class AbstractAsynchronouslyRefreshedCache<T>
extends Object
implements AsynchronouslyRefreshedCache<T>, RefreshableCacheListener, Callable<Void>, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, TransactionListener
The base implementation for an asynchronously refreshed cache.
Currently supports one value or a cache per key (such as tenant.) Implementors just need to provide buildCache(String key/tennnantId)
- Since:
- 4.1.3
- Author:
- Andy, mrogers MER 17/04/2014 Refactored to core and generalised tennancy
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked after transaction commit.void
void
Invoked after transaction rollback.void
beforeCommit
(boolean readOnly) Called before a transaction is committed.void
Invoked before transaction commit/rollback.void
protected abstract T
buildCache
(String key) Build the cache entry for the specific key.call()
void
Use the current thread to build and put a new version of the cache entry before returning.Get the cache.Get the cache idvoid
init()
boolean
isUpToDate
(String key) Determine if the cache is up to datevoid
onRefreshableCacheEvent
(RefreshableCacheEvent refreshableCacheEvent) Callback made when a cache refresh occursvoid
Refresh the cache asynchronously.void
register
(RefreshableCacheListener listener) Register to be informed when the cache is updated in the background.void
setBeanName
(String name) void
void
setThreadPoolExecutor
(ThreadPoolExecutor threadPoolExecutor) toString()
protected void
waitForBuild
(org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache.Refresh refresh)
-
Field Details
-
liveLock
-
live
-
-
Constructor Details
-
AbstractAsynchronouslyRefreshedCache
public AbstractAsynchronouslyRefreshedCache()
-
-
Method Details
-
register
Description copied from interface:RefreshableCache
Register to be informed when the cache is updated in the background. Note: it is up to the implementation to provide any transactional wrapping. Transactional wrapping is not required to invalidate a shared cache entry directly via a transactional cache- Specified by:
register
in interfaceRefreshableCache<T>
- Parameters:
listener
- RefreshableCacheListener
-
setThreadPoolExecutor
- Parameters:
threadPoolExecutor
- the threadPoolExecutor to set
-
setRegistry
- Parameters:
registry
- the registry to set
-
init
public void init() -
toString
-
get
Description copied from interface:RefreshableCache
Get the cache. If there is no cache value this call will block. If the underlying cache is being refreshed, the old cache value will be returned until the refresh is complete.- Specified by:
get
in interfaceRefreshableCache<T>
- Returns:
- T
-
forceInChangesForThisUncommittedTransaction
Use the current thread to build and put a new version of the cache entry before returning.- Parameters:
key
- the cache key
-
waitForBuild
protected void waitForBuild(org.alfresco.util.cache.AbstractAsynchronouslyRefreshedCache.Refresh refresh) -
refresh
Description copied from interface:RefreshableCache
Refresh the cache asynchronously.- Specified by:
refresh
in interfaceRefreshableCache<T>
-
onRefreshableCacheEvent
Description copied from interface:RefreshableCacheListener
Callback made when a cache refresh occurs- Specified by:
onRefreshableCacheEvent
in interfaceRefreshableCacheListener
- Parameters:
refreshableCacheEvent
- the cache event
-
isUpToDate
Description copied from interface:AsynchronouslyRefreshedCache
Determine if the cache is up to date- Specified by:
isUpToDate
in interfaceAsynchronouslyRefreshedCache<T>
- Parameters:
key
- tennant id- Returns:
- true if the cache is not currently refreshing itself
-
call
-
setBeanName
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
getCacheId
Description copied from interface:AsynchronouslyRefreshedCache
Get the cache id- Specified by:
getCacheId
in interfaceAsynchronouslyRefreshedCache<T>
- Specified by:
getCacheId
in interfaceRefreshableCacheListener
- Returns:
- the cache ID
-
buildCache
Build the cache entry for the specific key. This method is called in a thread-safe manner i.e. it is only ever called by a single thread.- Parameters:
key
-- Returns:
- new Cache instance
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
broadcastEvent
-
beforeCommit
public void beforeCommit(boolean readOnly) Description copied from interface:TransactionListener
Called before a transaction is committed.All transaction resources are still available.
- Specified by:
beforeCommit
in interfaceTransactionListener
- Parameters:
readOnly
- true if the transaction is read-only
-
beforeCompletion
public void beforeCompletion()Description copied from interface:TransactionListener
Invoked before transaction commit/rollback. Will be called afterTransactionListener.beforeCommit(boolean)
even ifTransactionListener.beforeCommit(boolean)
failed.All transaction resources are still available.
- Specified by:
beforeCompletion
in interfaceTransactionListener
-
afterCommit
public void afterCommit()Description copied from interface:TransactionListener
Invoked after transaction commit.Any exceptions generated here will only be logged and will have no effect on the state of the transaction.
Although all transaction resources are still available, this method should be used only for cleaning up resources after a commit has occured.
- Specified by:
afterCommit
in interfaceTransactionListener
-
afterRollback
public void afterRollback()Description copied from interface:TransactionListener
Invoked after transaction rollback.Any exceptions generated here will only be logged and will have no effect on the state of the transaction.
Although all transaction resources are still available, this method should be used only for cleaning up resources after a rollback has occured.
- Specified by:
afterRollback
in interfaceTransactionListener
-