mcardle     2005/11/15 13:50:37 CET

  Modified files:
    core/src/java/org/jahia/services/esi EsiService.java 
  Log:
  * support for invalidation of uninitialized containerLists with ID=0
  * refactorings
  
  Revision  Changes    Path
  1.13      +161 -216  
jahia/core/src/java/org/jahia/services/esi/EsiService.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/services/esi/EsiService.java.diff?r1=1.12&r2=1.13&f=h
  
  
  
  Index: EsiService.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/esi/EsiService.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EsiService.java   9 Oct 2005 08:48:01 -0000       1.12
  +++ EsiService.java   15 Nov 2005 12:50:37 -0000      1.13
  @@ -57,6 +57,7 @@
       private HashMap fieldsToInvalidate = new HashMap();
       private HashMap ctnsToInvalidate = new HashMap();
       private HashMap ctnListsToInvalidate = new HashMap();
  +    private HashMap ctnListsID0ToInvalidate = new HashMap();
       private HashMap pagesToInvalidate = new HashMap();
   
       //keeps track of which templates, containing aclGroup attributed 
fragments and
  @@ -88,6 +89,7 @@
   
       public void stop() {}
   
  +    //Following needs JDK 1.5 to work
       //private Stack tagStack = new Stack();
       /*private static ThreadLocal<Stack> tagStack = new ThreadLocal<Stack> () 
{
           protected Stack initialValue () {
  @@ -123,24 +125,22 @@
       public JesiObject tagStackPop(String sType, int ID) {
           JesiObject obj = (JesiObject) tagStack.getStack().peek();
           if ( sType.equals("Template") ) {
  -            if (logger.isDebugEnabled()) logger.debug("[esi]:  tagStackPop() 
 /////  Wants to pop a Template of pageID:"+ID);
  +            //if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackPop()  /////  Wants to pop a Template of pageID:"+ID);
               if (! (obj instanceof Template)) {
                   if (logger.isDebugEnabled()) logger.debug(
                           "tagStackPop()  /////  ERROR : Top of Stack is NOT a 
Template (it's URL is "+obj.URL+ ")");
               }
  -            else
  -            if (logger.isDebugEnabled())
  -                logger.debug("[esi]:  tagStackPop()  /////  Top of Stack IS 
indeed a Template of pageID:"+obj.pageID);
  +            //else
  +            //if (logger.isDebugEnabled())  logger.debug("[esi]:  
tagStackPop()  /////  Top of Stack IS indeed a Template of pageID:"+obj.pageID);
           }
           if ( sType.equals("Fragment") ) {
  -            if (logger.isDebugEnabled()) logger.debug("[esi]:  tagStackPop() 
 /////  Wants to pop a Fragment #"+ID);
  +            //if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackPop()  /////  Wants to pop a Fragment #"+ID);
               if (! (obj instanceof Fragment)) {
                   if (logger.isDebugEnabled()) logger.debug(
                           "tagStackPop()  /////  ERROR : Top of Stack is NOT a 
Fragment (it's URL is "+obj.URL+ ")");
               }
  -            else
  -            if (logger.isDebugEnabled())
  -                logger.debug("[esi]:  tagStackPop()  /////  Top of Stack IS 
a indeed Fragment #" + ((Fragment)obj).fragID );
  +            //else
  +            //if (logger.isDebugEnabled())  logger.debug("[esi]:  
tagStackPop()  /////  Top of Stack IS a indeed Fragment #" + 
((Fragment)obj).fragID );
           }
           return tagStackPop();
       }
  @@ -150,16 +150,14 @@
        * @return
        */
       public JesiObject tagStackPop() {
  -        //logger.debug("[esi]:  BEFORE - tagStackPop()  '''''  " + 
tagStacktoString());
   
           //Should be for efficiency:
           //return (JesiObject) tagStack.getStack().pop();
           JesiObject obj = (JesiObject) tagStack.getStack().pop();
  -        if (logger.isDebugEnabled()) {
  -            if (tagStack.getStack().empty())
  -                logger.debug("[esi]:  After - tagStackPop()  '''''  STACK IS 
NOW EMPTY. ");
  +        /*if (logger.isDebugEnabled()) {
  +            if (tagStack.getStack().empty()) logger.debug("[esi]:  After - 
tagStackPop()  '''''  STACK IS NOW EMPTY. ");
               else logger.debug("[esi]:  After - tagStackPop()  '''''  " + 
tagStacktoString());
  -        }
  +        }*/
           return obj;
       }
   
  @@ -170,12 +168,12 @@
        */
       public void tagStackPush(JesiObject obj) {
           tagStack.getStack().push(obj);
  -        if (logger.isDebugEnabled()) logger.debug("[esi]:  AFTER - 
tagStackPush()  '''''  " + tagStacktoString());
  +        //if (logger.isDebugEnabled()) logger.debug("[esi]:  AFTER - 
tagStackPush()  '''''  " + tagStacktoString());
       }
   
       public void tagStackClear() {
           tagStack.getStack().clear();
  -        if (logger.isDebugEnabled()) logger.debug("[esi]:  AFTER - 
tagStackClear() '''''  " + tagStacktoString());
  +        //if (logger.isDebugEnabled()) logger.debug("[esi]:  AFTER - 
tagStackClear() '''''  " + tagStacktoString());
       }
   
       /**
  @@ -214,160 +212,10 @@
           }
           return result.toString();
       }
  -
  -    protected final int CTN = 0;
  -    protected final int CTNLIST = 1;
  -    protected final int FIELD = 2;
  -
  -    /**
  -     * add a Container reference to the current JesiObject at the top of the 
Stack
  -     *
  -     * @param ctnID ID of Container to add
  -     */
  -    public void tagStackAddContainer(int ctnID) {
  -        tagStackAddContent(CTN, ctnID);
  -    }
  -    /**
  -     * add a ContainerList reference to the current JesiObject at the top of 
the Stack
  -     *
  -     * @param ctnListID ID of ContainerList to add
  -     */
  -    public void tagStackAddContainerList(int ctnListID) {
  -        tagStackAddContent(CTNLIST, ctnListID);
  -    }
  -    /**
  -     * add a Field reference to the current JesiObject at the top of the 
Stack
  -     *
  -     * @param fieldID ID of field to add
  -     */
  -    public void tagStackAddField(int fieldID) {
  -        tagStackAddContent(FIELD, fieldID);
  -    }
  -
  -    /*
  -    public void tagStackAddContentWithESICheck(int type, int contentID) {
  -        //Only do invalidation update if ESI is supported and tagStack
  -        //is initialized
  -       // if ( JesiTag.requestFromESI_10( 
Jahia.getThreadParamBean().getRealRequest() )//NECESSARY???????
  -       //     &&  !tagStack.getStack().empty() ) {
  -        if ( !tagStack.getStack().empty() )
  -            tagStackAddContent(type, contentID);
  -    }
  -      */
  -
  -    /**
  -     * add a content reference to the current JesiObject at the top of the 
Stack
  -     * @param type type of content object to add
  -     * @param contentID ID of content to add
  -     */
  -    public void tagStackAddContent (int type, int contentID) {
  -
  -        Object obj = tagStackPeek();
  -        if (obj instanceof Fragment) {
  -            Fragment fr = (Fragment) obj;
  -            String key = fr.siteID + "_" + fr.pageID + "_" + fr.fragID;
  -            //TODO: could cut this code down to half
  -            if (Fragments.containsKey(key)) {
  -                Fragment frg = (Fragment) Fragments.get(key);
  -                switch (type) {
  -                    case CTN:
  -                        frg.addContainer(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addContainer("+contentID+") for Fragment #"+frg.fragID);
  -                        break;
  -                    case CTNLIST:
  -                        frg.addContainerList(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addContainerList("+contentID+") for Fragment #"+frg.fragID);
  -                        break;
  -                    case FIELD:
  -                        frg.addField(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addField("+contentID+") for Fragment #"+frg.fragID);
  -                        break;
  -                    default:
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
Frag: THIS SHOULD HAPPEN EITHER!!!!!!!!");
  -                        break;
  -                }
  -                //Fragments.put(key, frg); 
//necessary????????????????????????????
  -            } else logger.error("[esi]:  Impossible clause: : detected a 
fragment which should have  been detected already");
  -        } else if (obj instanceof Template) {
  -            Template tp = (Template) obj;
  -            String key = tp.siteID + "_" + tp.pageID;
  -            if (Templates.containsKey(key)) {
  -                Template tpl = (Template) Templates.get(key);
  -                switch (type) {
  -                    case CTN:
  -                        tpl.addContainer(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addContainer("+contentID+") for Template #"+tpl.pageID);
  -                        break;
  -                    case CTNLIST:
  -                        tpl.addContainerList(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addContainerList("+contentID+") for Template #"+tpl.pageID);
  -                        break;
  -                    case FIELD:
  -                        tpl.addField(contentID);
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
tagStackAddContent-addField("+contentID+") for Template #"+tpl.pageID);
  -                        break;
  -                    default:
  -                        if (logger.isDebugEnabled()) logger.debug("[esi]:  
Templ: THIS SHOULD HAPPEN EITHER!!!!!!!!");
  -                        break;
  -                }
  -                //Templates.put(key, 
tpl);//necessary????????????????????????????
  -            } else logger.error("[esi]:  Impossible clause : detected a 
template which should have  been detected already");
  -        } else logger.error("[esi]:  Impossible clause: ESI Object Stack 
detected an object which wasn't a template or a fragment");
  -    }
  -
  -    /*  --------------------------------  END : ESI TAG STACK 
--------------------------------------- */
  +   /*  --------------------------------  END : ESI TAG STACK 
--------------------------------------- */
       /*  
-----------------------------------------------------------------------------------------------
 */
   
  -    /**
  -     * print contents of a Hashmap
  -     * @param hashm
  -     * @return
  -     */
  -    public static String printContents(final HashMap hashm){
  -        String out ="";
  -        if (hashm.isEmpty())
  -            out = "empty";
  -        else {
  -            Iterator pIter = hashm.keySet().iterator();
  -            while (pIter.hasNext()) {
  -                out = out + pIter.next()+ ", ";
  -            }
  -        }
  -        return out;
  -    }
  -    /**
  -     * print detailed contents of a Hashmap
  -     * @param hashm
  -     * @return
  -     */
  -    public static String printDetailedContents(final HashMap hashm){
  -        String out ="";
  -        if (hashm.isEmpty())
  -            out = "empty";
  -        else {
  -            Iterator pIter = hashm.keySet().iterator();
  -            while (pIter.hasNext()) {
  -                Object obj = pIter.next();
  -                out = out + "\n" + obj + " ["
  -                        + 
((hashm.get(obj)!=null)?hashm.get(obj).toString():"NULL OBJECT:" 
+hashm.get(obj))
  -                        +  "] , ";
  -            }
  -        }
  -        //out = out + "  --   "  ;
  -        //System.out.println();
  -        return out;
  -    }
  -
  -
   
  -    public String toString() {
  -        String out="";
  -        out = out + "Templates : \n";
  -        out = out + printContents(Templates);
  -        out = out + "Fragments : \n";
  -        out = out + printContents(Fragments);
  -        return out;
  -    }
   
       /**
        * add a new Fragment to the Fragments list (which is a global 
multi-site HashMap containing
  @@ -401,21 +249,15 @@
               FragmentCountbyPage.put(Integer.toString(frg_pageID), frgCount);
               if ( frgCount.intValue() !=  frg_fragcount)
                   logger.error("[esi]:  Number of tracked Fragments is 
inconsistant. mine="+frgCount.intValue() + " vs tags="+frg_fragcount);
  -            //DEBUG ---- Keep track of fragments per page
   
  -            //DEbug --------------
  -            /*Iterator iterator = Fragments.values().iterator();
  -            int numf = 0;
  -            while (iterator.hasNext()) {
  -                Fragment f = (Fragment) iterator.next();
  -                logger.debug("[esi]:  Fragment ID:"+frg.fragID +" (pos:"+ 
numf + ") : " + f.toString());
  -            }*/
           } else {
               frg = (Fragment) Fragments.get(key);
               if ( frg.fragID !=  frg_fragcount)
                   logger.error("[esi]:  Number of tracked Fragments is 
inconsistant.");
  +            if (logger.isDebugEnabled()) logger.debug("[esi]:  Stack: adding 
ALREADY declared Fragment " +frg_fragcount );//+ ": " + frg.toString());
  +            frg.emptyContent();
  +            if (logger.isDebugEnabled())  logger.debug("[esi]:  Cleared all 
ContentIDs in Fragment [" +key+ "]");
   
  -            logger.debug("[esi]:  Stack: adding ALREADY declared Fragment " 
+frg_fragcount );//+ ": " + frg.toString());
           }
   
           tagStackPush(frg);
  @@ -508,6 +350,8 @@
           else {
               tpl = (Template) Templates.get(key);
               if (logger.isDebugEnabled()) logger.debug("[esi]:  Stack: adding 
ALREADY declared Template on page:" + tpl.pageID );//+ tpl.toString());
  +            tpl.emptyContent();
  +            if (logger.isDebugEnabled())  logger.debug("[esi]:  Cleared all 
ContentIDs in Template on pageID [" +tpl.pageID+ "]");
           }
   
           tagStackPush(tpl);
  @@ -518,11 +362,11 @@
       }
   
       public Template getTemplate(int pageID) {
  -        return (Template) 
getTemplate(Jahia.getThreadParamBean().getSiteID(), pageID );
  +        return getTemplate(Jahia.getThreadParamBean().getSiteID(), pageID );
       }
   
       public Template getTemplate() {
  -        return (Template) 
getTemplate(Jahia.getThreadParamBean().getSiteID(), 
Jahia.getThreadParamBean().getPageID() );
  +        return getTemplate(Jahia.getThreadParamBean().getSiteID(), 
Jahia.getThreadParamBean().getPageID() );
       }
   
       //TODO: getFragmentsToInvalidate is very similar to 
getTemplatesToInvalidate, merge them!!
  @@ -539,21 +383,33 @@
                       + "Probable cause 2: Most of the requests rightfully 
generate an invalidation message, which is fine, so ignore this message."
                       + "\nctnsToInvalidate:"+printContents(ctnsToInvalidate)
                       + 
"\nctnListsToInvalidate:"+printContents(ctnListsToInvalidate)
  +                    + 
"\nctnListsID0ToInvalidate:"+printContents(ctnListsID0ToInvalidate)
                       + "\npagesToInvalidate:"+printContents(pagesToInvalidate)
                       + 
"\nfieldsToInvalidate:"+printContents(fieldsToInvalidate)
                       + 
"\naclGroupTemplatesToInvalidate:"+printContents(aclGroupTemplatesToInvalidate)
                       + "\ncheckForAnyContentToInvalidate : 
EMPTY["+empty_count+"] / NOT_EMPTY["+notempty_count+"]"
               );
           }
  +
           logger.debug("[esi]:  checkForAnyContentToInvalidate : 
EMPTY["+empty_count+"] / NOT_EMPTY["+notempty_count+"]");
   
           //TODO: Need to make sure no junk orphaned content stays in these 
lists
           //otherwise it will mess up performance
           if (!ctnsToInvalidate.isEmpty()
                   || !ctnListsToInvalidate.isEmpty()
  +                || !ctnListsID0ToInvalidate.isEmpty()
                   || !pagesToInvalidate.isEmpty()
                   || !fieldsToInvalidate.isEmpty()
                   || !aclGroupTemplatesToInvalidate.isEmpty() )   {
  +            //TODO: get rid of this debug info
  +            if (logger.isDebugEnabled())
  +                logger.debug(" checkForAnyContentToInvalidate: "
  +                 + "\nctnListsID0ToInvalidate: 
\t\t"+printContents(ctnListsID0ToInvalidate)
  +                 + "\nctnListsToInvalidate: 
\t\t"+printContents(ctnListsToInvalidate)
  +                 +"\nctnsToInvalidate: \t\t"+printContents(ctnsToInvalidate)
  +                 + "\npagesToInvalidate: 
\t\t"+printContents(pagesToInvalidate)
  +                 + "\nfieldsToInvalidate: 
\t\t"+printContents(fieldsToInvalidate)
  +                 + "\naclGroupTemplatesToInvalidate: 
\t\t"+printContents(aclGroupTemplatesToInvalidate) );
               notempty_count++;
               return true;
           }
  @@ -586,6 +442,8 @@
                   continue; //can skip rest since Fragment marked as invalid - 
no need to go further
               if 
(getFragmentToInvalidate(FragmentsToInvalidate,ctnListsToInvalidate, frg_key, 
frg, "CONTAINERLIST"))
                   continue;
  +            if 
(getFragmentToInvalidate(FragmentsToInvalidate,ctnListsID0ToInvalidate, 
frg_key, frg, "CONTAINERLISTID0"))
  +                continue;
               if 
(getFragmentToInvalidate(FragmentsToInvalidate,pagesToInvalidate, frg_key, frg, 
"PAGE"))
                   continue;
               if 
(getFragmentToInvalidate(FragmentsToInvalidate,fieldsToInvalidate, frg_key, 
frg, "FIELD"))
  @@ -613,16 +471,17 @@
                   " in contentToInvalidate [" + 
printContents(contentToInvalidate)
                   +"] which is referred in Fragment["+frg_key+"] of content : 
"+ frg );*/
   
  -        Integer ct_key;
  +        String ct_key;
   
           if (!contentToInvalidate.isEmpty()) {
               Iterator Itid = contentToInvalidate.keySet().iterator();
               while (Itid.hasNext()) {
  -                ct_key = (Integer) Itid.next();
  -                if ( (contentType.equals("FIELD") && frg.fields.containsKey( 
ct_key ) ) ||
  +                ct_key = (String) Itid.next();
  +                if (    (contentType.equals("FIELD") && 
frg.fields.containsKey( ct_key ) ) ||
                           (contentType.equals("PAGE") && 
frg.pages.containsKey( ct_key ) ) ||
                           (contentType.equals("CONTAINER") && 
frg.ctns.containsKey( ct_key ) ) ||
  -                        (contentType.equals("CONTAINERLIST") && 
frg.ctnlists.containsKey( ct_key ) )
  +                        (contentType.equals("CONTAINERLIST") && 
frg.ctnlists.containsKey( ct_key ) ) ||
  +                        (contentType.equals("CONTAINERLISTID0") && 
frg.ctnListID0.containsKey( ct_key ) )
                           ) {
                       if (!FragmentsToInvalidate.containsKey(frg_key) )
                       {
  @@ -664,6 +523,8 @@
                   continue;
               if 
(getTemplateToInvalidate(TemplatesToInvalidate,ctnListsToInvalidate, templ_key, 
tpl, "CONTAINERLIST"))
                   continue;
  +            if 
(getTemplateToInvalidate(TemplatesToInvalidate,ctnListsID0ToInvalidate, 
templ_key, tpl, "CONTAINERLISTID0"))
  +                continue;
               if 
(getTemplateToInvalidate(TemplatesToInvalidate,pagesToInvalidate, templ_key, 
tpl, "PAGE"))
                   continue;
               if 
(getTemplateToInvalidate(TemplatesToInvalidate,fieldsToInvalidate, templ_key, 
tpl, "FIELD"))
  @@ -691,16 +552,17 @@
   
           //logger.debug(printContents(contentToInvalidate) );
   
  -        Integer ct_key;
  +        String ct_key;
   
           if (!contentToInvalidate.isEmpty()) {
               Iterator Itid = contentToInvalidate.keySet().iterator();
               while (Itid.hasNext()) {
  -                ct_key = (Integer) Itid.next();
  +                ct_key = (String) Itid.next();
                   if ( (contentType.equals("FIELD") && tpl.fields.containsKey( 
ct_key ) ) ||
                           (contentType.equals("PAGE") && 
tpl.pages.containsKey( ct_key ) ) ||
                           (contentType.equals("CONTAINER") && 
tpl.ctns.containsKey( ct_key ) ) ||
  -                        (contentType.equals("CONTAINERLIST") && 
tpl.ctnlists.containsKey( ct_key ) )
  +                        (contentType.equals("CONTAINERLIST") && 
tpl.ctnlists.containsKey( ct_key ) ) ||
  +                        (contentType.equals("CONTAINERLISTID0") && 
tpl.ctnListID0.containsKey( ct_key ) )
                           ) {
                       if (!TemplatesToInvalidate.containsKey(templ_key) )
                       {
  @@ -718,6 +580,49 @@
       }
   
       /**
  +     * check to see if any Templates/Fragments reference the given 
containerList. This is used
  +     * when a new container is added and we want to find out if its 
enclosing containerList has
  +     * or has not yet been detected inside a Fragment/Template during AOP 
JSP detection. If not, then
  +     * this is a new containerList and we need to invalidate the 
Fragment/Template that has a reference
  +     * to the containerList's definition name in ctnListsID0ToInvalidate.
  +     * @param ctnListID
  +     */
  +    public boolean isCtnListAlreadyReferenced(final int ctnListID) {
  +        final String id = Integer.toString(ctnListID);
  +
  +        //check all Templates
  +        Iterator pIter = Templates.keySet().iterator();
  +        while (pIter.hasNext()) {
  +            String tpl_key = (String) pIter.next();
  +            Template tpl = (Template) Templates.get(tpl_key);
  +            if (tpl.ctnlists.containsKey(id)) {
  +                if (logger.isDebugEnabled())
  +                    logger.debug("Found ctnList="+ctnListID + " in Template 
"+tpl_key);
  +                return true;
  +            }
  +
  +        }
  +
  +        //check all Fragments
  +        pIter = Fragments.keySet().iterator();
  +        while (pIter.hasNext()) {
  +
  +            String frg_key = (String) pIter.next();
  +            Fragment frg = (Fragment) Fragments.get(frg_key);
  +            if (frg.ctnlists.containsKey(id))  {
  +                if (logger.isDebugEnabled() )
  +                    logger.debug("Found ctnList="+ctnListID + " in Fragment 
"+frg_key);
  +                return true;
  +            }
  +
  +        }
  +        if (logger.isDebugEnabled() )
  +            logger.debug("Couldn't find ctnList="+ctnListID + " in 
Fragments/Templates");
  +        //nope, couldn't find it
  +        return false;
  +    }
  +
  +    /**
        *  clear the contentIDs contained in any Templates that were invalidated
        *           so that AOP will redetect all the contentIDs of these 
Templates
        *            during the execution of the
  @@ -782,10 +687,10 @@
           //           Possible solution: use a contentObject time-to-live 
timer, so that when these objects haven't been
           //           deleted for ages, we just get rid of them.
   
  -        Integer tp_key = null;
  +        String tp_key = null;
           Iterator pIter = fieldsToInvalidate.keySet().iterator();
           while (pIter.hasNext()) {
  -            tp_key = (Integer) pIter.next();
  +            tp_key = (String) pIter.next();
               //only remove entries that have been marked as invalidated
               if ( ((Boolean) fieldsToInvalidate.get(tp_key) ).booleanValue() 
== true  )
                   pIter.remove();
  @@ -796,7 +701,7 @@
   
           pIter = ctnsToInvalidate.keySet().iterator();
           while (pIter.hasNext()) {
  -            tp_key = (Integer) pIter.next();
  +            tp_key = (String) pIter.next();
               //only remove entries that have been marked as invalidated
               if ( ((Boolean) ctnsToInvalidate.get(tp_key) ).booleanValue() == 
true  )
                   pIter.remove();
  @@ -807,7 +712,7 @@
   
           pIter = ctnListsToInvalidate.keySet().iterator();
           while (pIter.hasNext()) {
  -            tp_key = (Integer) pIter.next();
  +            tp_key = (String) pIter.next();
               //only remove entries that have been marked as invalidated
               if ( ((Boolean) ctnListsToInvalidate.get(tp_key) 
).booleanValue() == true  )
                   pIter.remove();
  @@ -818,7 +723,7 @@
   
           pIter = pagesToInvalidate.keySet().iterator();
           while (pIter.hasNext()) {
  -            tp_key = (Integer) pIter.next();
  +            tp_key = (String) pIter.next();
               //only remove entries that have been marked as invalidated
               if ( ((Boolean) pagesToInvalidate.get(tp_key) ).booleanValue() 
== true  )
                   pIter.remove();
  @@ -827,14 +732,19 @@
                   logger.debug("[esi]:  page " + tp_key + " was invalidated 
and removed from queue. (should be false ["+pagesToInvalidate.get(tp_key)+"])");
           }
   
  +        pIter = ctnListsID0ToInvalidate.keySet().iterator();
  +        while (pIter.hasNext()) {
  +            tp_key = (String) pIter.next();
  +            //only remove entries that have been marked as invalidated
  +            if ( ((Boolean) ctnListsID0ToInvalidate.get(tp_key) 
).booleanValue() == true  )
  +                pIter.remove();
  +            //ctnListsToInvalidate.remove(tp_key);
  +            if (logger.isDebugEnabled())
  +                logger.debug("[esi]:  containerListID0 " + tp_key + " was 
invalidated and removed from queue. (should be false 
["+ctnListsID0ToInvalidate.get(tp_key)+"])");
  +        }
  +
           //we can safely clear this:
           aclGroupTemplatesToInvalidate.clear();
  -
  -        /*ctnsToInvalidate.clear();
  -        ctnListsToInvalidate.clear();
  -        pagesToInvalidate.clear();
  -        fieldsToInvalidate.clear();*/
  -
       }
   
       /**
  @@ -869,11 +779,11 @@
        * @param ctn
        */
       public void ctnRequiresInvalidation (final JahiaContainer ctn) {//don't 
really need to put whole JahiaContainer object, could cut it down to a couple 
of ints
  -        ctnsToInvalidate.put( new Integer(ctn.getID()), new Boolean(false) 
); //Boolean is toggled once entry has been invalidated
  +        ctnsToInvalidate.put( Integer.toString(ctn.getID()), new 
Boolean(false) ); //Boolean is toggled once entry has been invalidated
           //new Integer[] {new Integer(ctn.getPageID()), new 
Integer(ctn.getID())} );
       }
       public void ctnRequiresInvalidation (final int ctnID) {
  -        ctnsToInvalidate.put( new Integer(ctnID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
  +        ctnsToInvalidate.put( Integer.toString(ctnID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
   
       }
   
  @@ -884,11 +794,11 @@
        * @param ctnList
        */
       public void ctnListRequiresInvalidation (final JahiaContainerList 
ctnList) {
  -        ctnListsToInvalidate.put(new Integer(ctnList.getID()), new 
Boolean(false) );
  +        ctnListsToInvalidate.put(Integer.toString(ctnList.getID()), new 
Boolean(false) );
           //new Integer[] {new Integer(ctnList.getPageID()),new 
Integer(ctnList.getID()) } );
       }
       public void ctnListRequiresInvalidation (final int ctnListID) {
  -        ctnListsToInvalidate.put( new Integer(ctnListID), new Boolean(false) 
); //Boolean is toggled once entry has been invalidated
  +        ctnListsToInvalidate.put( Integer.toString(ctnListID), new 
Boolean(false) ); //Boolean is toggled once entry has been invalidated
   
       }
       /**
  @@ -898,11 +808,11 @@
        * @param page
        */
       public void pageRequiresInvalidation (final JahiaPage page) {
  -        pagesToInvalidate.put(new Integer(page.getID()), new Boolean(false) 
);
  +        pagesToInvalidate.put(Integer.toString(page.getID()), new 
Boolean(false) );
           //new Integer(page.getID()));
       }
       public void pageRequiresInvalidation (int pageID) {
  -        pagesToInvalidate.put( new Integer(pageID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
  +        pagesToInvalidate.put( Integer.toString(pageID), new Boolean(false) 
); //Boolean is toggled once entry has been invalidated
   
       }
   
  @@ -913,33 +823,68 @@
        * @param field
        */
       public void fieldUpdateInvalidation (final JahiaField field) {
  -        fieldsToInvalidate.put( new Integer(field.getID()) , new 
Boolean(false) );
  +        fieldsToInvalidate.put( Integer.toString(field.getID()) , new 
Boolean(false) );
           //new Integer[] {new Integer(field.getPageID()),new 
Integer(field.getID())});
       }
       public void fieldUpdateInvalidation (final int fieldID) {
  -        fieldsToInvalidate.put( new Integer(fieldID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
  +        fieldsToInvalidate.put( Integer.toString(fieldID), new 
Boolean(false) ); //Boolean is toggled once entry has been invalidated
   
       }
   
  -    /*  //cycles through list of updated contentObjects and
  -     //sees which fragments/templates references them
  -     //called from Valve before generating ESI invalidation messages
  -     //after it has run it empties the hashmap of updated contentObjects, 
since they will have been invalidated
  -     //in the following step of the ESIInvalidateValve
  -    public void updateInvalidation () {
  -
  -
  -
  -    }*/
  -
  -
  +    public void ctnListID0RequiresInvalidation (String ctnListName, int 
ctnListPageID) {
  +         ctnListsID0ToInvalidate.put( ctnListPageID+"_"+ctnListName, new 
Boolean(false) ); //Boolean is toggled once entry has been invalidated
   
  +    }
   
  -    {}
   
  +    /**
  +     * print contents of a Hashmap
  +     * @param hashm
  +     * @return
  +     */
  +    public static String printContents(final HashMap hashm){
  +        String out ="";
  +        if (hashm.isEmpty())
  +            out = "empty";
  +        else {
  +            Iterator pIter = hashm.keySet().iterator();
  +            while (pIter.hasNext()) {
  +                out = out + pIter.next()+ ", ";
  +            }
  +        }
  +        return out;
  +    }
  +    /**
  +     * print detailed contents of a Hashmap
  +     * @param hashm
  +     * @return
  +     */
  +    public static String printDetailedContents(final HashMap hashm){
  +        String out ="";
  +        if (hashm.isEmpty())
  +            out = "empty";
  +        else {
  +            Iterator pIter = hashm.keySet().iterator();
  +            while (pIter.hasNext()) {
  +                Object obj = pIter.next();
  +                out = out + "\n" + obj + " ["
  +                        + 
((hashm.get(obj)!=null)?hashm.get(obj).toString():"NULL OBJECT:" 
+hashm.get(obj))
  +                        +  "] , ";
  +            }
  +        }
  +        return out;
  +    }
   
   
   
  +    public String toString() {
  +        String out="";
  +        out = out + "Templates : \n";
  +        out = out + printDetailedContents(Templates);
  +        out = out + "\nFragments : \n";
  +        out = out + printDetailedContents(Fragments);
  +        return out;
  +    }
   
   
   }
  

Reply via email to