Changeset 14441


Ignore:
Timestamp:
2007-09-06T10:46:11+12:00 (17 years ago)
Author:
xiao
Message:

make MGPPRetrieveWrapper a static variable; modify to make the calling of mgpp_src.getDocument() synchronized.

File:
1 edited

Legend:

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

    r13916 r14441  
    3535
    3636public class GS2MGPPRetrieve
    37     extends AbstractGS2DocumentRetrieve
    38 {
    39      static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGPPRetrieve.class.getName());
    40 
    41      // Parameters used
    42     private static final String LEVEL_PARAM = "level";
    43 
    44     // Elements used in the config file that are specific to this class
    45     private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
    46 
    47     private MGPPWrapper mgpp_src = null;
    48    
    49     private String default_level = null;
    50     private String mgpp_textdir = null;
    51    
    52     public GS2MGPPRetrieve() {
    53     this.mgpp_src = new MGPPWrapper();
     37  extends AbstractGS2DocumentRetrieve {
     38  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGPPRetrieve.class.getName());
     39 
     40  // Parameters used
     41  private static final String LEVEL_PARAM = "level";
     42 
     43  // Elements used in the config file that are specific to this class
     44  private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
     45 
     46  private static MGPPRetrieveWrapper mgpp_src = null;
     47 
     48  private String default_level = null;
     49  private String mgpp_textdir = null;
     50 
     51  public GS2MGPPRetrieve() {
     52    if(mgpp_src == null) {
     53      mgpp_src = new MGPPRetrieveWrapper();
    5454    }
    55 
    56     public void cleanUp() {
    57     super.cleanUp();
    58     this.mgpp_src.unloadIndexData();
    59     }
    60 
    61     /** configure this service */
    62     public boolean configure(Element info, Element extra_info)
    63     {
    64     if (!super.configure(info, extra_info)){
    65         return false;
    66     }
    67 
    68     // Do specific configuration
    69     logger.info("Configuring GS2MGPPRetrieve...");
    70 
    71     // Get the default level out of <defaultLevel> (buildConfig.xml)
    72     Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
    73     if (def != null) {
    74         this.default_level = def.getAttribute(GSXML.SHORTNAME_ATT);
    75     }
    76     if (this.default_level == null || this.default_level.equals("")) {
    77         logger.error("default level not specified!");
    78         return false;
    79     }
    80    
    81     // The location of the MGPP text files
    82     mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
    83         File.separatorChar + GSFile.collectionTextPath(this.index_stem);
    84 
    85     // Do generic configuration
    86     return true;
    87  
     55  }
     56 
     57  public void cleanUp() {
     58    super.cleanUp();
     59    mgpp_src.unloadIndexData();
     60  }
     61 
     62  /** configure this service */
     63  public boolean configure(Element info, Element extra_info) {
     64    if (!super.configure(info, extra_info)){
     65      return false;
    8866    }
    8967   
    90     /** returns the content of a node
    91      * should return a nodeContent element:
    92      * <nodeContent>text content or other elements</nodeContent>
    93      */
    94     protected Element getNodeContent(String doc_id, String lang) throws GSException {
    95     long doc_num = this.gdbm_src.OID2Docnum(doc_id);
    96     if (doc_num == -1) {
    97         logger.error("OID "+doc_id +" couldn't be converted to mgpp num");
    98         return null;
    99     }
    100     Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
    101    
    102     String doc_content = "";
    103     try {
    104         doc_content = this.mgpp_src.getDocument(this.mgpp_textdir,
    105                             this.default_level,
    106                             doc_num);
    107         if (doc_content != null) {
    108         doc_content = resolveTextMacros(doc_content, doc_id, lang);
    109         }
    110     } catch (Exception e) {
    111         logger.info("exception happended with mgpp_src.getDocument()" + e);
    112         doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n";
    113 
    114     }
    115     Text t = this.doc.createTextNode(doc_content);
    116     content_node.appendChild(t);
    117     return content_node;
    118 
     68    // Do specific configuration
     69    logger.info("Configuring GS2MGPPRetrieve...");
     70   
     71    // Get the default level out of <defaultLevel> (buildConfig.xml)
     72    Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
     73    if (def != null) {
     74      this.default_level = def.getAttribute(GSXML.SHORTNAME_ATT);
    11975    }
    120 
    121 
     76    if (this.default_level == null || this.default_level.equals("")) {
     77      logger.error("default level not specified!");
     78      return false;
     79    }
     80   
     81    // The location of the MGPP text files
     82    mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
     83      File.separatorChar + GSFile.collectionTextPath(this.index_stem);
     84   
     85    // Do generic configuration
     86    return true;
     87   
     88  }
     89 
     90  /** returns the content of a node
     91   * should return a nodeContent element:
     92   * <nodeContent>text content or other elements</nodeContent>
     93   */
     94  protected Element getNodeContent(String doc_id, String lang) throws GSException {
     95    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
     96    if (doc_num == -1) {
     97      logger.error("OID "+doc_id +" couldn't be converted to mgpp num");
     98      return null;
     99    }
     100    Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
     101    synchronized (mgpp_src) {
     102        String doc_content = "";
     103        try {
     104           
     105            doc_content = mgpp_src.getDocument(this.mgpp_textdir,
     106                    this.default_level,
     107                    doc_num);
     108           
     109            if (doc_content != null) {
     110                doc_content = resolveTextMacros(doc_content, doc_id, lang);
     111            }
     112           
     113        } catch (Exception e) {
     114            logger.info("exception happended with mgpp_src.getDocument()" + e);
     115            doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n";
     116           
     117        }
     118        Text t = this.doc.createTextNode(doc_content);
     119        content_node.appendChild(t);
     120        return content_node;
     121    }//end of synchronized
     122  }
     123 
     124 
    122125}
Note: See TracChangeset for help on using the changeset viewer.