mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Default page renderer site config now times out after 30 seconds
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6915 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -104,9 +104,12 @@ public class PageRendererServlet extends WebScriptServlet
|
|||||||
private static final String PARAM_COMPONENT_ID = "_alfId";
|
private static final String PARAM_COMPONENT_ID = "_alfId";
|
||||||
private static final String PARAM_COMPONENT_URL = "_alfUrl";
|
private static final String PARAM_COMPONENT_URL = "_alfUrl";
|
||||||
|
|
||||||
|
// timeout to reload default page cache from
|
||||||
|
private static final int DEFAULT_PAGE_CONFIG_CACHE_TIMEOUT = 30000;
|
||||||
|
|
||||||
private PageTemplateProcessor templateProcessor;
|
private PageTemplateProcessor templateProcessor;
|
||||||
private WebScriptTemplateLoader webscriptTemplateLoader;
|
private WebScriptTemplateLoader webscriptTemplateLoader;
|
||||||
private Map<String, PageDefinition> defaultPageDefCache = null;
|
private Map<String, ExpiringValueCache<PageDefinition>> defaultPageDefMap = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
@@ -129,7 +132,7 @@ public class PageRendererServlet extends WebScriptServlet
|
|||||||
configService = (ConfigService)context.getBean("pagerenderer.config");
|
configService = (ConfigService)context.getBean("pagerenderer.config");
|
||||||
|
|
||||||
// create cache for default config
|
// create cache for default config
|
||||||
defaultPageDefCache = Collections.synchronizedMap(new HashMap<String, PageDefinition>());
|
defaultPageDefMap = Collections.synchronizedMap(new HashMap<String, ExpiringValueCache<PageDefinition>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -274,14 +277,19 @@ public class PageRendererServlet extends WebScriptServlet
|
|||||||
private PageDefinition lookupPageDefinition(String store, String contextPath, String page)
|
private PageDefinition lookupPageDefinition(String store, String contextPath, String page)
|
||||||
{
|
{
|
||||||
// Lookup (and cache) config for default page-definition file in root
|
// Lookup (and cache) config for default page-definition file in root
|
||||||
PageDefinition defaultPageDef = defaultPageDefCache.get(store);
|
ExpiringValueCache<PageDefinition> cache = defaultPageDefMap.get(store);
|
||||||
// TODO: check last modified date (use auto-timeout cache object!)
|
if (cache == null)
|
||||||
|
{
|
||||||
|
cache = new ExpiringValueCache<PageDefinition>(DEFAULT_PAGE_CONFIG_CACHE_TIMEOUT);
|
||||||
|
defaultPageDefMap.put(store, cache);
|
||||||
|
}
|
||||||
|
PageDefinition defaultPageDef = cache.get();
|
||||||
if (defaultPageDef == null)
|
if (defaultPageDef == null)
|
||||||
{
|
{
|
||||||
// read default config for the site and cache the result
|
// read default config for the site and cache the result
|
||||||
String defaultConfigPath = getPageDefinitionPath(null, store, contextPath);
|
String defaultConfigPath = getPageDefinitionPath(null, store, contextPath);
|
||||||
defaultPageDef = readPageDefinitionConfig(defaultConfigPath, page, null);
|
defaultPageDef = readPageDefinitionConfig(defaultConfigPath, page, null);
|
||||||
defaultPageDefCache.put(store, defaultPageDef);
|
cache.put(defaultPageDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup page xml config in AVM store using page name as location
|
// Lookup page xml config in AVM store using page name as location
|
||||||
@@ -796,7 +804,7 @@ public class PageRendererServlet extends WebScriptServlet
|
|||||||
/**
|
/**
|
||||||
* Helper to return context path for generating urls
|
* Helper to return context path for generating urls
|
||||||
*/
|
*/
|
||||||
public static class URLHelper
|
private static class URLHelper
|
||||||
{
|
{
|
||||||
String context;
|
String context;
|
||||||
|
|
||||||
@@ -860,4 +868,58 @@ public class PageRendererServlet extends WebScriptServlet
|
|||||||
return "Component: " + Id + " URL: " + Url + " Properties: " + Properties.toString();
|
return "Component: " + Id + " URL: " + Url + " Properties: " + Properties.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to automatically expire a cached value after a timeout
|
||||||
|
*/
|
||||||
|
private static class ExpiringValueCache<T>
|
||||||
|
{
|
||||||
|
private long timeout;
|
||||||
|
private long snapshot = 0;
|
||||||
|
private T value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param timeout Timeout in milliseconds before cached value is discarded
|
||||||
|
*/
|
||||||
|
public ExpiringValueCache(long timeout)
|
||||||
|
{
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put a value into the cache. The item will be return from the associated get() method
|
||||||
|
* until the timeout expires then null will be returned.
|
||||||
|
*
|
||||||
|
* @param value The object to store in the cache
|
||||||
|
*/
|
||||||
|
public void put(T value)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
this.snapshot = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cached object. The set item will be returned until it expires, then null will be returned.
|
||||||
|
*
|
||||||
|
* @return cached object or null if not set or expired.
|
||||||
|
*/
|
||||||
|
public T get()
|
||||||
|
{
|
||||||
|
if (snapshot + timeout < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
this.value = null;
|
||||||
|
}
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cache value
|
||||||
|
*/
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
this.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user