Changeset 16938

Show
Ignore:
Timestamp:
21.08.2008 13:24:40 (11 years ago)
Author:
kjdon
Message:

modified session caching stuff so that if there is no collection name, use the service name instead as the key

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r16926 r16938  
    6363   */ 
    6464  protected Hashtable session_ids_table = new Hashtable(); 
    65   //this name is combined with the collection name and used for caching  
    66   protected String valid_site_name = ""; 
    67    
     65  
    6866  /** the maximum interval that the cached info remains in session_ids_table (in seconds)  
    6967   *  This is set in web.xml 
     
    114112      } 
    115113    } 
    116     valid_site_name = (site_name != null)? site_name : remote_site_name; 
    117114     
    118115    if (this.default_lang == null) { 
     
    344341    String subaction = request.getParameter (GSParams.SUBACTION); 
    345342    String collection = request.getParameter(GSParams.COLLECTION); 
    346  
    347     //specifically we clean up the cache session_ids_table if the two reconfigure command 
    348     //are issued: a=s&sa=c and a=s&sa=c&c=coll_name, in which case there is no caching action to be taken 
     343    String service = request.getParameter(GSParams.SERVICE); 
     344 
     345    // We clean up the cache session_ids_table if system 
     346    // commands are issued (and also don't need to do caching for this request) 
    349347    boolean should_cache = true; 
    350     if(action != null && action.equals(GSParams.SYSTEM)  
    351        && subaction != null && subaction.equals(GSParams.CONFIGURE)) { 
    352       if (collection == null || collection.equals("")) { 
    353     //user reconfiugred the whole site, clean up all cached info 
    354     //logger.info("clear cache for the whole site."); 
     348    if(action != null && action.equals(GSParams.SYSTEM)) { 
     349      should_cache = false; 
     350 
     351      // we may want to remove all collection cache info, or just a specific collection 
     352      boolean clean_all = true;  
     353      String clean_collection = null; 
     354      // system commands are to activate/deactivate stuff 
     355      // collection param is in the sc parameter. 
     356      // don't like the fact that it is hard coded here 
     357      String coll = request.getParameter(GSParams.SYSTEM_CLUSTER); 
     358      if (coll != null && !coll.equals("")) { 
     359    clean_all = false; 
     360    clean_collection = coll; 
     361      } else { 
     362    // check other system types 
     363    if (subaction.equals("a") || subaction.equals("d")) { 
     364      String module_name = request.getParameter("sn"); 
     365      if (module_name != null && !module_name.equals("")) { 
     366        clean_all = false; 
     367        clean_collection = module_name; 
     368      } 
     369    } 
     370      } 
     371      if (clean_all) { 
    355372    session_ids_table = new Hashtable();  
    356373    session.removeAttribute(GSXML.USER_SESSION_CACHE_ATT); 
    357374      } else { 
    358     //clean up all cache info related to the collection 
    359     //logger.info("clear cache for collection: " + collection); 
     375    // just clean up info for clean_collection 
    360376    ArrayList cache_list = new ArrayList(session_ids_table.values()); 
    361377    for (int i=0; i<cache_list.size(); i++) { 
    362378      UserSessionCache cache = (UserSessionCache)cache_list.get(i); 
    363       cache.cleanupCache(collection); 
     379      cache.cleanupCache(clean_collection); 
    364380    } 
    365       } 
    366       should_cache = false; 
     381     
     382      } 
     383 
     384    } 
     385     
     386    // cache_key is the collection name, or service name 
     387    String cache_key = collection; 
     388    if (cache_key == null || cache_key.equals("")) { 
     389      cache_key = service; 
    367390    } 
    368391     
    369392    //  logger.info("should_cache= " + should_cache); 
     393 
    370394    //clear the collection-specific cache in the session, since we have no way to know whether this session is  
    371395    //about the same collection as the last session or not. 
     
    382406    // create a dumy collection name for Authentication  
    383407    if (subaction != null && subaction.equals("authen")){ 
    384       collection = "0000000000"; 
     408      cache_key = "0000000000"; 
    385409    } 
    386410     
     
    389413    Hashtable table = null; 
    390414    String sid = session.getId(); 
    391     if (should_cache == true && collection != null && !collection.equals("")) { 
    392       String key_str = valid_site_name + collection; 
     415    if (should_cache == true && cache_key != null && !cache_key.equals("")) { 
    393416      if (session_ids_table.containsKey(sid)) { 
    394417    session_cache = (UserSessionCache)session_ids_table.get(sid); 
    395418    param_table = session_cache.getParamsTable(); 
    396419    logger.info("collections in table: " + tableToString(param_table)); 
    397     if (param_table.containsKey(key_str)) { 
     420    if (param_table.containsKey(cache_key)) { 
    398421      //logger.info("existing table: " + collection); 
    399       table = (Hashtable)param_table.get(key_str); 
     422      table = (Hashtable)param_table.get(cache_key); 
    400423    } else { 
    401424      table = new Hashtable(); 
    402       param_table.put(key_str, table); 
     425      param_table.put(cache_key, table); 
    403426      //logger.info("new table: " + collection); 
    404427    } 
     
    406429    param_table = new Hashtable(); 
    407430    table = new Hashtable(); 
    408     param_table.put(key_str, table); 
     431    param_table.put(cache_key, table); 
    409432    session_cache = new UserSessionCache(sid, param_table); 
    410433    session_ids_table.put(sid, session_cache); 
     
    417440      // should we do all the following stuff if using default page? 
    418441      // display the home page  - the default page 
    419       action = "p"; 
    420       subaction = PageAction.HOME_PAGE; 
    421        
    422       xml_request.setAttribute (GSXML.ACTION_ATT, action); 
    423       xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 
    424        
    425     } else { 
    426        
     442      xml_request.setAttribute (GSXML.ACTION_ATT, "p"); 
     443      xml_request.setAttribute (GSXML.SUBACTION_ATT, PageAction.HOME_PAGE); 
     444    } 
     445    else { 
    427446      xml_request.setAttribute (GSXML.ACTION_ATT, action); 
    428447      if (subaction != null) { 
    429         xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 
     448    xml_request.setAttribute (GSXML.SUBACTION_ATT, subaction); 
    430449      } 
    431450       
     
    438457      while(params.hasMoreElements ()) { 
    439458        String name = (String)params.nextElement (); 
    440         if (!name.equals (GSParams.ACTION)  
     459    if (!name.equals (GSParams.ACTION)  
    441460        && !name.equals (GSParams.SUBACTION)  
    442461        && !name.equals (GSParams.LANGUAGE)  
     
    451470          } 
    452471          // either add it to the param list straight away, or save it to the session and add it later 
    453           if (this.params.shouldSave (name)) { 
    454         if (table != null) {                 
     472          if (this.params.shouldSave (name) && table != null) { 
    455473          table.put(name, value);                     
    456         } 
    457474          } else { 
    458475            Element param = this.doc.createElement (GSXML.PARAM_ELEM); 
     
    464481      } 
    465482      //put everything in the table into the session 
     483      // do we need to do this? why not just put from table into param list 
    466484      if (table != null) { 
    467485    Enumeration keys = table.keys (); 
     
    491509      } 
    492510    } 
    493      
     511       
    494512    if (!output.equals ("html")) { 
    495513      response.setContentType ("text/xml"); // for now use text 
     
    503521     
    504522    displaySize(session_ids_table); 
    505   } 
     523} 
     524 
    506525  //a debugging method 
    507526  private void displaySize(Hashtable table) {