Changeset 14538


Ignore:
Timestamp:
2007-09-18T15:10:08+12:00 (14 years ago)
Author:
qq6
Message:

if the server couldn't be connected in 10 seconds, a warning message is displayed and suggesting the user to terminate the current connecting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/greenstone3/ServletConfiguration.java

    r14323 r14538  
    4040import java.io.*;
    4141import java.lang.ref.*;
     42import java.lang.Thread;
    4243import java.net.*;
    4344import java.util.*;
     
    6566    private HashMap mappings = null;
    6667
    67     public ServletConfiguration(String gsdl3_path) {
     68    public ServletConfiguration(String gsdl3_path) throws InterruptedException {
    6869   
    6970    this.gsdl3_path = gsdl3_path;
    7071
    7172    if (Gatherer.isGsdlRemote){
    72         if (RemoteGreenstoneServer.downloadWebXMLFile().equals("")) {
    73         System.err.println("Error: Could not download web.xml.");
    74         System.exit(0);
    75         }
    76     }
     73        // if (RemoteGreenstoneServer.downloadWebXMLFile().equals("")) {
     74        //System.err.println("Error: Could not download web.xml.");
     75        //System.exit(0);
     76        //}
     77        System.out.println("Starting download web.xml.");
     78        long startTime = System.currentTimeMillis();
     79        long patience = 1000 * 10;
     80        Thread t = new Thread(new downloadWebXMl());
     81        t.start();
     82
     83        System.out.println("Waiting for download thread to finish");
     84        while (t.isAlive()) {
     85        System.out.println("Still waiting...");
     86        //Wait maximum of 1 second for MessageLoop thread to
     87            //finish.
     88        t.join(1000);
     89        if (((System.currentTimeMillis() - startTime) > patience) &&
     90                    t.isAlive()) {
     91            //t.interrupt();
     92            //Shouldn't be long now -- wait indefinitely
     93            //t.join();
     94            System.out.print("Have been waiting 10 seconds for connecting to the server, do you want to terminate the connection?(y/n)");
     95            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     96            try {
     97            if (br.readLine().toLowerCase().startsWith("y")){
     98                 System.out.println("Terminate the connection! ");
     99                 System.exit(0);
     100            }else{
     101                startTime = System.currentTimeMillis();
     102            };
     103            } catch (IOException ioe) {
     104            System.out.println("IO error trying to read your answer!");
     105            System.exit(1);
     106            }
     107        }
     108        }
     109        System.out.println("The web.xml file has been downloaded");
     110    }
     111   
    77112    //String web_xml_path = gsdl3_path + File.separator + "web" + File.separator + "WEB-INF"+ File.separator + "web.xml";
    78113    File web_xml;
     
    184219    return site;
    185220    }
     221
     222    private static class downloadWebXMl implements Runnable {
     223    public void run() {
     224        if (RemoteGreenstoneServer.downloadWebXMLFile().equals("")) {
     225        System.err.println("Error: Could not download web.xml.");
     226        System.exit(0);
     227        }
     228    }
     229    }
     230
    186231}
Note: See TracChangeset for help on using the changeset viewer.