Ignore:
Timestamp:
2019-02-28T18:40:10+13:00 (5 years ago)
Author:
ak19
Message:

The major change is that opening the coll db and oai-inf db is moved from OAIPMH.configure() into OAIPMH.configureOAI() since we don't want to end up with 2 instances of DB handles: once when the MessageRouter of the library servlet calls configure() on a collection's services including OAIPMH and once when the OAIMessageRouter of the oaiserver servlet calls configure() (before calling configureOAI()) on its OAICollections' OAIPMH services. Instead, the dbs are only opened and the handles stored once, when configureOAI() is called on OAIPMH by OAIMessageRouter when the OAIServer servlet is first visited. Minor accompanying changes are that index_stem and infodb_type need to be member vars instead of local to configure() now.

File:
1 edited

Legend:

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

    r32213 r32828  
    7171  protected HashMap<String, Element> format_meta_elem_map = null;
    7272 
     73  protected String index_stem = "";
     74  protected String infodb_type = "";
     75 
    7376  /** constructor */
    7477  public OAIPMH() {
     
    7881  public void cleanUp() {
    7982    super.cleanUp();//??
    80     this.coll_db.closeDatabase();
     83    this.coll_db.closeDatabase();
    8184    if (this.oaiinf_db != null){
    8285        this.oaiinf_db.closeDatabase();
    8386    }
    84    
    85   }
     87  }
     88 
    8689  /** configure this service
    8790  info is the OAIPMH service rack from collectionConfig.xml, and
     
    103106    // the index stem is either specified in the buildConfig.xml file (extra_info) or uses the collection name
    104107    Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    105     String index_stem = "";
    106     String infodb_type = "";
     108
    107109    if (metadata_list != null) {
    108110     
     
    110112     
    111113      if (index_stem_elem != null) {
    112     index_stem = GSXML.getNodeText(index_stem_elem);
     114    this.index_stem = GSXML.getNodeText(index_stem_elem);
    113115      }
    114116
    115117      Element infodb_type_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "infodbType");
    116118      if (infodb_type_elem != null) {
    117     infodb_type = GSXML.getNodeText(infodb_type_elem);
     119    this.infodb_type = GSXML.getNodeText(infodb_type_elem);
    118120      }
    119121
     
    121123
    122124    if (index_stem == null || index_stem.equals("")) {
    123     index_stem = this.cluster_name; // index_stem is the name of the db in indext/text, it is <colname>.<db>
     125    this.index_stem = this.cluster_name; // index_stem is the name of the db in indext/text, it is <colname>.<db>
    124126    }
    125127    if (infodb_type == null || infodb_type.equals("")) {
    126       infodb_type = "gdbm"; // the default
    127     }
    128 
    129     coll_db = new SimpleCollectionDatabase(infodb_type);
    130     if (!coll_db.databaseOK()) {
    131       logger.error("Couldn't create the collection database of type "+infodb_type);
    132       return false;
    133     }
    134 
    135     oaiinf_db = new SimpleCollectionDatabase(infodb_type);
    136     if (!oaiinf_db.databaseOK()) {
    137       logger.error("Couldn't create the oai-inf database of type "+infodb_type);
    138       return false;
    139     }
    140 
    141    
    142     // Open databases for querying
    143     String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type);
    144     if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
    145       logger.error("Could not open collection database!");
    146       return false;
    147     }
    148     // the oaiinf_db is called oai-inf.<infodb_type_extension>
    149     String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);
    150     File oaiinfFile = new File(oaiinf_db_file);
    151    
    152     if(!oaiinfFile.exists()) {
    153     logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");
    154     oaiinf_db = null;
    155     } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {
    156     logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");
    157     oaiinf_db = null;
    158     }
     128      this.infodb_type = "gdbm"; // the default
     129    }
     130
     131    // DB OPENING STUFF MOVED TO configureOAI(), because OAIPMH.configure() is called by the regular MessageRouter when this activates collections for the regular "library" servlet
     132    // whereas OAIPMH.configureOAI() is only called by OAIMessageRouter when it activates collections for the "oaiserver" servlet (after OAIMessageRouter calls regular configure() first)
     133    // We don't want the DBs opened twice: once by MessageRouter's call to OAIPMH.configure() and once by OAIMessageRouter calling OAIPMH.configure().
    159134   
    160135    // work out what sets this collection has. Will usually contain the collection itself, optional super collection, and maybe subcolls if appropriate classifiers are present.
     
    235210      format_meta_elem_map.put(prefix, OAIXML.getMetadataPrefixElement(this.desc_doc, prefix, collection_version_format));
    236211     
    237     }
     212    } // end for
     213   
     214    // Open the coll db and oai-inf db databases and store handles to them 
     215    coll_db = new SimpleCollectionDatabase(infodb_type);
     216    if (!coll_db.databaseOK()) {
     217      logger.error("Couldn't create the collection database of type "+infodb_type);
     218      return false;
     219    }
     220
     221    oaiinf_db = new SimpleCollectionDatabase(infodb_type);
     222    if (!oaiinf_db.databaseOK()) {
     223      logger.error("Couldn't create the oai-inf database of type "+infodb_type);
     224      return false;
     225    }
     226
     227   
     228    // Open databases for querying
     229    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type);
     230    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     231      logger.error("Could not open collection database!");
     232      return false;
     233    }
     234    // the oaiinf_db is called oai-inf.<infodb_type_extension>
     235    String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);
     236    File oaiinfFile = new File(oaiinf_db_file);
     237   
     238    if(!oaiinfFile.exists()) {
     239    logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");
     240    oaiinf_db = null;
     241    } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {
     242    logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");
     243    oaiinf_db = null;
     244    }
     245   
    238246    return true;
    239247  }
Note: See TracChangeset for help on using the changeset viewer.