Changeset 7734 for trunk/gsdl/src/java


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.