Changeset 7734


Ignore:
Timestamp:
2004-07-13T10:57:05+12:00 (20 years ago)
Author:
kjdon
Message:

commiting John T's changes (c/- DL Consulting) to stop phind hanging the browser if the gsdl server goes boom

Location:
trunk/gsdl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/Phind/Phind.java

    r6269 r7734  
    9090
    9191import java.net.Socket;
     92import java.net.SocketTimeoutException;
    9293import java.net.InetAddress;
    9394import java.net.UnknownHostException;
     
    187188    //    ignored.
    188189
    189  
     190    /** We're adding a timeout to the loop used to read the result from the
     191     *  server - partially because of the 'fails to return anything' death
     192     *  spiral - but also because its a good idea anyway. Why DataInputStream
     193     *  doesn't have a TimeOutException, given its most often used to get data
     194     *  from a URL, I don't know. Lets default it to 60 seconds.
     195     *  DLConsulting 12-07-2004
     196     */
     197    private int timeout = 60;
     198
    190199    public String getAppletInfo() {
    191200    return "Phind by Gordon Paynter ([email protected]). Copyright 1997-2000.";
     
    457466    // Send the query to the phindcgi program
    458467    System.out.println("sending query: " + query);
     468    /** Start timeout counter.
     469     *  DLConsulting 12-07-2004
     470     */
     471    int time = 0;
    459472    try {
    460473        URL phindcgi = new URL(query);
     
    467480        if (availableBytes == 0) {
    468481            // if i had threads i'd do a wait here for 1 second
     482            /** Ah-ha but we do have threads here - at least one thread
     483             *  anyway! Note that we want to prevent interrupted
     484             *  exceptions flinging us out of the read loop.
     485             *  We also check that the time count hasn't reached out
     486             *  timeout threshold yet. If so, make use of the nifty
     487             *  execption handling.
     488             *  DLConsulting 12-07-2004
     489             *  Start...
     490             */
     491            if(time >= timeout) {
     492            throw new SocketTimeoutException(
     493                "No data recieved in " + time +
     494                " seconds. Connection timed-out.");
     495            }
     496            try {
     497            Thread.sleep(1000);
     498            }
     499            catch(InterruptedException exception) {
     500            System.err.println("Unexpected InterruptedException. Non-fatal.");
     501            exception.printStackTrace();
     502            }
     503            time++;
     504            /** ...End */
    469505        } else {
    470506            buffer = new byte[availableBytes];
     
    685721    // expansion_bg = parameterValue("expansion_bg", Color.white);
    686722    // document_bg = parameterValue("document_bg", Color.white);
     723
     724    /** How long should the read loop wait before timing out?
     725     *  DLConsulting 12-07-2004
     726     */
     727    timeout = parameterValue("timeout", 60);
    687728    }
    688729
     
    917958
    918959}
     960
  • trunk/gsdl/src/recpt/phindaction.cpp

    r7417 r7734  
    181181
    182182    DocNumArray result;
    183     find_phrase_number_from_word(basepath, word, result);
     183    /** In order to prevent browser crashing problems, any method which
     184     *  previously suffered a silent fatal error, now instead returns false
     185     *  to indicate a fatal error has occured. We can then dispatch an
     186     *  appropriate error tag to the Phind applet (rather than leave it
     187     *  whiling away the milliseconds until the end of existence - or at
     188     *  least your browser - in an infinite loop!)
     189     *  DLConsulting 12-07-2004
     190     */
     191    if(!find_phrase_number_from_word(basepath, word, result)) {
     192    output_error("phindaction: Fatal Error! Couldn't load index information in find_phrase_number_from_word()",
     193             textout, outconvert, disp, logout, XMLmode);
     194    return true;
     195    }
    184196   
    185197    if (result.empty()) {
     
    205217  if (!textdata.LoadData (base, fullpathc)) {
    206218    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
    207     exit (0);
     219    //exit(0);
     220    /** We must return something to the client, whether this error is fatal or
     221     *  no, otherwise we risk sending their browser into an infinite loop!
     222     *  DLConsulting 12-07-2004
     223     */
     224    output_error("phindaction: Fatal Error! Couldn't load text information for collection",
     225         textout, outconvert, disp, logout, XMLmode);
     226    return true;
    208227  }
    209228
    210229  delete []fullpathc;
    211230
    212   get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el,
    213               linkdest, linktype, docNums, docfreq);
     231  /** Another previously silent method can now cry out.
     232   *  DLConsulting 12-07-2004
     233   */
     234  if(!get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el,
     235              linkdest, linktype, docNums, docfreq)) {
     236    output_error(
     237      "phindaction: Fatal Error! Couldn't parse phrase in get_phrase_all_data()",
     238      textout, outconvert, disp, logout, XMLmode);
     239      return true;   
     240  }
    214241
    215242  // Output the header
     
    243270          << "\" start=\"" << first_l
    244271          << "\" end=\"" << last_l << "\">\n";
    245       print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
    246                 first_l, last_l, disp, outconvert, textout);
     272      /** DLConsulting 12-07-2004 */
     273      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
     274                   first_l, last_l, disp, outconvert, textout)) {
     275    output_error(
     276             "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
     277             textout, outconvert, disp, logout, XMLmode);
     278    return true;   
     279      }
    247280      textout << "</thesauruslist>\n";
    248281    }
     
    257290
    258291      textout << "<p><table border=1><tr><th>type</th><th>topic</th><th>freq</th><th>docs</th></tr>\n";
    259       print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
    260                 first_l, last_l, disp, outconvert, textout);
     292      /** DLConsulting 12-07-2004 */
     293      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
     294                   first_l, last_l, disp, outconvert, textout)) {
     295    output_error(
     296             "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
     297             textout, outconvert, disp, logout, XMLmode);
     298    return true;
     299      }
    261300      textout << "</table>\n";
    262301
     
    368407          << "\" end=\"" << last_d << "\">\n";
    369408     
    370       print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
    371               first_d, last_d, disp, outconvert, textout);
     409      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
     410              first_d, last_d, disp, outconvert, textout)) {
     411    output_error(
     412             "phindaction: Fatal Error! Couldn't load text information in print_documents() or get_document_all_data()",
     413             textout, outconvert, disp, logout, XMLmode);
     414    return true;   
     415      }
    372416
    373417      textout << "</documentlist>\n";
     
    384428
    385429      textout << "<p><table border=1><tr><th align=left>document</th><th>freq</th></tr>\n";
    386       print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
    387               first_d, last_d, disp, outconvert, textout);
     430      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
     431              first_d, last_d, disp, outconvert, textout)) {
     432    output_error(
     433             "phindaction: Fatal Error! Couldn't load text information in print_documents()",
     434             textout, outconvert, disp, logout, XMLmode);
     435    return true;
     436      }
    388437      textout << "</table>\n";
    389438     
     
    430479
    431480// Find the phrase number of a word in the index file
    432 void phindaction::find_phrase_number_from_word(const text_t &basepath,
     481bool phindaction::find_phrase_number_from_word(const text_t &basepath,
    433482                           const text_t &query,
    434483                           DocNumArray &result) {
     
    447496  if (!indexData.LoadData (base, fullpathc)) {
    448497    //    FatalError (1, "Couldn't load index information for \"%s\"", fullpathc);
    449     exit (0);
     498    //exit(0);
     499    /** Don't handle fatal errors here anymore.
     500     *  DLConsulting 12-07-2004
     501     */
     502    return false; // Indicates something very bad has happened
    450503  }
    451504
     
    478531
    479532  indexData.UnloadData();
     533
     534  /** This method now returns a boolean, so...
     535   *  DLConsulting 12-07-2004
     536   */
     537  return true; // Indicates that what happened is all good, baby.
    480538}
    481539
     
    492550//   ll - the list of phrases that are thesaurus links
    493551//   dl - the list of documents that contain phrase
    494 void phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,
     552bool phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,
    495553                      text_t &word, unsigned long &tf, unsigned long &ef,
    496554                      unsigned long &lf, unsigned long &df,
     
    507565  if (!GetDocText (textdata, docLevel, phrase, text)) {
    508566    //    FatalError (1, "Error while trying to get phrase %u", phrase);
    509     exit (0);
     567    //exit(0);
     568    return false; // Something very bad has happened.
    510569  }
    511570
     
    630689    }
    631690  }
    632 }
    633 
    634 void phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode,
     691
     692  return true; // Indicates that what happened is all good, baby.
     693}
     694
     695bool phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode,
    635696                    TextData &textdata, vector <unsigned long> &linkdest,
    636697                    vector <UCArray> &linktype, unsigned long first,
     
    647708    phrase = linkdest[l];
    648709    type = linktype[l];
    649     get_phrase_freq_data(textdata, phrase, text, tf, ef, df);
     710
     711    /** DLConsulting 12-07-2004 */
     712    if(!get_phrase_freq_data(textdata, phrase, text, tf, ef, df)) {
     713      return false;
     714    }
    650715   
    651716    if (XMLmode) {
     
    665730    }
    666731  }
     732
     733  /** DLConsulting 12-07-2004 */
     734  return true;
    667735}
    668736
     
    675743//   ef - the expansion frequency of the phrase
    676744//   df - the document frequency of the phrase
    677 void phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase,
     745/**
     746 *   Returns:
     747 *     false if the method suffered a fatal error, true otherwise
     748 */
     749bool phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase,
    678750                       UCArray &word, unsigned long &tf,
    679751                       unsigned long &ef, unsigned long &df) {
     
    686758  if (!GetDocText (textdata, docLevel, phrase, text)) {
    687759    //    FatalError (1, "Error while trying to get phrase %u", phrase);
    688     exit (0);
     760    //exit(0);
     761    /** DLConsulting 12-07-2004 */
     762    return false;
    689763  }
    690764
     
    719793    df += (*next - '0');
    720794  }
     795
     796  /** DLConsulting 12-07-2004 */
     797  return true;
    721798}
    722799
     
    844921}
    845922
    846 void phindaction::print_documents(bool XMLmode, const text_t &basepath,
     923bool phindaction::print_documents(bool XMLmode, const text_t &basepath,
    847924                  const text_t &collection,
    848925                  const vector <unsigned long> &docNums,
     
    865942  if (!docdata.LoadData (base, fullpathc)) {
    866943    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
    867     exit (0);
     944    //exit(0);
     945    /** DLConsulting 12-07-2004 */
     946    return false;
    868947  }
    869948
     
    877956    freq = docFreq[d];
    878957
    879     get_document_all_data(docdata, doc, title, hash);
     958    /** DLConsulting 13-07-2004 */
     959    if(!get_document_all_data(docdata, doc, title, hash)) {
     960      return false;
     961    }
    880962
    881963    if (XMLmode) {
     
    894976
    895977  docdata.UnloadData();
     978
     979  /** DLConsulting 12-07-2004 */
     980  return true;
    896981}
    897982
     
    902987//   title - the document's title
    903988//   hash - the document's unique OID
    904 void phindaction::get_document_all_data(TextData &docdata, unsigned long docNum,
     989/** Returns:
     990 *   false if a fatal error occured, true otherwise
     991 *  DLConsulting 12-07-2004
     992 */
     993bool phindaction::get_document_all_data(TextData &docdata, unsigned long docNum,
    905994                    UCArray &title, UCArray &hash) {
    906995
     
    9121001  if (!GetDocText (docdata, docLevel, docNum, text)) {
    9131002    //    FatalError (1, "Error while trying to get document %u", docNum);
    914     exit (0);
     1003    //exit(0);
     1004    /** DLConsulting 13-07-2004 */
     1005    return false;
    9151006  }
    9161007
     
    9311022    title.push_back(*next);
    9321023  }
     1024
     1025  /** DLConsulting 13-07-2004 */
     1026  return true;
    9331027}
    9341028
     
    9661060
    9671061#endif //GSDL_USE_PHIND_ACTION
     1062
  • trunk/gsdl/src/recpt/phindaction.h

    r7371 r7734  
    4545protected:
    4646
    47   void find_phrase_number_from_word(const text_t &basepath,
     47  bool find_phrase_number_from_word(const text_t &basepath,
    4848                    const text_t &query,
    4949                    DocNumArray &result);
    5050
    51   void get_phrase_all_data(TextData &textdata, unsigned long phrase,
     51  bool get_phrase_all_data(TextData &textdata, unsigned long phrase,
    5252               text_t &word, unsigned long &tf, unsigned long &ef,
    5353               unsigned long &lf, unsigned long &df,
     
    5858               vector <unsigned long> &docfrq);
    5959
    60   void print_thesaurus_links(const text_t &collection, bool XMLmode,
     60  bool print_thesaurus_links(const text_t &collection, bool XMLmode,
    6161                 TextData &textdata, vector <unsigned long> &linkdest,
    6262                 vector <UCArray> &linktype, unsigned long first,
     
    6464                 outconvertclass &outconvert, ostream &textout);
    6565
    66   void get_phrase_freq_data(TextData &textdata, unsigned long phrase,
     66  bool get_phrase_freq_data(TextData &textdata, unsigned long phrase,
    6767                UCArray &word, unsigned long &tf,
    6868                unsigned long &ef, unsigned long &df);
     
    8181            UCArray::const_iterator end);
    8282
    83   void print_documents(bool XMLmode, const text_t &basepath,
     83  bool print_documents(bool XMLmode, const text_t &basepath,
    8484               const text_t &collection,
    8585               const vector <unsigned long> &docNums,
     
    8989               ostream &textout);
    9090
    91   void get_document_all_data(TextData &docdata, unsigned long docNum,
     91  bool get_document_all_data(TextData &docdata, unsigned long docNum,
    9292                 UCArray &title, UCArray &hash);
    9393
     
    120120#endif //!PHINDACTION_H
    121121#endif //GSDL_USE_PHIND_ACTION
     122
Note: See TracChangeset for help on using the changeset viewer.