Package org.ametys.site
Class CacheAccessManager
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.site.CacheAccessManager
-
- All Implemented Interfaces:
Initializable
,Component
,Contextualizable
,LogEnabled
,Serviceable
,ThreadSafe
public class CacheAccessManager extends AbstractLogEnabled implements Component, Initializable, Serviceable, Contextualizable, ThreadSafe
Component that regulates access to the page cache.
-
-
Field Summary
Fields Modifier and Type Field Description protected Context
_context
The cocoon context.protected ConcurrentMap<String,Boolean>
_pageCacheable
A Map keeping record of whether the pages are cacheable or not.protected ConcurrentMap<String,ReentrantLock>
_pageLocks
Map of page cache locks.protected BackOfficeRequestProxyExtensionPoint
_requestProxyExtensionPoint
The extension point for adding request headers in BO requeststatic String
ROLE
The avalon role.
-
Constructor Summary
Constructors Constructor Description CacheAccessManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_isCacheable(String pagePath)
Get the cacheable status of a page from the back-office.void
contextualize(Context context)
void
initialize()
boolean
isCacheable(String pagePath)
Tests if the page is cacheable.void
reset()
Resets all the local caches and locks.void
resetPage(String pagePath)
Remove a specified page path from the local cache and lock.void
service(ServiceManager serviceManager)
void
unlock(String pagePath)
Release the lock associated with a page.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
_pageCacheable
protected ConcurrentMap<String,Boolean> _pageCacheable
A Map keeping record of whether the pages are cacheable or not. The key is the page path, the value indicates if the page is cacheable.
-
_pageLocks
protected ConcurrentMap<String,ReentrantLock> _pageLocks
Map of page cache locks. The lock is acquired on the first call to the page, when the cache is empty, and released when the page is written into the cache.
-
_requestProxyExtensionPoint
protected BackOfficeRequestProxyExtensionPoint _requestProxyExtensionPoint
The extension point for adding request headers in BO request
-
-
Constructor Detail
-
CacheAccessManager
public CacheAccessManager()
-
-
Method Detail
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
isCacheable
public boolean isCacheable(String pagePath) throws IOException
Tests if the page is cacheable. If more than one thread call this method concurrently, only one tests the cacheability and (possibly) generates the corresponding resource. The concurrent threads are blocked until the page is known not to be cacheable, or known to be cacheable and put into the cache (inGeneratePageAction
).- Parameters:
pagePath
- the page path.- Returns:
- true if the page is cacheable, false otherwise.
- Throws:
IOException
- if an error occurs sending the cacheability request to the back-office.- See Also:
GeneratePageAction
-
unlock
public void unlock(String pagePath)
Release the lock associated with a page.- Parameters:
pagePath
- the page path.
-
reset
public void reset()
Resets all the local caches and locks.
-
resetPage
public void resetPage(String pagePath)
Remove a specified page path from the local cache and lock.- Parameters:
pagePath
- the page path.
-
_isCacheable
protected boolean _isCacheable(String pagePath) throws IOException
Get the cacheable status of a page from the back-office.- Parameters:
pagePath
- the page path.- Returns:
- true if the page is cacheable, false otherwise.
- Throws:
IOException
- in case of a problem or the connection was aborted
-
-