cmailleux    2005/02/24 14:24:21 CET

  Modified files:        (Branch: JAHIA-4-1-BRANCH)
    src/java/org/jahia/engines/addcontainer 
                                            AddContainer_Engine.java 
    src/java/org/jahia/engines/containerlistproperties 
                                                       
ContainerListProperties_Engine.java 
    src/java/org/jahia/engines/deletecontainer 
                                               DeleteContainer_Engine.java 
    src/java/org/jahia/engines/pages PageProperties_Engine.java 
    src/java/org/jahia/engines/updatecontainer 
                                               UpdateContainer_Engine.java 
    src/java/org/jahia/engines/updatefield UpdateField_Engine.java 
    src/java/org/jahia/engines/workflow WorkflowEngine.java 
    src/java/org/jahia/operations OperationManager.java 
    src/java/org/jahia/params ParamBean.java 
    src/java/org/jahia/services/cache Cache.java HtmlCache.java 
  Log:
  Queueing of page in operation Manager

  Modification of cache to flush entry by workflow state

  Merge with branch 4-0
  
  Revision       Changes    Path
  1.69.2.3.2.3   +2 -2      
jahia/src/java/org/jahia/engines/addcontainer/AddContainer_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/addcontainer/AddContainer_Engine.java.diff?r1=1.69.2.3.2.2&r2=1.69.2.3.2.3&f=h
  1.41.4.1.2.1   +2 -2      
jahia/src/java/org/jahia/engines/containerlistproperties/ContainerListProperties_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/containerlistproperties/ContainerListProperties_Engine.java.diff?r1=1.41.4.1&r2=1.41.4.1.2.1&f=h
  1.31.4.1.2.1   +3 -4      
jahia/src/java/org/jahia/engines/deletecontainer/DeleteContainer_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/deletecontainer/DeleteContainer_Engine.java.diff?r1=1.31.4.1&r2=1.31.4.1.2.1&f=h
  1.48.2.9.2.1   +2 -2      
jahia/src/java/org/jahia/engines/pages/PageProperties_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/pages/PageProperties_Engine.java.diff?r1=1.48.2.9&r2=1.48.2.9.2.1&f=h
  1.62.4.3.2.3   +4 -4      
jahia/src/java/org/jahia/engines/updatecontainer/UpdateContainer_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/updatecontainer/UpdateContainer_Engine.java.diff?r1=1.62.4.3.2.2&r2=1.62.4.3.2.3&f=h
  1.48.4.1.2.1   +2 -2      
jahia/src/java/org/jahia/engines/updatefield/UpdateField_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/updatefield/UpdateField_Engine.java.diff?r1=1.48.4.1&r2=1.48.4.1.2.1&f=h
  1.47.2.6.2.1   +2 -2      
jahia/src/java/org/jahia/engines/workflow/WorkflowEngine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/workflow/WorkflowEngine.java.diff?r1=1.47.2.6&r2=1.47.2.6.2.1&f=h
  1.34.2.2.2.1   +152 -114  
jahia/src/java/org/jahia/operations/OperationManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/operations/OperationManager.java.diff?r1=1.34.2.2&r2=1.34.2.2.2.1&f=h
  1.149.2.9.2.2  +8 -4      jahia/src/java/org/jahia/params/ParamBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/params/ParamBean.java.diff?r1=1.149.2.9.2.1&r2=1.149.2.9.2.2&f=h
  1.30.2.8.2.1   +4 -2      jahia/src/java/org/jahia/services/cache/Cache.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/cache/Cache.java.diff?r1=1.30.2.8&r2=1.30.2.8.2.1&f=h
  1.13.2.1.2.1   +29 -0     
jahia/src/java/org/jahia/services/cache/HtmlCache.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/cache/HtmlCache.java.diff?r1=1.13.2.1&r2=1.13.2.1.2.1&f=h
  
  
  
  Index: AddContainer_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/addcontainer/Attic/AddContainer_Engine.java,v
  retrieving revision 1.69.2.3.2.2
  retrieving revision 1.69.2.3.2.3
  diff -u -r1.69.2.3.2.2 -r1.69.2.3.2.3
  --- AddContainer_Engine.java  23 Feb 2005 10:02:40 -0000      1.69.2.3.2.2
  +++ AddContainer_Engine.java  24 Feb 2005 13:24:17 -0000      1.69.2.3.2.3
  @@ -610,7 +610,7 @@
                   while (pageRefIDs.hasNext ()) {
                       Integer curPageID = (Integer) pageRefIDs.next ();
                       if (htmlCache != null) {
  -                        htmlCache.invalidatePageEntries (curPageID.toString 
());
  +                        htmlCache.invalidatePageEntries (curPageID.toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
                       }
                   }
               } else {
  @@ -624,7 +624,7 @@
           // and the containerList is not referenced in an absolute way.
           if (htmlCache != null) {
               htmlCache.invalidatePageEntries (
  -                    Integer.toString (jParams.getPageID ()).toString ());
  +                    Integer.toString (jParams.getPageID ()).toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
           }
       }
   
  
  
  
  Index: ContainerListProperties_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/containerlistproperties/Attic/ContainerListProperties_Engine.java,v
  retrieving revision 1.41.4.1
  retrieving revision 1.41.4.1.2.1
  diff -u -r1.41.4.1 -r1.41.4.1.2.1
  --- ContainerListProperties_Engine.java       6 Aug 2004 17:59:37 -0000       
1.41.4.1
  +++ ContainerListProperties_Engine.java       24 Feb 2005 13:24:17 -0000      
1.41.4.1.2.1
  @@ -491,7 +491,7 @@
                   while (pageRefIDs.hasNext ()) {
                       Integer curPageID = (Integer) pageRefIDs.next ();
                       if (htmlCache != null)
  -                        htmlCache.invalidatePageEntries (curPageID.toString 
());
  +                        htmlCache.invalidatePageEntries (curPageID.toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
                   }
               } else {
                   logger.debug ("Why is cross ref list empty ?");
  @@ -503,7 +503,7 @@
           // since we updated properties on this container list, let's flush
           // the cache for the page this container list is on...
           if (htmlCache != null)
  -            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID ()));
  +            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID ()),jParams.getEntryLoadRequest().getWorkflowState());
       }
   
       /**
  
  
  
  Index: DeleteContainer_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/deletecontainer/Attic/DeleteContainer_Engine.java,v
  retrieving revision 1.31.4.1
  retrieving revision 1.31.4.1.2.1
  diff -u -r1.31.4.1 -r1.31.4.1.2.1
  --- DeleteContainer_Engine.java       6 Aug 2004 17:59:37 -0000       1.31.4.1
  +++ DeleteContainer_Engine.java       24 Feb 2005 13:24:18 -0000      
1.31.4.1.2.1
  @@ -312,8 +312,7 @@
                       Integer curPageID = (Integer) pageRefIDs.next ();
   
                       if (htmlCache != null)
  -                        htmlCache.invalidatePageEntries (curPageID.
  -                                toString ());
  +                        htmlCache.invalidatePageEntries (curPageID.toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
                   }
               } else {
                   logger.debug ("Why is cross ref list empty ?");
  @@ -325,8 +324,8 @@
           // since we have made modifications concerning this page, let's flush
           // the content cache for all the users and browsers...
           if (htmlCache != null)
  -            htmlCache.invalidatePageEntries (Integer.toString (jParams.
  -                    getPageID ()).toString ());
  +            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID()).toString(),
  +                                             
jParams.getEntryLoadRequest().getWorkflowState());
       }
   
       /**
  
  
  
  Index: PageProperties_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/pages/Attic/PageProperties_Engine.java,v
  retrieving revision 1.48.2.9
  retrieving revision 1.48.2.9.2.1
  diff -u -r1.48.2.9 -r1.48.2.9.2.1
  --- PageProperties_Engine.java        8 Dec 2004 13:27:22 -0000       1.48.2.9
  +++ PageProperties_Engine.java        24 Feb 2005 13:24:18 -0000      
1.48.2.9.2.1
  @@ -1,4 +1,4 @@
  -// $Id: PageProperties_Engine.java,v 1.48.2.9 2004/12/08 13:27:22 shuber Exp 
$
  +// $Id: PageProperties_Engine.java,v 1.48.2.9.2.1 2005/02/24 13:24:18 
cmailleux Exp $
   //
   //
   //                                   ____.
  @@ -931,7 +931,7 @@
                   LockKey lockKey = LockKey.composeLockKey 
(LockKey.UPDATE_PAGE_TYPE,
                                                             curPageID, 
curPageID);
                   lockRegistry.release (lockKey, jParams.getUser (), 
jParams.getSessionID ());
  -                htmlCache.invalidatePageEntries(Integer.toString(curPageID));
  +                
htmlCache.invalidatePageEntries(Integer.toString(curPageID),jParams.getEntryLoadRequest().getWorkflowState());
               }
           }
       }
  
  
  
  Index: UpdateContainer_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/updatecontainer/Attic/UpdateContainer_Engine.java,v
  retrieving revision 1.62.4.3.2.2
  retrieving revision 1.62.4.3.2.3
  diff -u -r1.62.4.3.2.2 -r1.62.4.3.2.3
  --- UpdateContainer_Engine.java       23 Feb 2005 10:02:40 -0000      
1.62.4.3.2.2
  +++ UpdateContainer_Engine.java       24 Feb 2005 13:24:18 -0000      
1.62.4.3.2.3
  @@ -1,4 +1,4 @@
  -// $Id: UpdateContainer_Engine.java,v 1.62.4.3.2.2 2005/02/23 10:02:40 
cmailleux Exp $
  +// $Id: UpdateContainer_Engine.java,v 1.62.4.3.2.3 2005/02/24 13:24:18 
cmailleux Exp $
   //
   //
   //                                   ____.
  @@ -641,7 +641,7 @@
               while (pageRefIDs.hasNext ()) {
                   Integer curPageID = (Integer) pageRefIDs.next ();
                   if (htmlCache != null)
  -                    htmlCache.invalidatePageEntries (curPageID.toString ());
  +                    htmlCache.invalidatePageEntries (curPageID.toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
               }
           } else {
               logger.debug ("Why is cross ref list empty ?");
  @@ -649,8 +649,8 @@
           // this is still necessary in the case we are on the page itself
           // and the containerList is not referenced in an absolute way.
           if (htmlCache != null)
  -            htmlCache.invalidatePageEntries (Integer.toString (jParams.
  -                    getPageID ()));
  +            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID ()),
  +                                             
jParams.getEntryLoadRequest().getWorkflowState());
       }
   
       /**
  
  
  
  Index: UpdateField_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/updatefield/Attic/UpdateField_Engine.java,v
  retrieving revision 1.48.4.1
  retrieving revision 1.48.4.1.2.1
  diff -u -r1.48.4.1 -r1.48.4.1.2.1
  --- UpdateField_Engine.java   6 Aug 2004 17:59:41 -0000       1.48.4.1
  +++ UpdateField_Engine.java   24 Feb 2005 13:24:19 -0000      1.48.4.1.2.1
  @@ -498,7 +498,7 @@
                   Integer curPageID = (Integer) pageRefIDs.next ();
   
                   if (htmlCache != null)
  -                    htmlCache.invalidatePageEntries (curPageID.toString ());
  +                    htmlCache.invalidatePageEntries (curPageID.toString 
(),jParams.getEntryLoadRequest().getWorkflowState());
               }
           } else {
               logger.debug ("Why is cross ref list empty ?");
  @@ -507,7 +507,7 @@
           // since we have made modifications concerning this page, let's flush
           // the content cache for all the users and browsers...
           if (htmlCache != null)
  -            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID ()));
  +            htmlCache.invalidatePageEntries (Integer.toString 
(jParams.getPageID ()),jParams.getEntryLoadRequest().getWorkflowState());
       }
   
       /**
  
  
  
  Index: WorkflowEngine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/engines/workflow/Attic/WorkflowEngine.java,v
  retrieving revision 1.47.2.6
  retrieving revision 1.47.2.6.2.1
  diff -u -r1.47.2.6 -r1.47.2.6.2.1
  --- WorkflowEngine.java       7 Oct 2004 17:27:20 -0000       1.47.2.6
  +++ WorkflowEngine.java       24 Feb 2005 13:24:19 -0000      1.47.2.6.2.1
  @@ -244,7 +244,7 @@
                                   siteMapContentPage.getID (), 
siteMapContentPage.getID ());
                           if (lockRegistry.acquire (lockKey, user, 
jParams.getSessionID (),
                                   jParams.getSession ().getMaxInactiveInterval 
())) {
  -                            
htmlCache.invalidatePageEntries(Integer.toString(siteMapContentPage.getID()));
  +                            
htmlCache.invalidatePageEntries(Integer.toString(siteMapContentPage.getID()),jParams.getEntryLoadRequest().getWorkflowState());
                               logger.debug (
                                       "Lock acquired for page " +
                                       siteMapContentPage.getTitles (true));
  @@ -771,7 +771,7 @@
                       LockKey lockKey = LockKey.composeLockKey 
(LockKey.WORKFLOW_TYPE,
                               siteMapContentPage.getID (), 
siteMapContentPage.getID ());
                       lockRegistry.release (lockKey, jParams.getUser (), 
jParams.getSessionID ());
  -                    
htmlCache.invalidatePageEntries(Integer.toString(siteMapContentPage.getID()));
  +                    
htmlCache.invalidatePageEntries(Integer.toString(siteMapContentPage.getID()),jParams.getEntryLoadRequest().getWorkflowState());
                   }
               }
           }
  
  
  
  Index: OperationManager.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/operations/Attic/OperationManager.java,v
  retrieving revision 1.34.2.2
  retrieving revision 1.34.2.2.2.1
  diff -u -r1.34.2.2 -r1.34.2.2.2.1
  --- OperationManager.java     28 Jul 2004 15:27:24 -0000      1.34.2.2
  +++ OperationManager.java     24 Feb 2005 13:24:19 -0000      1.34.2.2.2.1
  @@ -16,10 +16,7 @@
   package org.jahia.operations;
   
   import java.io.OutputStreamWriter;
  -import java.util.ArrayList;
  -import java.util.Date;
  -import java.util.Hashtable;
  -import java.util.Locale;
  +import java.util.*;
   
   import javax.servlet.ServletContext;
   import javax.servlet.ServletOutputStream;
  @@ -39,6 +36,9 @@
   import org.jahia.services.cache.CacheEntry;
   import org.jahia.settings.SettingsBean;
   import org.jahia.utils.LanguageCodeConverters;
  +import org.apache.commons.collections.FastHashMap;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
   
   /**
    * This class is responsible for dispatching to an engine. In the special
  @@ -52,14 +52,17 @@
    * @author Eric Vassalli
    * @author Serge Huber
    * @author Fulco Houkes
  - *
  + * @author Cédric Mailleux
    * @version 3.1
    */
   public class OperationManager {
   
       private static org.apache.log4j.Logger logger =
               org.apache.log4j.Logger.getLogger (OperationManager.class);
  -
  +    // Map containing the entry key of the currently generating page
  +    private static Map generatingPage = new FastHashMap(3);
  +    // Map containing the entry of the generated page
  +    private static Map generatedPage = new FastHashMap(2503);
       /** Default constructor, creates a new <code>OperationManager</code> 
object instance
        */
       public OperationManager () {
  @@ -81,16 +84,14 @@
        * @throws org.jahia.exceptions.JahiaForbiddenAccessException
        *      when the user has not access to the requested operation
        */
  -    public void handleOperations ( ParamBean jParams,
  -                                  SettingsBean jSettings)
  -        throws  JahiaException,
  -                JahiaSessionExpirationException,
  -                JahiaForbiddenAccessException
  -    {
  +    public void handleOperations(ParamBean jParams,
  +                                 SettingsBean jSettings)
  +            throws JahiaException,
  +                   JahiaSessionExpirationException,
  +                   JahiaForbiddenAccessException {
           JahiaData jData = null;
           // Get the language code
           String curLanguageCode = 
LanguageCodeConverters.localeToLanguageTag(jParams.getLocale());
  -
           // extract the workflow state out of the parameters bean
           int workflowState = jParams.getEntryLoadRequest().getWorkflowState();
   
  @@ -104,62 +105,71 @@
               ServletContext context = jParams.getContext();
               if (context != null) {
                   try {
  -                    
jParams.getRequest().setAttribute("Jahia_ParamBean",jParams);
  -                    
context.getRequestDispatcher("/jsp/jahia/errors/site_not_found.jsp" ).forward(
  -                            jParams.getRequest(), jParams.getResponse() );
  -                } catch (Throwable t ){
  -                    logger.error (t);
  -                    throw new JahiaException ("400 Page Not Found: No site 
specified",
  -                            "The requested site not found" ,
  -                            JahiaException.SECURITY_ERROR,
  -                            JahiaException.ERROR_SEVERITY);
  +                    jParams.getRequest().setAttribute("Jahia_ParamBean", 
jParams);
  +                    
context.getRequestDispatcher("/jsp/jahia/errors/site_not_found.jsp").forward(jParams.getRequest(),
 jParams.getResponse());
  +                } catch (Throwable t) {
  +                    logger.error(t);
  +                    throw new JahiaException("400 Page Not Found: No site 
specified",
  +                                             "The requested site not found",
  +                                             JahiaException.SECURITY_ERROR,
  +                                             JahiaException.ERROR_SEVERITY);
                   }
                   return;
               } else {
  -                throw new JahiaException ("400 Page Not Found:",
  -                        "Context is null" ,
  -                        JahiaException.SECURITY_ERROR,
  -                        JahiaException.ERROR_SEVERITY);
  +                throw new JahiaException("400 Page Not Found:",
  +                                         "Context is null",
  +                                         JahiaException.SECURITY_ERROR,
  +                                         JahiaException.ERROR_SEVERITY);
               }
           }
   
           // Get the engine instance (can throw a JahiaException)
           String engineName = jParams.getEngine();
  -        JahiaEngine theEngine = getEngineInstance (engineName);
  -
  +        JahiaEngine theEngine = getEngineInstance(engineName);
  +        String entryKey = 
htmlCache.computeEntryKey(Integer.toString(jParams.getPageID()),
  +                                                    
jParams.getUser().getUsername(),
  +                                                    curLanguageCode,
  +                                                    workflowState,
  +                                                    jParams.getUserAgent());
  +        // boolean which indicate if we have to generate the page of we must 
wait for the cache to be generated
  +        boolean haveToBeenGenerate = false;
  +        // forec generation of page if this one is not cacheable
  +        boolean iscacheable = false;
           if (theEngine != null) {
   
  -            if ( "core".equals(jParams.getEngine()) ){
  -                if ( jParams.getPage() == null &&
  -                     ( jParams.getOperationMode().equals(ParamBean.EDIT)
  -                     || 
jParams.getOperationMode().equals(ParamBean.COMPARE)) ){
  +            if ("core".equals(jParams.getEngine())) {
  +                if(logger.isDebugEnabled()) {
  +                    
logger.debug(ToStringBuilder.reflectionToString(htmlCache,ToStringStyle.MULTI_LINE_STYLE));
  +                }
  +                if (jParams.getPage() == null &&
  +                    (jParams.getOperationMode().equals(ParamBean.EDIT)
  +                     || 
jParams.getOperationMode().equals(ParamBean.COMPARE))) {
                       // try to switch to NORMAL Mode
                       // force to recompute all locales be removing session 
locale
  -                    // and switching to NOMAL MODE
  +                    // and switching to NORMAL MODE
                       
jParams.getSession().removeAttribute(ParamBean.SESSION_LOCALE);
                       jParams.flushLocaleListCache();
                       ArrayList locales = jParams.getLocales(true);
                       Hashtable pageTitles = 
jParams.getContentPage().getTitles(true);
                       Locale locale = null;
                       String lang = null;
  -                    for ( int i=0 ; i<locales.size(); i++ ){
  -                        locale = (Locale)locales.get(i);
  -                        if ( pageTitles.containsKey(locale.toString()) ){
  +                    for (int i = 0; i < locales.size(); i++) {
  +                        locale = (Locale) locales.get(i);
  +                        if (pageTitles.containsKey(locale.toString())) {
                               lang = locale.toString();
                               break;
                           }
                       }
   
  -                    if ( lang != null ){
  -                        
jParams.getSession().setAttribute(ParamBean.SESSION_LOCALE,locale);
  +                    if (lang != null) {
  +                        
jParams.getSession().setAttribute(ParamBean.SESSION_LOCALE, locale);
                           jParams.setUser(jParams.getUser());
                           jParams.changePage(jParams.getContentPage());
                       }
                   }
               }
  -
               // logger.debug("Engine=" + engineName);
  -            if (theEngine.needsJahiaData (jParams)) {
  +            if (theEngine.needsJahiaData(jParams)) {
   
                   // logger.debug("Engine need JahiaData");
   
  @@ -168,13 +178,13 @@
                   // the current page, so we let the user display the engine!
                   // if no read access -> launch exception
   
  -                if ( jParams.getPage() != null && 
!jParams.getPage().checkReadAccess (jParams.getUser())) {
  -                    throw new JahiaException ("403 Forbidden - Page:"+ 
jParams.getPageID(),
  -                                "No read access for page " + 
jParams.getPageID() +
  -                                " user=" + jParams.getUser().getUsername() +
  -                                " acl=" + jParams.getPage().getAclID(),
  -                                JahiaException.SECURITY_ERROR,
  -                                JahiaException.ERROR_SEVERITY);
  +                if (jParams.getPage() != null && 
!jParams.getPage().checkReadAccess(jParams.getUser())) {
  +                    throw new JahiaException("403 Forbidden - Page:" + 
jParams.getPageID(),
  +                                             "No read access for page " + 
jParams.getPageID() +
  +                                             " user=" + 
jParams.getUser().getUsername() +
  +                                             " acl=" + 
jParams.getPage().getAclID(),
  +                                             JahiaException.SECURITY_ERROR,
  +                                             JahiaException.ERROR_SEVERITY);
                   }
   
                   if 
(jParams.settings().lookupBoolean(SettingsBean.OUTPUT_CACHE_ACTIVATED)) {
  @@ -184,31 +194,23 @@
                        *  restrict it for now. We might be interested in doing 
more
                        *  work here in order to cache more often.
                        */
  -                    if ( ("core".equals(jParams.getEngine())) &&
  -                         (jParams.getHttpMethod() == ParamBean.GET_METHOD) &&
  -                         
(ParamBean.CACHE_ON.equals(jParams.getCacheStatus()))
  -                       )
  -                    {
  +                    if (("core".equals(jParams.getEngine())) &&
  +                        (jParams.getHttpMethod() == ParamBean.GET_METHOD) &&
  +                        (ParamBean.CACHE_ON.equals(jParams.getCacheStatus()))
  +                    ) {
                           // logger.debug("Requested page is : " + 
jParams.getPageID() );
   
  -                        String entryKey = htmlCache.computeEntryKey(
  -                                Integer.toString (jParams.getPageID ()),
  -                                jParams.getUser().getUsername(),
  -                                curLanguageCode,
  -                                workflowState,
  -                                jParams.getUserAgent ());
  -
                           CacheEntry cacheEntry = 
htmlCache.getCacheEntry(entryKey);
  -
  +                        // This page is cacheable
  +                        iscacheable = true;
                           if (cacheEntry != null) {
   //                            logger.debug ("Found HTML page in 
cache!!!!!!!!!!!!!!!!!!");
  -                            HtmlCacheEntry htmlEntry = 
(HtmlCacheEntry)cacheEntry.getObject();
  +                            HtmlCacheEntry htmlEntry = (HtmlCacheEntry) 
cacheEntry.getObject();
                               String htmlContent = htmlEntry.getContentBody();
  -
                               if 
(!cacheEntry.getOperationMode().equals(jParams.getOperationMode())) {
                                   logger.debug("Cache entry mode is NOT equal 
to current mode, flushing page entry and generating page...");
  -                                htmlCache.remove (entryKey);
  -
  +                                htmlCache.remove(entryKey);
  +                                generatedPage.remove(entryKey);
                               } else {
                                   if (htmlContent != null) {
                                       logger.debug("Found content in cache, 
writing directly bypassing processing...");
  @@ -225,77 +227,102 @@
                                           if (contentType != null) {
                                               int charsetPos = 
contentType.toLowerCase().indexOf("charset=");
                                               if (charsetPos != -1) {
  -                                                String encoding = 
contentType.substring(charsetPos + "charset=".length()).toUpperCase();
  +                                                String encoding = 
contentType.substring(charsetPos +
  +                                                                             
           "charset=".length()).toUpperCase();
                                                   logger.debug("Using 
streamWriter with encoding : " + encoding);
                                                   streamWriter = new
  -                                                    OutputStreamWriter 
(outputStream, encoding);
  +                                                        
OutputStreamWriter(outputStream, encoding);
                                               }
                                           }
                                           streamWriter.write(htmlContent, 0, 
htmlContent.length());
                                           streamWriter.flush();
                                       } catch (java.io.IOException ioe) {
  -                                        logger.error( "Error writing cache 
output, IOException generated error", ioe);
  -                                        throw new JahiaException 
("OperationsManager.handleOperations",
  -                                                    "Error writing cache 
content to writer",
  -                                                    
JahiaException.SECURITY_ERROR,
  -                                                    
JahiaException.ERROR_SEVERITY, ioe);
  +                                        logger.error("Error writing cache 
output, IOException generated error", ioe);
  +                                        throw new 
JahiaException("OperationsManager.handleOperations",
  +                                                                 "Error 
writing cache content to writer",
  +                                                                 
JahiaException.SECURITY_ERROR,
  +                                                                 
JahiaException.ERROR_SEVERITY, ioe);
                                       }
                                       return; // exit handling here !
                                   }
                               }
                           } else {
  -                            logger.debug ("!!!!!! Could not find HTML page 
in cache!!!!!!!!!!!!!!!!!!");
  +//                            logger.debug("!!!!!! Could not find HTML page 
in cache!!!!!!!!!!!!!!!!!!");
  +                            generatedPage.remove(entryKey);
                           }
                       }
  -
  -                    if ( 
(ParamBean.CACHE_OFFONCE.equals(jParams.getCacheStatus())) ||
  -                         
(ParamBean.CACHE_BYPASS.equals(jParams.getCacheStatus())) ||
  -                         
(ParamBean.CACHE_ONLYUPDATE.equals(jParams.getCacheStatus()))
  -                       ) {
  +                    if 
((ParamBean.CACHE_OFFONCE.equals(jParams.getCacheStatus())) ||
  +                        
(ParamBean.CACHE_BYPASS.equals(jParams.getCacheStatus())) ||
  +                        
(ParamBean.CACHE_ONLYUPDATE.equals(jParams.getCacheStatus()))
  +                    ) {
                           // if we have a mode that is only temporary, all the
                           // urls will be generated to have the cache active
                           // by default.
  -                        jParams.setCacheStatus (ParamBean.CACHE_ON);
  +                        jParams.setCacheStatus(ParamBean.CACHE_ON);
                       }
                   } else {
  -                    logger.debug ("Output cache not activated.");
  -                }
  -
  -                if ( jParams.getPage () != null ){
  -                    jData = new JahiaData (jParams);
  -                } else {
  -                    jData = new JahiaData (jParams,false);
  +                    logger.debug("Output cache not activated.");
                   }
               }
  -
  -            if ( jData == null ){
  -                // at least create a jData with minimum data for taglibs 
usage everywhere
  -                jData = new JahiaData (jParams,false);
  +            // So we does not found the page in the cache
  +            // check if the page is already generating or is generated
  +            synchronized (generatingPage) {
  +                if (!generatingPage.containsKey(entryKey) && 
!generatedPage.containsKey(entryKey) &&
  +                    generatingPage.size() < 10) {
  +                    // generate almost 3 pages in parallel
  +                    generatingPage.put(entryKey, entryKey);
  +                    generatedPage.remove(entryKey);
  +                    haveToBeenGenerate = true;
  +                }
  +                // force generation
  +                if (!iscacheable)
  +                    haveToBeenGenerate = true;
               }
  +            if (haveToBeenGenerate) {
  +                if( logger.isDebugEnabled()) {
  +                    logger.debug("We generate page "+entryKey);
  +//                logger.debug("Cache mode "+jParams.getCacheStatus()+" 
original cache "+jParams.getOriginalCacheStatus());
  +//                logger.debug("Engine type "+theEngine.getName());
  +                }
  +                if (theEngine.needsJahiaData(jParams) && jParams.getPage() 
!= null) {
  +                    jData = new JahiaData(jParams);
  +                } else {
  +                    jData = new JahiaData(jParams, false);
  +                }
   
  -            // for JSp
  -            
jParams.getRequest().setAttribute("org.jahia.data.JahiaData",jData);
  -
  -            theEngine.handleActions (jParams, jData);
  -            logger.debug("Operation handled for engine " + engineName);
  +                // for JSp
  +                
jParams.getRequest().setAttribute("org.jahia.data.JahiaData", jData);
   
  -            HttpSession session = jParams.getRequest().getSession();
  +                try {
  +                    theEngine.handleActions(jParams, jData);
  +                } catch (Throwable e) {
  +                    generatingPage.remove(entryKey);
  +                    throw new JahiaException("Error during handle of 
operation","Error during handle of 
operation",JahiaException.PAGE_ERROR,JahiaException.ERROR_SEVERITY,e);
  +                }
  +                logger.debug("Operation handled for engine " + engineName);
   
  -            // save last engine name in session
  -            session.setAttribute(ParamBean.SESSION_LAST_ENGINE_NAME,
  -                                 jParams.getEngine());
  +                HttpSession session = jParams.getRequest().getSession();
   
  -            // save last requested page id in session
  -            session.setAttribute(ParamBean.SESSION_LAST_REQUESTED_PAGE_ID,
  -                                 new Integer(jParams.getPageID()));
  +                // save last engine name in session
  +                session.setAttribute(ParamBean.SESSION_LAST_ENGINE_NAME, 
jParams.getEngine());
   
  -            // destroys request-dependant objects
  -            jData = null;
  +                // save last requested page id in session
  +                
session.setAttribute(ParamBean.SESSION_LAST_REQUESTED_PAGE_ID, new 
Integer(jParams.getPageID()));
   
  +                // destroys request-dependant objects
  +                jData = null;
  +            } else if(!haveToBeenGenerate && iscacheable) {
  +                try {
  +                    Thread.sleep(2000);
  +                } catch (InterruptedException e) {
  +                    logger.error("Exception during sleep ", e);
  +                }
  +                this.handleOperations(jParams, jSettings);
  +                return;
  +            }
           } else {
  -            logger.debug ("Could not get the engine [" + engineName + "] 
instance.");
  +            logger.debug("Could not get the engine [" + engineName + "] 
instance.");
           }
  -
           try {
               // Let's retrieve the generated content from the response 
wrapper object.
               String generatedOutput = jParams.getGeneratedOutput();
  @@ -329,12 +356,13 @@
               }
   
               if 
(jParams.settings().lookupBoolean(SettingsBean.OUTPUT_CACHE_ACTIVATED)) {
  -                storeInCache (jParams, htmlCache, workflowState, 
curLanguageCode,
  -                        generatedOutput, curContentType);
  +                logger.debug("store in cache "+entryKey);
  +                storeInCache(jParams, htmlCache, workflowState, 
curLanguageCode, generatedOutput, curContentType);
               }
  -
           } catch (java.io.IOException ioe) {
  -            logger.debug("Error retrieving real response writer object or 
while retrieving generated output :", ioe);
  +            logger.debug("Error retrieving real response writer object or 
while retrieving generated output :",
  +                         ioe);
  +            generatingPage.remove(entryKey);
           }
       }
   
  @@ -351,13 +379,14 @@
                                  int workflowState, String languageCode,
                                  String generatedOutput, String contentType) {
           logger.debug ("Storing generated content into the HTML Cache...");
  -
  +        // Modified getOriginalCacheStatus to cacheStatus 
           if (("core".equals (jParams.getEngine ())) &&
  -                ((ParamBean.CACHE_ON.equals (jParams.getOriginalCacheStatus 
())) ||
  -                (ParamBean.CACHE_ONLYUPDATE.equals 
(jParams.getOriginalCacheStatus ())) ||
  -                (ParamBean.CACHE_OFFONCE.equals 
(jParams.getOriginalCacheStatus ()))
  +                ((ParamBean.CACHE_ON.equals 
(jParams.getOriginalCacheStatus() )) ||
  +                (ParamBean.CACHE_ONLYUPDATE.equals 
(jParams.getOriginalCacheStatus() )) ||
  +                (ParamBean.CACHE_OFFONCE.equals 
(jParams.getOriginalCacheStatus() ))
                   )
           ) {
  +            if(logger.isDebugEnabled()){
               // let's update the cache...
               StringBuffer buffer = new StringBuffer ("Storing output in cache 
for page=");
               buffer.append (jParams.getPageID ());
  @@ -370,7 +399,7 @@
               buffer.append (jParams.getUserAgent ());
               buffer.append ("...");
               logger.debug (buffer.toString ());
  -
  +        }
               HtmlCacheEntry htmlEntry = new HtmlCacheEntry (generatedOutput, 
contentType);
               CacheEntry newEntry = new CacheEntry (htmlEntry);
               newEntry.setOperationMode (jParams.getOperationMode ());
  @@ -409,8 +438,17 @@
   
               htmlCache.putCacheEntry (entryKey, newEntry, true);
               logger.debug("Added HTML page into the cache.");
  +            generatingPage.remove(entryKey);
  +            generatedPage.put(entryKey,entryKey);
           } else {
               logger.debug("Bypassing HTML cache storage");
  +            String entryKey = htmlCache.computeEntryKey (
  +                    Integer.toString (jParams.getPageID ()),
  +                    jParams.getUser ().getUsername (),
  +                    languageCode,
  +                    workflowState,
  +                    jParams.getUserAgent ());
  +            generatingPage.remove(entryKey);
           }
       }
   
  
  
  
  Index: ParamBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/params/Attic/ParamBean.java,v
  retrieving revision 1.149.2.9.2.1
  retrieving revision 1.149.2.9.2.2
  diff -u -r1.149.2.9.2.1 -r1.149.2.9.2.2
  --- ParamBean.java    15 Feb 2005 16:46:55 -0000      1.149.2.9.2.1
  +++ ParamBean.java    24 Feb 2005 13:24:20 -0000      1.149.2.9.2.2
  @@ -288,6 +288,7 @@
       private int diffVersionID = 0;
   
       private ArrayList pageURLKeys = new ArrayList();
  +    private long delayFromNow;
   
       static {
           /** @todo we might want to put this in a configuration file so the
  @@ -2775,7 +2776,12 @@
        * (but may be flush upon content changes or other events).
        */
       public java.util.Date getCacheExpirationDate () {
  -        return cacheExpirationDate;
  +        if(cacheExpirationDate!=null)
  +            return cacheExpirationDate;
  +        else if(delayFromNow!=0) {
  +            return new Date(System.currentTimeMillis() + delayFromNow);
  +        }
  +        return null;
       }
   
       /**
  @@ -2797,9 +2803,7 @@
        * from now for the expiration of the current page's cache.
        */
       final public void setCacheExpirationDelay (long delayFromNow) {
  -        Date nowDate = new Date();
  -        Date expirationDate = new Date(nowDate.getTime() + delayFromNow);
  -        setCacheExpirationDate(expirationDate);
  +        this.delayFromNow = delayFromNow;
       }
   
       private void processActivationAction ()
  
  
  
  Index: Cache.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/services/cache/Attic/Cache.java,v
  retrieving revision 1.30.2.8
  retrieving revision 1.30.2.8.2.1
  diff -u -r1.30.2.8 -r1.30.2.8.2.1
  --- Cache.java        23 Sep 2004 16:31:22 -0000      1.30.2.8
  +++ Cache.java        24 Feb 2005 13:24:20 -0000      1.30.2.8.2.1
  @@ -39,6 +39,8 @@
   
   package org.jahia.services.cache;
   
  +import org.apache.commons.collections.FastHashMap;
  +
   import java.util.Map;
   import java.util.Vector;
   import java.util.HashMap;
  @@ -294,7 +296,7 @@
   
           // check the cache is still valid
           if (cache == null) {
  -                cache = new HashMap();
  +                cache = new FastHashMap(2503);
           }
   
           if (getCacheLimit () == 0) {
  @@ -348,7 +350,7 @@
           jmsHub = hub;
   
           // create the cache HashMap
  -        cache = new HashMap ();
  +        cache = new FastHashMap (2503);
       }
   
   
  
  
  
  Index: HtmlCache.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/src/java/org/jahia/services/cache/Attic/HtmlCache.java,v
  retrieving revision 1.13.2.1
  retrieving revision 1.13.2.1.2.1
  diff -u -r1.13.2.1 -r1.13.2.1.2.1
  --- HtmlCache.java    29 Jul 2004 15:39:50 -0000      1.13.2.1
  +++ HtmlCache.java    24 Feb 2005 13:24:20 -0000      1.13.2.1.2.1
  @@ -150,6 +150,35 @@
           }
       }
   
  +    /** <p>Invalidates all the cache entries related to the specified page 
<code>pageID</code>,
  +     * by removing the cache entries.</p>
  +     *
  +     * <p><b>Caution</b>: depending of the HTML cache size, this operation 
can be
  +     * time consumming!</p>
  +     *
  +     * @param pageID    the page identification
  +     */
  +    public synchronized void invalidatePageEntries (String pageID, int 
workflowState) {
  +        if (pageID == null) {
  +            logger.debug ("Cannot remove a null page ID fromt the cache!");
  +            return;
  +        }
  +
  +        logger.debug ("Removing cache entries for page ["+ pageID +"]");
  +
  +        String pageKey = PAGE_PREFIX + pageID + 
HIERARCHY_SEPARATOR+"(.*)"+KEY_SEPARATOR+workflowState;
  +        Object[] keys = keys();
  +        for (int i=0; i<keys.length; i++) {
  +            if (keys[i] instanceof String) {
  +                String key = (String)keys[i];
  +
  +                // if the key starts with the pageID, remove the element 
from the cache
  +                if (key.matches(pageKey)) {
  +                    remove(keys[i]);
  +                }
  +            }
  +        }
  +    }
   
       /** <p>Invalidates all the cache entries related to the specified user
        *  <code>username</code>, by removing the cache entries.</p>
  

Reply via email to