Changeset 25580

Show
Ignore:
Timestamp:
11.05.2012 22:10:15 (7 years ago)
Author:
ak19
Message:

SystemAction? now supports pinging on a collection with ?a=s&sa=ping&st=collection&sn=colName

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/SystemAction.java

    r25571 r25580  
    7474            system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info); 
    7575        } 
    76         else if (subaction.equals("ping")){ 
    77             // No pinging on collections yet in GS3 as is there in GS2 
    78             // The ping subaction is at present just for activate.pl 
     76        else if (subaction.equals("ping")) { // can ping the server or a collection 
     77            String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME); 
     78             
     79            if(name != null && !name.equals("")) {  
     80                // Pinging a collection (or module) with ?a=s&sa=ping&st=collection&sn=<colName> 
     81                // is a collection-level (servicecluster/module level) ping 
     82                 
     83                String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE); 
     84                if(type == null || type.equals("")) {  
     85                    type = "collection"; // if the st=collection was omitted, assume collection 
     86                }                
     87                // ping action set to moduleType=Collection and moduleName=colName 
     88                system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name); 
     89                system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type); 
     90                system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING); 
     91            } // else SYSTEM_MODULE_NAME given by the "sn" GSParam is null or empty  
     92              // meaning server-level ping: ?a=s&sa=ping 
     93               
    7994            system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING); 
    8095        } 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r25571 r25580  
    570570  } 
    571571   
     572  // testing whether a collection (or more generally, a module) is active 
     573  protected boolean pingModule(String name) { 
     574    // module (including collection) would have been added to module_map  
     575    // if activated, and removed from map if deactivated. 
     576    // The this.collection_list Element would contain the collection too,  
     577    // but the following check seems to be more generally useful 
     578    return this.module_map.containsKey(name);    
     579  } 
     580   
    572581  /** creates and configures a new collection 
    573582      if this is done for a reconfigure, the collection should be deactivated first. 
     
    835844    return false; 
    836845  } 
    837    
     846     
    838847  protected boolean deactivateModule(String type, String name) { 
    839848     
     
    974983        Element elem = (Element)commands.item(i); 
    975984        String action = elem.getAttribute(GSXML.TYPE_ATT); 
    976         if (action.equals(GSXML.SYSTEM_TYPE_PING)) { 
    977             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM,  "Ping succeeded."); 
     985         
     986        if (action.equals(GSXML.SYSTEM_TYPE_PING)) { // ?a=s&sa=ping or ?a=s&sa=ping(&st=collection)&sn=colname 
     987                         
     988            String message = ""; // will be creating the same messages as in GS2's recept/pingaction.cpp 
     989            String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT); 
     990            String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);            
     991             
     992            if(module_name.equals("")) { // server-level ping                
     993                message = "Ping succeeded."; 
     994            } else { // ping at collection level 
     995                if(pingModule(module_name)) {                    
     996                    message = "Ping for " + module_name + " succeeded."; 
     997                } else { 
     998                    message = "Ping for " + module_name + " did not succeed."; 
     999                } 
     1000            } 
     1001            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message); 
    9781002            response.appendChild(s); 
    9791003        } 
    980         //if (action.equals(GSXML.SYSTEM_TYPE_ISPERSISTENT)) { 
     1004        //else if (action.equals(GSXML.SYSTEM_TYPE_ISPERSISTENT)) { 
    9811005        //  Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM,  "Persistent: true."); 
    9821006        //  response.appendChild(s);