Changeset 14431

Show
Ignore:
Timestamp:
06.09.2007 10:40:09 (12 years ago)
Author:
xiao
Message:

make MGRetrieveWrapper a static variable; modify to make the calling of mg_src.getDocument() synchronized.

Files:
1 modified

Legend:

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

    r14000 r14431  
    3535 
    3636public class GS2MGRetrieve 
    37     extends AbstractGS2DocumentRetrieve 
    38 { 
    39    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGRetrieve.class.getName()); 
    40  
     37extends AbstractGS2DocumentRetrieve { 
     38    static Logger logger = Logger.getLogger (org.greenstone.gsdl3.service.GS2MGRetrieve.class.getName ()); 
     39     
    4140    // Elements used in the config file that are specific to this class 
    4241    private static final String DEFAULT_INDEX_ELEM = "defaultIndex"; 
     
    4544    private static final String DEFAULT_INDEX_SUBCOLLECTION_ELEM = "defaultIndexSubcollection"; 
    4645    private static final String DEFAULT_INDEX_LANGUAGE_ELEM = "defaultIndexLanguage"; 
    47    
    48     private MGWrapper mg_src = null; 
     46     
     47    private MGRetrieveWrapper mg_src = null; 
     48//    private MGWrapper mg_src = null; 
     49     
    4950    private String mg_basedir = null; 
    5051    private String mg_textdir = null; 
    5152    private String default_index = null; 
    5253    private boolean has_default_index = false; 
    53      
    54     public GS2MGRetrieve() { 
    55     this.mg_src = new MGWrapper(); 
     54     
     55    public GS2MGRetrieve () { 
     56        this.mg_src = new MGRetrieveWrapper (); 
    5657    } 
    57  
    58     public void cleanUp() { 
    59     super.cleanUp(); 
    60     this.mg_src.unloadIndexData(); 
     58     
     59    public void cleanUp () { 
     60        super.cleanUp (); 
     61        this.mg_src.unloadIndexData (); 
    6162    } 
    62  
     63     
    6364    /** configure this service */ 
    64     public boolean configure(Element info, Element extra_info) 
    65     { 
    66     if (!super.configure(info, extra_info)){ 
    67         return false; 
    68     } 
    69      
    70     // Do specific configuration 
    71     logger.info("Configuring GS2MGRetrieve..."); 
    72      
    73     // Get the default index out of <defaultIndex> (buildConfig.xml) 
    74     Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_ELEM); 
    75     if (def != null) { 
    76         this.default_index = def.getAttribute(GSXML.SHORTNAME_ATT); 
    77     } 
    78          Element defSub = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_SUBCOLLECTION_ELEM);  
    79     if (defSub != null) { 
    80         this.default_index += defSub.getAttribute(GSXML.SHORTNAME_ATT); 
    81         logger.info("default indexSubcollection is "+defSub.getAttribute(GSXML.SHORTNAME_ATT));       
    82     } //concate defaultIndex + defaultIndexSubcollection 
    83  
    84     //get the default indexLanguage out of <defaultIndexLanguage> (buildConfig.xml) 
    85         Element defLang = (Element) GSXML.getChildByTagName(info, DEFAULT_INDEX_LANGUAGE_ELEM);  
    86     if (defLang != null) { 
    87         this.default_index += defLang.getAttribute(GSXML.SHORTNAME_ATT); 
    88             logger.info("default indexLanguage is "+defLang.getAttribute(GSXML.SHORTNAME_ATT));  
    89     } //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage 
    90       
    91  
    92     if (this.default_index == null || this.default_index.equals("")) { 
    93              logger.error("default index is not specified, the content of a document will not be retrieved"); 
    94               has_default_index = false; 
    95           return true; 
    96         //} 
    97     } 
    98     logger.debug("Default index: " + this.default_index); 
    99         
    100     // The location of the MG index and text files 
    101     mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG 
    102     mg_textdir = GSFile.collectionTextPath(this.index_stem); 
    103     // index is only needed to start up MG, not used so just use the default index 
    104     String indexpath = GSFile.collectionIndexPath(this.index_stem, this.default_index); 
    105     this.mg_src.setIndex(indexpath); 
    106     has_default_index = true; 
    107     return true; 
     65    public boolean configure (Element info, Element extra_info) { 
     66        if (!super.configure (info, extra_info)){ 
     67            return false; 
     68        } 
     69         
     70        // Do specific configuration 
     71        logger.info ("Configuring GS2MGRetrieve..."); 
     72         
     73        // Get the default index out of <defaultIndex> (buildConfig.xml) 
     74        Element def = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_ELEM); 
     75        if (def != null) { 
     76            this.default_index = def.getAttribute (GSXML.SHORTNAME_ATT); 
     77        } 
     78        Element defSub = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_SUBCOLLECTION_ELEM); 
     79        if (defSub != null) { 
     80            this.default_index += defSub.getAttribute (GSXML.SHORTNAME_ATT); 
     81            logger.info ("default indexSubcollection is "+defSub.getAttribute (GSXML.SHORTNAME_ATT)); 
     82        } //concate defaultIndex + defaultIndexSubcollection 
     83         
     84        //get the default indexLanguage out of <defaultIndexLanguage> (buildConfig.xml) 
     85        Element defLang = (Element) GSXML.getChildByTagName (info, DEFAULT_INDEX_LANGUAGE_ELEM); 
     86        if (defLang != null) { 
     87            this.default_index += defLang.getAttribute (GSXML.SHORTNAME_ATT); 
     88            logger.info ("default indexLanguage is "+defLang.getAttribute (GSXML.SHORTNAME_ATT)); 
     89        } //concate defaultIndex + defaultIndexSubcollection + defaultIndexLanguage 
     90         
     91         
     92        if (this.default_index == null || this.default_index.equals ("")) { 
     93            logger.error ("default index is not specified, the content of a document will not be retrieved"); 
     94            has_default_index = false; 
     95            return true; 
     96            //} 
     97        } 
     98        logger.debug ("Default index: " + this.default_index); 
     99         
     100        // The location of the MG index and text files 
     101        mg_basedir = GSFile.collectionBaseDir (this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG 
     102        mg_textdir = GSFile.collectionTextPath (this.index_stem); 
     103        // index is only needed to start up MG, not used so just use the default index 
     104        String indexpath = GSFile.collectionIndexPath (this.index_stem, this.default_index); 
     105        this.mg_src.setIndex (indexpath); 
     106        has_default_index = true; 
     107        return true; 
    108108    } 
    109109     
     
    112112     * <nodeContent>text content or other elements</nodeContent> 
    113113     */ 
    114     protected Element getNodeContent(String doc_id, String lang) throws GSException { 
    115     long doc_num = this.gdbm_src.OID2Docnum(doc_id); 
    116     if (doc_num == -1) { 
    117         logger.error("OID "+doc_id +" couldn't be converted to mg num"); 
    118         return null; 
    119     } 
    120     Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM); 
    121      
    122           
    123     String doc_content = null; 
    124  
    125         //means that this.mg_src is up and running   
    126     if (has_default_index ){ 
    127             doc_content =  this.mg_src.getDocument(this.mg_basedir, 
    128                          this.mg_textdir, doc_num); 
    129     } 
    130   
    131     if (doc_content!=null) { 
    132         // remove any ctrl-c or ctrl-b  
    133         doc_content = doc_content.replaceAll("\u0002|\u0003", ""); 
    134         // replace _httpimg_ with the correct address 
    135         doc_content = resolveTextMacros(doc_content, doc_id, lang); 
    136         //GSXML.addDocText(this.doc, doc, doc_content); 
    137     } else { 
    138         logger.error("the doc content was null, not getting that section\n"); 
    139         doc_content = "couldn't retrieve content for this section, please check the log file for more detail\n"; 
    140     } 
    141     Text t = this.doc.createTextNode(doc_content); 
    142     content_node.appendChild(t); 
    143     return content_node; 
    144  
     114    protected Element getNodeContent (String doc_id, String lang) throws GSException { 
     115        long doc_num = this.gdbm_src.OID2Docnum (doc_id); 
     116        if (doc_num == -1) { 
     117            logger.error ("OID "+doc_id +" couldn't be converted to mg num"); 
     118            return null; 
     119        } 
     120        Element content_node = this.doc.createElement (GSXML.NODE_CONTENT_ELEM); 
     121         
     122         
     123        String doc_content = null; 
     124         
     125        //means that this.mg_src is up and running 
     126        if (has_default_index ){ 
     127            doc_content =  this.mg_src.getDocument (this.mg_basedir, 
     128            this.mg_textdir, doc_num); 
     129        } 
     130         
     131        if (doc_content!=null) { 
     132            // remove any ctrl-c or ctrl-b 
     133            doc_content = doc_content.replaceAll ("\u0002|\u0003", ""); 
     134            // replace _httpimg_ with the correct address 
     135            doc_content = resolveTextMacros (doc_content, doc_id, lang); 
     136            //GSXML.addDocText(this.doc, doc, doc_content); 
     137        } else { 
     138            logger.error ("the doc content was null, not getting that section\n"); 
     139            doc_content = "couldn't retrieve content for this section, please check the log file for more detail\n"; 
     140        } 
     141        Text t = this.doc.createTextNode (doc_content); 
     142        content_node.appendChild (t); 
     143        return content_node; 
     144         
    145145    } 
    146  
    147  
     146     
     147     
    148148}