mcardle     2005/09/06 16:01:45 CEST

  Modified files:
    core/src/java/org/jahia/services/esi EsiService.java 
  Log:
  * adds support for the aclGroup fragment attribute to share fragments between 
users with the same group permissions

  * name refactoring

  * some cleanup
  
  Revision  Changes    Path
  1.8       +54 -45    
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.7&r2=1.8&f=h
  
  
  
  Index: EsiService.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/services/esi/EsiService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EsiService.java   30 Aug 2005 15:47:23 -0000      1.7
  +++ EsiService.java   6 Sep 2005 14:01:44 -0000       1.8
  @@ -59,6 +59,11 @@
       private HashMap ctnListsToInvalidate = new HashMap();
       private HashMap pagesToInvalidate = new HashMap();
   
  +    //keeps track of which templates, containing aclGroup attributed 
fragments and
  +    // which have had a new username added with addAclUserNames(), need to 
be invalidated
  +    private HashMap aclGroupTemplatesToInvalidate = new HashMap();
  +
  +
       public EsiService () {
       }
   
  @@ -143,7 +148,7 @@
       public JesiObject tagStackPop() {
           //logger.debug("BEFORE - tagStackPop()  '''''  " + 
tagStacktoString());
   
  -        //Should be:
  +        //Should be for efficiency:
           //return (JesiObject) tagStack.getStack().pop();
           JesiObject obj = (JesiObject) tagStack.getStack().pop();
           if (tagStack.getStack().empty())
  @@ -370,14 +375,14 @@
        *
        */
   
  -    public int addFragment (int frg_siteID, int frg_pageID, int 
frg_fragcount, String frg_URL) {
  +    public int addFragment (int frg_siteID, int frg_pageID, int 
frg_fragcount, String frg_URL, String aclGroup) {
           //       synchronized (this) {
   
           String key = frg_siteID + "_" + frg_pageID + "_" + frg_fragcount;
           Fragment frg = null;
   
           if (!Fragments.containsKey(key)) {
  -            frg = new Fragment(frg_siteID, frg_pageID,frg_fragcount, 
frg_URL);
  +            frg = new Fragment(frg_siteID, frg_pageID,frg_fragcount, 
frg_URL, aclGroup);
               Fragments.put(key, frg);
               logger.debug("Stack: adding NEW Fragment " + frg.fragID );//+ " 
: " + frg.toString());
   
  @@ -524,7 +529,15 @@
        */
       public boolean checkForAnyContentToInvalidate() {
           if (notempty_count > 0 && notempty_count > empty_count)
  -             logger.error("A Content object probably cannot be invalidated. 
(probable cause: it is not attached to a Template/Fragment)");
  +             logger.warn("The majority of requests generate ESI 
invalidations.\n"
  +                     + "Probable cause 1: A Content object probably cannot 
be invalidated as it is not attached to a Template/Fragment."
  +                     + "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)
  +                     + 
"\npagesToInvalidate:"+printContents(pagesToInvalidate)
  +                     + 
"\nfieldsToInvalidate:"+printContents(fieldsToInvalidate)
  +                     + 
"\naclGroupTemplatesToInvalidate:"+printContents(aclGroupTemplatesToInvalidate)
  +             );
   
           logger.debug("checkForAnyContentToInvalidate : 
EMPTY["+empty_count+"] / NOT_EMPTY["+notempty_count+"]");
   
  @@ -533,7 +546,8 @@
           if (!ctnsToInvalidate.isEmpty()
                   || !ctnListsToInvalidate.isEmpty()
                   || !pagesToInvalidate.isEmpty()
  -                || !fieldsToInvalidate.isEmpty() )   {
  +                || !fieldsToInvalidate.isEmpty()
  +                || !aclGroupTemplatesToInvalidate.isEmpty() )   {
               notempty_count++;
               return true;
           }
  @@ -648,6 +662,10 @@
               if 
(getTemplateToInvalidate(TemplatesToInvalidate,fieldsToInvalidate, templ_key, 
tpl, "FIELD"))
                   continue;
           }
  +        //add any templates, containing aclGroup attributed fragments and
  +        // which have had a new username added with addAclUserNames(), to be 
invalidated
  +        TemplatesToInvalidate.putAll(aclGroupTemplatesToInvalidate);
  +
           return TemplatesToInvalidate;
       }
   
  @@ -691,37 +709,6 @@
           return false;
       }
   
  -
  -
  -//   public Vector getTemplatesToInvalidate () {
  -//        Vector TemplatesToInvalidate = new Vector();
  -//
  -//        Iterator pIter = 
Templates.keySet().iterator();//Templates.entrySet().iterator();
  -//        while (pIter.hasNext()) {
  -//            TemplatesToInvalidate.add( (Template) 
Templates.get(pIter.next()));
  -    /*String url = ( (Template) Templates.get(pIter.next())).URL;
  -    if (!TemplatesToInvalidate.contains(url)) {
  -        TemplatesToInvalidate.add(url);
  -        logger.debug("EsiService:   Template to invalidate :" +
  -                           url);
  -    }*/
  -//       }
  -//        return TemplatesToInvalidate;
  -//    }
  -
  -    /*public Vector getObjsToInvalidate () {
  -        Vector ObjsToInvalidate = getTemplatesToInvalidate();
  -        ObjsToInvalidate.addAll(getFragmentsToInvalidate());
  -
  -        //clean up now
  -        ctnsToInvalidate.clear();
  -        ctnListsToInvalidate.clear();
  -        pagesToInvalidate.clear();
  -        fieldsToInvalidate.clear();
  -
  -        return ObjsToInvalidate;
  -    }*/
  -
       /**
        *  clear the contentIDs contained in any Templates that were invalidated
        *           so that AOP will redetect all the contentIDs of these 
Templates
  @@ -781,7 +768,7 @@
           //           which means that they will stay forever in the  
*ToInvalidate HashMaps. This is pain
           //           since the system will constantly be looking for these 
content objects in Fragments/Templates
           //           but will never find them. Now this is bearable if there 
is only a limited number of these
  -        //           orphan objects, but it become a resource hog is they 
too numerous.
  +        //           orphan objects, but it becomes a resource hog if they 
too numerous.
           //           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.
   
  @@ -826,28 +813,50 @@
               logger.debug("page " + tp_key + " was invalidated and removed 
from queue. (should be false ["+pagesToInvalidate.get(tp_key)+"])");
           }
   
  +        //we can safely clear this:
  +        aclGroupTemplatesToInvalidate.clear();
   
  -        /*ctnsToInvalidate.clear();
  +       /*ctnsToInvalidate.clear();
           ctnListsToInvalidate.clear();
           pagesToInvalidate.clear();
           fieldsToInvalidate.clear();*/
   
       }
   
  +    /**
  +     * Add the current Template to be invalidated at the next ESI 
invalidation message.
  +     * This is because the current Template contains an aclGroup attributed 
fragment(s) and
  +     * has had a new username added with addAclUserNames().
  +     */
  +    public void aclGroupTemplateRequiresInvalidation () {
  +        Template tpl = getTemplate();
  +        aclGroupTemplateRequiresInvalidation (tpl.siteID,tpl.siteID);
  +    }
  +
  +    public void aclGroupTemplateRequiresInvalidation (int siteID, int 
pageID) {
  +        String key = siteID + "_" + pageID;
  +        logger.info("Adding Template ["+key+"] to 
aclGroupTemplatesToInvalidate since it requires invalidation");
  +
  +        if (aclGroupTemplatesToInvalidate.put(key , (Template) 
Templates.get(key))   == null)
  +            logger.info("Successfully added Template to 
aclGroupTemplatesToInvalidate");
  +        else
  +            logger.info("Template was already present in 
aclGroupTemplatesToInvalidate");
  +    }
  +
   
   
  -    //TODO: Get rid of JahiaObject verison of method and just use Integer ID 
versions
  +    //TODO: Get rid of JahiaObject version of method and just use Integer ID 
versions
       /**
        * add a Container to the list of content to be invalidated, typically 
because the EsiInvalidationEventListener
        * detected an update/create/delete event on this content object.  All 
ESI Fragments/Templates that point to
        * this content will be invalidated.
        * @param ctn
        */
  -    public void ctnUpdateInvalidation (final JahiaContainer ctn) {//don't 
really need to put whole JahiaContainer object, could cut it down to a couple 
of ints
  +    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
           //new Integer[] {new Integer(ctn.getPageID()), new 
Integer(ctn.getID())} );
       }
  -    public void ctnUpdateInvalidation (final int ctnID) {
  +    public void ctnRequiresInvalidation (final int ctnID) {
           ctnsToInvalidate.put( new Integer(ctnID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
   
       }
  @@ -858,11 +867,11 @@
        * this content will be invalidated.
        * @param ctnList
        */
  -    public void ctnListUpdateInvalidation (final JahiaContainerList ctnList) 
{
  +    public void ctnListRequiresInvalidation (final JahiaContainerList 
ctnList) {
           ctnListsToInvalidate.put(new Integer(ctnList.getID()), new 
Boolean(false) );
           //new Integer[] {new Integer(ctnList.getPageID()),new 
Integer(ctnList.getID()) } );
       }
  -    public void ctnListUpdateInvalidation (final int ctnListID) {
  +    public void ctnListRequiresInvalidation (final int ctnListID) {
           ctnListsToInvalidate.put( new Integer(ctnListID), new Boolean(false) 
); //Boolean is toggled once entry has been invalidated
   
       }
  @@ -872,11 +881,11 @@
        * this content will be invalidated.
        * @param page
        */
  -    public void pageUpdateInvalidation (final JahiaPage page) {
  +    public void pageRequiresInvalidation (final JahiaPage page) {
           pagesToInvalidate.put(new Integer(page.getID()), new Boolean(false) 
);
           //new Integer(page.getID()));
       }
  -    public void pageUpdateInvalidation (int pageID) {
  +    public void pageRequiresInvalidation (int pageID) {
           pagesToInvalidate.put( new Integer(pageID), new Boolean(false) ); 
//Boolean is toggled once entry has been invalidated
   
       }
  

Reply via email to