Changeset 4349


Ignore:
Timestamp:
2003-05-27T15:16:46+12:00 (21 years ago)
Author:
jmt12
Message:

Bug fix to prevent GLI exit leaving GSDLSite.cfg in an inconsistant state - John

File:
1 edited

Legend:

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

    r4335 r4349  
    172172
    173173                // If we were given a server run it if neccessary.
    174                 startServerEXE();
     174                if(config.exec_file != null) {
     175                     startServerEXE();
     176                }
    175177
    176178                // Having loaded the configuration (necessary to determine if certain warnings have been disabled) and dictionary, we now check if the necessary path variables have been provided.
     
    320322                }
    321323          }
     324
     325          // If we started a server, we should try to stop it.
     326          if(gsdlsite_cfg != null) {
     327                stopServerEXE();
     328          }
     329
    322330          if(apps.size() == 0) {
    323                 stopServerEXE();
    324                 //try {
    325                 //   wait(200);
    326                 //}
    327                 //catch(Exception error) {
    328                 //}
    329331                System.exit(0);
    330332          }
     
    452454              else if(args[i].equals("-library") && (i + 1) < args.length) {
    453455                     exec_path = args[i+1];
     456                     // If we are on a non-windows system, and thus the local server is unavailable, we can append http:// if no protocol found.
     457                     if(exec_path.lastIndexOf(":", 5) == -1) {
     458                          exec_path = "http://" + exec_path;
     459                     }
    454460                     // If the user has given us an address, but it ends with a '/' we assume we're using the greenstone library.cgi
    455                      if(exec_path.endsWith("/")) {
     461                     if(exec_path.startsWith("http://") && exec_path.endsWith("/")) {
    456462                          exec_path = exec_path + "library";
    457463                     }
     
    668674                // First of all we create a GSDLSiteCFG object and check if a URL is already present, in which case the server is already running.
    669675                gsdlsite_cfg = new GSDLSiteConfig(config.exec_file);
    670                 if(gsdlsite_cfg.exists()) {
    671                      String url = gsdlsite_cfg.getURL();
    672                      // If its already running then set exec address.
    673                      if(url != null) {
    674                           try {
    675                                 config.exec_address = new URL(url);
    676                                 gsdlsite_cfg = null; // Don't need this anymore.
     676                String url = gsdlsite_cfg.getURL();
     677                // If its already running then set exec address.
     678                if(url != null) {
     679                     try {
     680                          config.exec_address = new URL(url);
     681                     }
     682                     catch(Exception error) {
     683                     }
     684                }
     685                // Otherwise its time to run the server in a spawned process.
     686                if(config.exec_address == null && config.exec_file.exists()) {
     687                     // Configure for immediate entry. Note that this only works if the gsdlsite.cfg file exists.
     688                     gsdlsite_cfg.set();
     689                     // Spawn server
     690                     server = new ExternalApplication(config.exec_file.getAbsolutePath());
     691                     server.start();
     692                     // Now we have to wait until program has started. We do this by reloading and checking
     693                     try {
     694                          gsdlsite_cfg.load();
     695                          while((url = gsdlsite_cfg.getURL()) == null) {
     696                                synchronized(this) {
     697                                     wait(1000);
     698                                }
     699                                gsdlsite_cfg.load();
    677700                          }
    678                           catch(Exception error) {
    679                           }
    680                      }
    681                      // Otherwise its time to run the server in a spawned process.
    682                      if(config.exec_address == null) {
    683                           // Configure for immediate entry.
    684                           gsdlsite_cfg.setAutoEnter();
    685                           // Spawn server
    686                           server = new ExternalApplication(config.exec_file.getAbsolutePath());
    687                           apps.add(server);
    688                           server.start();
    689                           // Now we have to wait until program has started. We do this by reloading and checking
    690                           try {
    691                                 gsdlsite_cfg.load();
    692                                 while((url = gsdlsite_cfg.getURL()) == null) {
    693                                     synchronized(this) {
    694                                         wait(1000);
    695                                     }
    696                                      gsdlsite_cfg.load();
    697                                 }
    698                                 // Ta-da. Now the url should be available.
    699                                 config.exec_address = new URL(url);
    700                           }
    701                           catch (Exception error) {
    702                               error.printStackTrace();
    703                           }
     701                          // Ta-da. Now the url should be available.
     702                          config.exec_address = new URL(url);
     703                     }
     704                     catch (Exception error) {
     705                          error.printStackTrace();
    704706                     }
    705707                }
    706708                // Can't do a damb thing.
    707709          }
     710          System.err.println("Having started server.exe, exec_address is: " + config.exec_address);
    708711     }
    709712
    710713    private void stopServerEXE() {
    711         // If we started the local library server, then kill it.
    712         if(server != null) {
    713             // Wait until it exits.
    714             try {
    715                 gsdlsite_cfg.load();
    716                 while(gsdlsite_cfg.getURL() != null) {
    717                     synchronized(this) {
    718                         wait(1000);
     714         // See if its already exited for some reason.
     715         gsdlsite_cfg.load();
     716         if(gsdlsite_cfg.getURL() != null) {
     717              // Send the command for it to exit.
     718              //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.QUIT_COMMAND);
     719              // Wait until it exits.
     720              try {
     721                    gsdlsite_cfg.load();
     722                    while(gsdlsite_cfg.getURL() != null) {
     723                         synchronized(this) {
     724                              wait(1000);
     725                         }
     726                         gsdlsite_cfg.load();
    719727                    }
    720                     gsdlsite_cfg.load();
    721                 }
    722             }
    723             catch (Exception error) {
    724               error.printStackTrace();
    725             }
    726             // Restore the gsdlsite_cfg
    727             if(gsdlsite_cfg != null) {
    728                 gsdlsite_cfg.restoreAutoEnter();
    729             }
    730         }
     728              }
     729              catch (Exception error) {
     730                    error.printStackTrace();
     731              }
     732         }
     733         // Restore the gsdlsite_cfg
     734         if(gsdlsite_cfg != null) {
     735              gsdlsite_cfg.restore();
     736         }
     737         gsdlsite_cfg = null;
    731738    }
    732739
Note: See TracChangeset for help on using the changeset viewer.