lumis.portal.page.cache
Class PageCacheManager

Package class diagram package PageCacheManager
java.lang.Object
  extended by lumis.portal.page.cache.PageCacheManager
All Implemented Interfaces:
IPageCacheManager

public class PageCacheManager
extends Object
implements IPageCacheManager

Manager for page cache information.

Since:
4.0.0

Nested Class Summary
protected static class PageCacheManager.HttpAccessResult
          Structure used to hold the result of doHttpAccess(URL, String).
 
Nested classes/interfaces inherited from interface lumis.portal.page.cache.IPageCacheManager
IPageCacheManager.GenerationOutcome
 
Field Summary
static String PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX
           
 
Fields inherited from interface lumis.portal.page.cache.IPageCacheManager
CLEAR_CACHE_CHANGE_TYPE_DELETE, CLEAR_CACHE_CHANGE_TYPE_UPDATE, PAGE_CACHE_GEN_STATE_DISABLED, PAGE_CACHE_GEN_STATE_ENABLED
 
Constructor Summary
PageCacheManager()
           
 
Method Summary
 String add(SessionConfig sessionConfig, PageCacheConfig pageCacheConfig, ITransaction transaction)
          Adds a Page Cache Config object.
 void addOrUpdate(SessionConfig sessionConfig, PageCacheConfig pageCacheConfig, ITransaction transaction)
          If the Page Cache Config exists, it is updated, else it is added.
 void clearAllHTMLCache(ITransaction transaction)
          Clears all page HTML cache.
 void clearCacheByChannelIds(SessionConfig sessionConfig, Collection<String> channelIds, Parameters parameters, int changeType, boolean clearImmediately, ITransaction transaction)
          Clear the cache of the pages within the specified channels recursively.
 void clearCacheByPagesIds(SessionConfig sessionConfig, Collection<String> pagesIds, Parameters parameters, int changeType, boolean clearImmediately, ITransaction transaction)
          Deprecated. 
 void clearCacheByPagesIds(SessionConfig sessionConfig, Collection<String> pagesIds, Parameters parameters, int changeType, ITransaction transaction)
          Deprecated. 
 void clearCacheByPagesIds(SessionConfig sessionConfig, Collection<String> pagesIds, Parameters parameters, Locale locale, int changeType, boolean clearImmediately, ITransaction transaction)
          Clear the cache of the specified pages.
 void clearCacheByServiceInterfaceInstances(SessionConfig sessionConfig, Collection<ServiceInterfaceInstanceConfig> serviceInterfaceInstances, Parameters parameters, int changeType, ITransaction transaction)
          Deprecated. 
 void clearCacheByServiceInterfaceInstancesIds(SessionConfig sessionConfig, Collection<String> serviceInterfaceInstanceIds, Parameters parameters, int changeType, ITransaction transaction)
          Deprecated. 
 String convertMainUrl(SessionConfig sessionConfig, String mainUrl, ITransaction transaction)
          Converts a url to main.jsp to a url to the cached page html url.
 void delete(SessionConfig sessionConfig, String pageCacheId, ITransaction transaction)
          Delete a page cache.
protected  PageCacheManager.HttpAccessResult doHttpAccess(URL url, String cookies)
           
 PageCacheConfig generateNextPage(boolean forImmediateUseOnly)
          Generates next outdated page cache, according to its priority.
protected  void generatePage(PageCacheConfig pageCacheConfig)
           
 PageCacheConfig generatePage(String pageCacheId)
          Generates a page cache.
 PageCacheConfig get(SessionConfig sessionConfig, String pageCacheId, ITransaction transaction)
          Returns a page cache config given its id.
 PageCacheConfig getByCachedPageProperties(SessionConfig sessionConfig, PageCacheConfig cachedPageProperties, ITransaction transaction)
          Given the url and language, this method returns the appropriate page cache config.
 String getCachedPageId(SessionConfig sessionConfig, PageCacheConfig pageCacheConfig)
          Get the Id of the Page's cache.
protected  PageCacheConfig getGenerationLock(String pageCacheId)
          Gets a lock for generating a cached page.
protected  PageCacheConfig getNextPageForGeneration(boolean forImmediateUseOnly)
          Returns the next page cache to be generated.
 int getPageCacheGenerationState(SessionConfig sessionConfig, ITransaction transaction)
          Returns whether page cache generation is enabled or not
 String getPageCacheRelativePath(PageConfig pageConfig, String cachedPageId)
          Returns the path, relative to the web application root, where a page cached HTML is stored.
 String getPageCacheRelativePath(String pageCacheId, ITransaction transaction)
          Returns the path, relative to the web application root, where a page cached HTML is stored.
 String getPageUrl(PageCacheConfig pageCacheConfig, ITransaction transaction)
          Get the Page's URL.
 void pageCacheMissed(String pageCacheId, boolean forImmediateUse)
          Indicates a miss in the page cache occurred.
 String parseHTMLContent(SessionConfig sessionConfig, String htmlContent, String cachedPageId, int cacheType, ITransaction transaction)
          Processes the HTML content correcting relative paths.
 String processHtmlReferencesToCachedPages(SessionConfig sessionConfig, String html, ITransaction transaction)
          Finds in the given html dynamic references to cached pages, adding PageCacheConfig when a proper one does not already exist.
protected  void releaseGenerationLock(PageCacheConfig pageCacheConfig, IPageCacheManager.GenerationOutcome outcome)
          Releases the generation lock for a cached page.
 void setPageCacheGenerationState(SessionConfig sessionConfig, int state, ITransaction transaction)
          Sets the page cache generation state.
 void update(SessionConfig sessionConfig, PageCacheConfig pageCacheConfig, ITransaction transaction)
          Updates a Page Cache Config Object.
 void updateCachedFilesLastModifiedDate(SessionConfig sessionConfig, PageConfig pageConfig, Locale locale, Date lastModifiedDate, ITransaction transaction)
          Updates the last modified date of the cached files that match the given pageId and locale.
 String waitForGeneration(String pageCacheId, long timeout)
          Waits for the generation of a page cache.
 void waitForPagesReadyToGenerate(long timeout, boolean forImmediateUseOnly)
          Waits for new pages to be ready to be generated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX

public static final String PAGE_CACHE_MANAGER_LANGUAGE_FILENAME_PREFIX
See Also:
Constant Field Values
Constructor Detail

PageCacheManager

public PageCacheManager()
Method Detail

waitForGeneration

public String waitForGeneration(String pageCacheId,
                                long timeout)
                         throws PortalException,
                                InterruptedException
Description copied from interface: IPageCacheManager
Waits for the generation of a page cache.

Specified by:
waitForGeneration in interface IPageCacheManager
Parameters:
pageCacheId - the page cache identifier.
timeout - maximum time to wait.
Returns:
the generated page content.
Throws:
InterruptedException - if the thread was interrupted.
PortalException

waitForPagesReadyToGenerate

public void waitForPagesReadyToGenerate(long timeout,
                                        boolean forImmediateUseOnly)
                                 throws InterruptedException
Description copied from interface: IPageCacheManager
Waits for new pages to be ready to be generated.

Specified by:
waitForPagesReadyToGenerate in interface IPageCacheManager
Parameters:
timeout - maximum time to wait.
forImmediateUseOnly - if true, wait until a page for immediate use is ready to generate. If false, wait until any page is ready to generate.
Throws:
InterruptedException - if the thread was interrupted.

doHttpAccess

protected PageCacheManager.HttpAccessResult doHttpAccess(URL url,
                                                         String cookies)
                                                  throws UnsupportedEncodingException,
                                                         IOException
Throws:
UnsupportedEncodingException
IOException

generatePage

protected void generatePage(PageCacheConfig pageCacheConfig)
                     throws ManagerException,
                            PortalException
Throws:
ManagerException
PortalException

generateNextPage

public PageCacheConfig generateNextPage(boolean forImmediateUseOnly)
                                 throws PortalException
Description copied from interface: IPageCacheManager
Generates next outdated page cache, according to its priority. If the generation lock could not be obtained, the page is not generated.

Specified by:
generateNextPage in interface IPageCacheManager
Parameters:
forImmediateUseOnly - if true, only pages whose priority is higher than PageCacheConfig.MAX_INITIAL_PRIORITY are taken in account.
Returns:
the generated page cache information, or null if the generation lock could not be obtained or if there is no outdated page (as specified in the parameters).
Throws:
PortalException

generatePage

public PageCacheConfig generatePage(String pageCacheId)
                             throws PortalException
Description copied from interface: IPageCacheManager
Generates a page cache. If the generation lock could not be obtained, the page is not generated.

Specified by:
generatePage in interface IPageCacheManager
Parameters:
pageCacheId - the page cache identifier.
Returns:
the generated page cache information, or null if the generation lock could not be obtained.
Throws:
PortalException

getPageCacheRelativePath

public String getPageCacheRelativePath(PageConfig pageConfig,
                                       String cachedPageId)
Description copied from interface: IPageCacheManager
Returns the path, relative to the web application root, where a page cached HTML is stored.

Specified by:
getPageCacheRelativePath in interface IPageCacheManager
Parameters:
pageConfig - the page that is cached.
Returns:
the cache file path, relative to the web application root.

getPageUrl

public String getPageUrl(PageCacheConfig pageCacheConfig,
                         ITransaction transaction)
                  throws ManagerException,
                         PortalException
Description copied from interface: IPageCacheManager
Get the Page's URL.

Specified by:
getPageUrl in interface IPageCacheManager
Returns:
a String.
Throws:
ManagerException
PortalException

getCachedPageId

public String getCachedPageId(SessionConfig sessionConfig,
                              PageCacheConfig pageCacheConfig)
                       throws ManagerException,
                              PortalException
Description copied from interface: IPageCacheManager
Get the Id of the Page's cache.

Specified by:
getCachedPageId in interface IPageCacheManager
Parameters:
sessionConfig - TODO
Returns:
a String.
Throws:
ManagerException
PortalException

addOrUpdate

public void addOrUpdate(SessionConfig sessionConfig,
                        PageCacheConfig pageCacheConfig,
                        ITransaction transaction)
                 throws ManagerException,
                        PortalException
Description copied from interface: IPageCacheManager
If the Page Cache Config exists, it is updated, else it is added.

Specified by:
addOrUpdate in interface IPageCacheManager
Throws:
ManagerException
PortalException

delete

public void delete(SessionConfig sessionConfig,
                   String pageCacheId,
                   ITransaction transaction)
            throws ManagerException,
                   PortalException
Description copied from interface: IPageCacheManager
Delete a page cache.

Specified by:
delete in interface IPageCacheManager
Throws:
ManagerException
PortalException

add

public String add(SessionConfig sessionConfig,
                  PageCacheConfig pageCacheConfig,
                  ITransaction transaction)
           throws ManagerException,
                  PortalException
Description copied from interface: IPageCacheManager
Adds a Page Cache Config object.

Specified by:
add in interface IPageCacheManager
Returns:
Throws:
ManagerException
PortalException

update

public void update(SessionConfig sessionConfig,
                   PageCacheConfig pageCacheConfig,
                   ITransaction transaction)
            throws ManagerException,
                   PortalException
Description copied from interface: IPageCacheManager
Updates a Page Cache Config Object.

Specified by:
update in interface IPageCacheManager
Throws:
ManagerException
PortalException

get

public PageCacheConfig get(SessionConfig sessionConfig,
                           String pageCacheId,
                           ITransaction transaction)
                    throws ManagerException,
                           PortalException
Description copied from interface: IPageCacheManager
Returns a page cache config given its id.

Specified by:
get in interface IPageCacheManager
Returns:
Throws:
ManagerException
PortalException

getByCachedPageProperties

public PageCacheConfig getByCachedPageProperties(SessionConfig sessionConfig,
                                                 PageCacheConfig cachedPageProperties,
                                                 ITransaction transaction)
                                          throws ManagerException,
                                                 PortalException
Description copied from interface: IPageCacheManager
Given the url and language, this method returns the appropriate page cache config.

If no config is found, a PortalObjectNotFound exception is thrown.

Specified by:
getByCachedPageProperties in interface IPageCacheManager
Returns:
Throws:
ManagerException
PortalException

parseHTMLContent

public String parseHTMLContent(SessionConfig sessionConfig,
                               String htmlContent,
                               String cachedPageId,
                               int cacheType,
                               ITransaction transaction)
                        throws PortalException
Description copied from interface: IPageCacheManager
Processes the HTML content correcting relative paths.

Specified by:
parseHTMLContent in interface IPageCacheManager
Returns:
Throws:
ManagerException
PortalException

clearCacheByServiceInterfaceInstancesIds

@Deprecated
public void clearCacheByServiceInterfaceInstancesIds(SessionConfig sessionConfig,
                                                                Collection<String> serviceInterfaceInstanceIds,
                                                                Parameters parameters,
                                                                int changeType,
                                                                ITransaction transaction)
                                              throws ManagerException,
                                                     PortalException
Deprecated. 

Description copied from interface: IPageCacheManager
Clear the cache given the Id of the Service's Interface's Instance.

Specified by:
clearCacheByServiceInterfaceInstancesIds in interface IPageCacheManager
Throws:
ManagerException
PortalException

clearCacheByServiceInterfaceInstances

@Deprecated
public void clearCacheByServiceInterfaceInstances(SessionConfig sessionConfig,
                                                             Collection<ServiceInterfaceInstanceConfig> serviceInterfaceInstances,
                                                             Parameters parameters,
                                                             int changeType,
                                                             ITransaction transaction)
                                           throws ManagerException,
                                                  PortalException
Deprecated. 

Description copied from interface: IPageCacheManager
Clear the page cache given a list Service Interface Instances.

Specified by:
clearCacheByServiceInterfaceInstances in interface IPageCacheManager
Throws:
ManagerException
PortalException

clearCacheByPagesIds

@Deprecated
public void clearCacheByPagesIds(SessionConfig sessionConfig,
                                            Collection<String> pagesIds,
                                            Parameters parameters,
                                            int changeType,
                                            ITransaction transaction)
                          throws PortalException
Deprecated. 

Description copied from interface: IPageCacheManager
Clear the cache given the Ids of the Pages.

Specified by:
clearCacheByPagesIds in interface IPageCacheManager
Throws:
ManagerException
PortalException

clearCacheByPagesIds

@Deprecated
public void clearCacheByPagesIds(SessionConfig sessionConfig,
                                            Collection<String> pagesIds,
                                            Parameters parameters,
                                            int changeType,
                                            boolean clearImmediately,
                                            ITransaction transaction)
                          throws PortalException
Deprecated. 

Description copied from interface: IPageCacheManager
Clear the cache of the specified pages. This method always clears the specified pages cache after the transaction commits. If clearImmediately is set to true, it will also clear the specified pages cache immediately, synchronously.

Specified by:
clearCacheByPagesIds in interface IPageCacheManager
Parameters:
sessionConfig - the user session information.
pagesIds - a collection of the pages identifiers.
parameters - the page parameters.
changeType - the cause of the cache clear. Must be one of the CLEAR_CACHE_CHANGE_TYPE_* constants.
clearImmediately - if the cache clearing is also to be executed immediately.
transaction - the transaction for persistence access.
Throws:
PortalException

clearCacheByPagesIds

public void clearCacheByPagesIds(SessionConfig sessionConfig,
                                 Collection<String> pagesIds,
                                 Parameters parameters,
                                 Locale locale,
                                 int changeType,
                                 boolean clearImmediately,
                                 ITransaction transaction)
                          throws PortalException
Description copied from interface: IPageCacheManager
Clear the cache of the specified pages. This method always clears the specified pages cache after the transaction commits. If clearImmediately is set to true, it will also clear the specified pages cache immediately, synchronously.

Specified by:
clearCacheByPagesIds in interface IPageCacheManager
Parameters:
sessionConfig - the user session information.
pagesIds - a collection of the pages identifiers.
parameters - the page parameters.
locale - specifies the locale to which the cache clearing is to be applied. May be null to indicate any locale.
changeType - the cause of the cache clear. Must be one of the CLEAR_CACHE_CHANGE_TYPE_* constants.
clearImmediately - if the cache clearing is also to be executed immediately.
transaction - the transaction for persistence access.
Throws:
PortalException

clearCacheByChannelIds

public void clearCacheByChannelIds(SessionConfig sessionConfig,
                                   Collection<String> channelIds,
                                   Parameters parameters,
                                   int changeType,
                                   boolean clearImmediately,
                                   ITransaction transaction)
                            throws PortalException
Description copied from interface: IPageCacheManager
Clear the cache of the pages within the specified channels recursively. This method always clears the specified pages cache after the transaction commits. If clearImmediately is set to true, it will also clear the specified pages cache immediately, synchronously.

Specified by:
clearCacheByChannelIds in interface IPageCacheManager
Parameters:
sessionConfig - the user session information.
parameters - the page parameters.
changeType - the cause of the cache clear. Must be one of the CLEAR_CACHE_CHANGE_TYPE_* constants.
clearImmediately - if the cache clearing is also to be executed immediately.
transaction - the transaction for persistence access.
Throws:
PortalException

getPageCacheGenerationState

public int getPageCacheGenerationState(SessionConfig sessionConfig,
                                       ITransaction transaction)
                                throws PortalException
Returns whether page cache generation is enabled or not

Specified by:
getPageCacheGenerationState in interface IPageCacheManager
Parameters:
sessionConfig -
transaction -
Returns:
Throws:
PortalException
Since:
4.0.11

setPageCacheGenerationState

public void setPageCacheGenerationState(SessionConfig sessionConfig,
                                        int state,
                                        ITransaction transaction)
                                 throws PortalException
Sets the page cache generation state.

The session provided must have MANAGE_CACHE permission at the portal level in order to execute this method successfully.

Specified by:
setPageCacheGenerationState in interface IPageCacheManager
Parameters:
sessionConfig -
state -
transaction -
Throws:
PortalException
Since:
4.0.11

getGenerationLock

protected PageCacheConfig getGenerationLock(String pageCacheId)
                                     throws PortalException
Gets a lock for generating a cached page.

To get a lock successfully, the page cache status must be PageCacheConfig.STATUS_OUTDATED.

If successful, the page cache status will be changed to PageCacheConfig.STATUS_GENERATING.

Parameters:
pageCacheId - the page cache identifier.
Returns:
the locked page cache, or null if it could not be locked for generation.
Throws:
PortalException

releaseGenerationLock

protected void releaseGenerationLock(PageCacheConfig pageCacheConfig,
                                     IPageCacheManager.GenerationOutcome outcome)
                              throws PortalException
Releases the generation lock for a cached page.

According to the outcome argument, the following happens:

Parameters:
pageCacheConfig - the page cache.
outcome - the generation outcome.
newStatus - the new status if the current status is generating.
Throws:
PortalException
Since:
4.1.0

updateCachedFilesLastModifiedDate

public void updateCachedFilesLastModifiedDate(SessionConfig sessionConfig,
                                              PageConfig pageConfig,
                                              Locale locale,
                                              Date lastModifiedDate,
                                              ITransaction transaction)
                                       throws PortalException
Description copied from interface: IPageCacheManager
Updates the last modified date of the cached files that match the given pageId and locale.

Specified by:
updateCachedFilesLastModifiedDate in interface IPageCacheManager
Parameters:
sessionConfig - the user session information.
pageConfig - the portal page.
locale - locale for which the cached files needs to be modified.
lastModifiedDate - date to which the matched files must be modified to.
transaction - the transaction for persistence access.
Throws:
PortalException

pageCacheMissed

public void pageCacheMissed(String pageCacheId,
                            boolean forImmediateUse)
                     throws PortalException
Description copied from interface: IPageCacheManager
Indicates a miss in the page cache occurred. This provokes an asynchronous page cache generation and causes an increase in its priority due to the interest in accessing it.

Specified by:
pageCacheMissed in interface IPageCacheManager
Parameters:
pageCacheId - the page cache identifier.
forImmediateUse - if true, indicates that the missed page cache is required for immediate use. This will greater boost the priority to generate the corresponding page cache.
Throws:
PortalException

getNextPageForGeneration

protected PageCacheConfig getNextPageForGeneration(boolean forImmediateUseOnly)
                                            throws PortalException
Returns the next page cache to be generated. It is locked for generation before being returned.

Parameters:
forImmediateUseOnly - if true, only pages whose priority is higher than PageCacheConfig.MAX_INITIAL_PRIORITY are taken in account.
Returns:
the next page cache to be generated, or null if no suitable page was found.
Throws:
PortalException
Since:
4.1.0
See Also:
#getGenerationLock(PageCacheConfig), #releaseGenerationLock(PageCacheConfig, int)

getPageCacheRelativePath

public String getPageCacheRelativePath(String pageCacheId,
                                       ITransaction transaction)
                                throws PortalException
Description copied from interface: IPageCacheManager
Returns the path, relative to the web application root, where a page cached HTML is stored.

This method may access the database. Consider using IPageCacheManager.getPageCacheRelativePath(PageConfig, String) for better performance if the corresponding PageConfig is already available.

Specified by:
getPageCacheRelativePath in interface IPageCacheManager
Parameters:
pageCacheId - the page cache identifier.
transaction - the transaction for persistence access.
Returns:
the cache file path, relative to the web application root.
Throws:
PortalException

processHtmlReferencesToCachedPages

public String processHtmlReferencesToCachedPages(SessionConfig sessionConfig,
                                                 String html,
                                                 ITransaction transaction)
                                          throws PortalException
Description copied from interface: IPageCacheManager
Finds in the given html dynamic references to cached pages, adding PageCacheConfig when a proper one does not already exist. The dynamic references are replaced by static references.

Specified by:
processHtmlReferencesToCachedPages in interface IPageCacheManager
Parameters:
sessionConfig - user session information.
html - the html.
transaction - transaction for persistence access.
Returns:
the html, with dynamic references replaced by static references.
Throws:
PortalException

convertMainUrl

public String convertMainUrl(SessionConfig sessionConfig,
                             String mainUrl,
                             ITransaction transaction)
                      throws PortalException
Converts a url to main.jsp to a url to the cached page html url. Creates the PageCacheConfig if necessary and appropriated.

Specified by:
convertMainUrl in interface IPageCacheManager
Parameters:
sessionConfig - the user session information.
mainUrl - the url to main.jsp. Must start with main.jsp.
transaction - the transaction for persistence access.
Returns:
the converted url, or the original url if a conversion is not appropriated (cache is disabled for that page, for example).
Throws:
PortalException
Since:
4.1.0

clearAllHTMLCache

public void clearAllHTMLCache(ITransaction transaction)
                       throws PortalException
Description copied from interface: IPageCacheManager
Clears all page HTML cache.

Specified by:
clearAllHTMLCache in interface IPageCacheManager
Parameters:
transaction - the transaction for persistence access.
Throws:
PortalException


Lumisportal  4.1.0.071221 - Copyright © 2001-2007, Lumis. All Rights Reserved.