Changeset 4335
- Timestamp:
- 2003-05-26T16:25:32+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r4303 r4335 58 58 import org.greenstone.gatherer.msm.MetadataSetManager; 59 59 import org.greenstone.gatherer.util.ArrayTools; 60 import org.greenstone.gatherer.util.GSDLSiteConfig; 60 61 import org.greenstone.gatherer.util.Utility; 61 62 import sun.misc.*; … … 99 100 /** Extra environment information which must be set before shell processes will run properly. Should always be null if the startup script/program has done its job properly. */ 100 101 static public String extra_env[] = null; 102 private GSDLSiteConfig gsdlsite_cfg = null; 103 private ExternalApplication server = null; 101 104 /** The name of the Gatherers configuration file. */ 102 105 static private String CONFIG_FILE_NAME = "gatherer.cfg"; … … 168 171 dictionary = new Dictionary(config.getLocale("general.locale", true), config.getFont("general.font", true)); 169 172 173 // If we were given a server run it if neccessary. 174 startServerEXE(); 175 170 176 // 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. 171 177 172 178 if(config.exec_file == null && config.exec_address == null) { 173 179 missingEXEC(dictionary); … … 176 182 missingGSDL(dictionary); 177 183 } 178 // Perl path is a little different as it is perfectly ok to start the Gatherer without providing a perl path 184 // Perl path is a little different as it is perfectly ok to start the Gatherer without providing a perl path 179 185 boolean found_perl = false; 180 186 if(config.perl_path != null) { … … 301 307 config.setDimension("general.size", true, size); 302 308 } 309 303 310 // Save configuration. 304 311 saveConfig(); … … 314 321 } 315 322 if(apps.size() == 0) { 316 try { 317 wait(200); 318 } 319 catch(Exception error) { 320 } 323 stopServerEXE(); 324 //try { 325 // wait(200); 326 //} 327 //catch(Exception error) { 328 //} 321 329 System.exit(0); 322 330 } … … 444 452 else if(args[i].equals("-library") && (i + 1) < args.length) { 445 453 exec_path = args[i+1]; 454 // 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("/")) { 456 exec_path = exec_path + "library"; 457 } 446 458 } 447 459 else if(args[i].equals("-perl")) { … … 625 637 try { 626 638 config = new Configuration(gsdl_path, exec_path, perl_path); 627 } 639 } 628 640 catch (Exception error) { 629 641 Gatherer.println("config.xml is not a well formed XML document."); … … 652 664 } 653 665 666 private void startServerEXE() { 667 if(config.exec_file != null && config.exec_address == null && Utility.isWindows()) { 668 // First of all we create a GSDLSiteCFG object and check if a URL is already present, in which case the server is already running. 669 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. 677 } 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 } 704 } 705 } 706 // Can't do a damb thing. 707 } 708 } 709 710 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); 719 } 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 } 731 } 732 654 733 /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has volunteerily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */ 655 734 private class ExternalApplication 656 735 extends Thread { 736 private Process process = null; 657 737 /** The initial command string given to this sub-process. */ 658 738 private String command = null; … … 675 755 debug("Running " + command); 676 756 Runtime rt = Runtime.getRuntime(); 677 Process prcs = rt.exec(command);678 pr cs.waitFor();757 process = rt.exec(command); 758 process.waitFor(); 679 759 } 680 760 catch (Exception error) { … … 685 765 // Call exit if we were the last outstanding child process thread. 686 766 if(apps.size() == 0 && exit == true) { 767 stopServerEXE(); 687 768 System.exit(0); 688 769 } 770 } 771 public void stopExternalApplication() { 772 if(process != null) { 773 process.destroy(); 774 } 689 775 } 690 776 }
Note:
See TracChangeset
for help on using the changeset viewer.