Changeset 8620
- Timestamp:
- 2004-11-23T09:29:02+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Configuration.java
r8396 r8620 97 97 static public Configuration self = null; 98 98 99 static public File exec_file;100 99 /** The path (or url) to the webserver which is serving the Greenstone collection. */ 101 100 static public String exec_path = null; … … 163 162 } 164 163 } 165 // If the above failed, then its up to us to try and figure out what to do.166 if(exec_address == null) {167 // Try building a file from the given exec_path168 try {169 File local_file = new File(exec_path);170 if(local_file.exists()) {171 // All good. I hope.172 exec_file = local_file;173 }174 else {175 DebugStream.println("No local library at given file path.");176 }177 }178 // All sorts of errors might be thrown by a bogus file path.179 catch (Exception error) {180 DebugStream.println("Libary url does not indicate the server.exe file.");181 ///atherer.printStackTrace(error);182 }183 // We can generate the path to where the local library should be and use that if it is there.184 if(exec_file == null) {185 File server_exe = new File(gsdl_path + Utility.SERVER_EXE);186 if(server_exe.exists()) {187 exec_file = server_exe;188 }189 else {190 DebugStream.println("No local library.");191 }192 }193 // If we get to here with no exec_address nor an exec_file its just plain not going to work.194 }195 else {196 DebugStream.println("exec_address != null -> " + exec_address);197 }198 164 199 165 this.perl_path = perl_path; … … 290 256 } 291 257 } 292 DebugStream.println("EXEC_FILE = " + exec_file); 258 293 259 DebugStream.println("EXEC_ADDRESS = " + exec_address); 294 260 } -
trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r8613 r8620 49 49 import org.greenstone.gatherer.gui.URLField; 50 50 import org.greenstone.gatherer.gui.WarningDialog; 51 import org.greenstone.gatherer.util.GSDLSiteConfig;52 51 import org.greenstone.gatherer.util.StaticStrings; 53 52 import org.greenstone.gatherer.util.Utility; … … 116 115 /** the action recorder dialog */ 117 116 static public ActionRecorderDialog feedback_dialog = null; 118 /** 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. */ 119 static public String extra_env[] = null; 120 private GSDLSiteConfig gsdlsite_cfg = null; 121 private ExternalApplication server = null; 117 122 118 123 119 /** Magic to allow Enter to fire the default button. */ … … 136 132 137 133 138 public GUIManager init(Dimension size, String gsdl_path, String gsdl3_path, 134 public GUIManager init(Dimension size, String gsdl_path, String gsdl3_path, String local_library_path, 139 135 String exec_path, boolean debug_enabled, String perl_path, 140 136 boolean no_load, String open_collection, … … 143 139 String wget_path) 144 140 { 145 146 141 // This will hopefully catch ctrl-c and terminate, and exit gracefully. However it is platform specific, and may not be supported by some JVMs. 147 142 /** It does, but I get bloody sick of it working when the Gatherer hangs. … … 202 197 } 203 198 204 // If we were given a server run it if neccessary.205 if ( !GS3 && Configuration.exec_file != null) {206 startServerEXE();199 // Start up the local library server, if that's what we want 200 if (Utility.isWindows() && local_library_path != null && !GS3) { 201 LocalLibraryServer.start(gsdl_path, local_library_path); 207 202 } 208 203 209 204 // 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. 210 if ( Configuration.exec_file== null && Configuration.exec_address == null) {211 DebugStream.println(" config.exec_fileis null");205 if (local_library_path == null && Configuration.exec_address == null) { 206 DebugStream.println("local_library_path is null"); 212 207 DebugStream.println("config.exec_address is null"); 213 208 missingEXEC(); … … 433 428 434 429 // If we started a server, we should try to stop it. 435 if (!GS3 && gsdlsite_cfg != null) {436 stopServerEXE();430 if (LocalLibraryServer.isRunning() == true) { 431 LocalLibraryServer.stop(); 437 432 } 438 433 … … 445 440 JOptionPane.showMessageDialog(g_man, Dictionary.get("General.Outstanding_Processes"), Dictionary.get("General.Outstanding_Processes_Title"), JOptionPane.ERROR_MESSAGE); 446 441 g_man.setVisible(false); 447 }448 }449 450 // Used to send messages to the local library451 // Warning: this has a lot of potential for nasty race conditions452 // The response code is returned immediately -- but this does not mean the local453 // library action has finished!454 static public void configServer(String command)455 {456 try {457 String raw_url = Configuration.exec_address.toString() + command;458 URL url = new URL(raw_url);459 DebugStream.println("Action: " + raw_url);460 HttpURLConnection library_connection = (HttpURLConnection) url.openConnection();461 int response_code = library_connection.getResponseCode();462 if(HttpURLConnection.HTTP_OK <= response_code && response_code < HttpURLConnection.HTTP_MULT_CHOICE) {463 DebugStream.println("200 - Complete.");464 }465 else {466 DebugStream.println("404 - Failed.");467 }468 url = null;469 }470 catch (Exception ex) {471 DebugStream.printStackTrace(ex);472 442 } 473 443 } … … 522 492 } 523 493 } 524 494 495 496 public void spawnApplication(String command) 497 { 498 ExternalApplication app = new ExternalApplication(command); 499 apps.add(app); 500 app.start(); 501 } 502 503 525 504 /** Used to 'spawn' a new browser application or reset an existing one when the preview button is clicked 526 505 * @param url The url to open the browser at … … 681 660 } 682 661 683 private void startServerEXE() {684 if(Configuration.exec_file != null && Configuration.exec_address == null && Utility.isWindows() && !GS3) {685 // First of all we create a GSDLSiteCFG object and check if a URL is already present, in which case the server is already running.686 gsdlsite_cfg = new GSDLSiteConfig(Configuration.exec_file);687 String url = gsdlsite_cfg.getURL();688 // If its already running then set exec address.689 if(url != null) {690 try {691 Configuration.exec_address = new URL(url);692 }693 catch(Exception error) {694 }695 }696 // Otherwise its time to run the server in a spawned process.697 if(Configuration.exec_address == null && Configuration.exec_file.exists()) {698 // Configure for immediate entry. Note that this only works if the gsdlsite.cfg file exists.699 gsdlsite_cfg.set();700 // Spawn server701 String command = Configuration.exec_file.getAbsolutePath() + " " + gsdlsite_cfg.getSiteConfigFilename();702 server = new ExternalApplication(command);703 server.start();704 command = null;705 // Now we have to wait until program has started. We do this by reloading and checking706 ///ystem.err.print("Waiting until the local library has loaded");707 try {708 gsdlsite_cfg.load();709 710 int try_again = JOptionPane.YES_OPTION;711 int attempt_count = 0;712 while(gsdlsite_cfg.getURL() == null && try_again == JOptionPane.YES_OPTION) {713 ///ystem.err.print(".");714 if(attempt_count == 60) {715 attempt_count = 0;716 try_again = JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("Server.QuitTimeOut"), Dictionary.get("General.Warning"), JOptionPane.YES_NO_OPTION);717 }718 else {719 synchronized(this) {720 wait(1000); // Wait one second (give or take)721 }722 gsdlsite_cfg.load();723 attempt_count++;724 }725 }726 727 if((url = gsdlsite_cfg.getURL()) != null) {728 // Ta-da. Now the url should be available.729 Configuration.exec_address = new URL(url);730 731 // A quick test involves opening a connection to get the home page for this collection. If this fails then we try changing the url to be localhost.732 try {733 DebugStream.println("Try connecting to server on config url: '" + Configuration.exec_address + "'");734 URLConnection connection = Configuration.exec_address.openConnection();735 connection.getContent();736 }737 catch(IOException bad_url_connection) {738 try {739 DebugStream.println("Try connecting to server on local host: '" + gsdlsite_cfg.getLocalHostURL() + "'");740 Configuration.exec_address = new URL(gsdlsite_cfg.getLocalHostURL ());741 URLConnection connection = Configuration.exec_address.openConnection();742 connection.getContent();743 }744 catch(IOException worse_url_connection) {745 DebugStream.println("Can't connect to server on either address.");746 Configuration.exec_address = null;747 Configuration.exec_file = null;748 }749 }750 }751 // Unable to start local library. Show appropriate message.752 else {753 missingEXEC();754 }755 }756 catch (Exception exception) {757 DebugStream.printStackTrace(exception);758 }759 }760 // Can't do a damb thing.761 }762 DebugStream.println("Having started server.exe, exec_address is: " + Configuration.exec_address);763 }764 765 private void stopServerEXE() {766 if(server != null && Configuration.exec_address != null) {767 // See if its already exited for some reason.768 gsdlsite_cfg.load();769 if(gsdlsite_cfg.getURL() != null) {770 // Send the command for it to exit.771 configServer(GSDLSiteConfig.QUIT_COMMAND);772 // Wait until it exits.773 try {774 gsdlsite_cfg.load();775 int try_again = JOptionPane.YES_OPTION;776 int attempt_count = 0;777 while(gsdlsite_cfg.getURL() != null && try_again == JOptionPane.YES_OPTION) {778 if(attempt_count == 60) {779 attempt_count = 0;780 try_again = JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("Server.QuitTimeOut"), Dictionary.get("General.Warning"), JOptionPane.YES_NO_OPTION);781 }782 else {783 synchronized(this) {784 wait(1000); // Wait one second (give or take)785 }786 gsdlsite_cfg.load();787 attempt_count++;788 }789 }790 //if(gsdlsite_cfg.getURL() != null) {791 //JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.QuitManual"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);792 //}793 }794 catch (Exception exception) {795 DebugStream.printStackTrace(exception);796 }797 }798 // Restore the gsdlsite_cfg.799 if(gsdlsite_cfg != null) {800 gsdlsite_cfg.restore();801 }802 // If the local server is still running then our changed values will get overwritten.803 if(gsdlsite_cfg.getURL() != null) {804 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.QuitFailed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);805 }806 gsdlsite_cfg = null;807 server = null;808 }809 }810 662 811 663 // TODO fill this in … … 865 717 apps.remove(this); 866 718 // Call exit if we were the last outstanding child process thread. 867 if (apps.size() == 0 && exit == true) {868 stopServerEXE();719 if (apps.size() == 0 && exit == true) { 720 LocalLibraryServer.stop(); 869 721 System.exit(0); 870 722 } … … 953 805 apps.remove(this); 954 806 // Call exit if we were the last outstanding child process thread. 955 if (apps.size() == 0 && exit == true) {956 stopServerEXE();807 if (apps.size() == 0 && exit == true) { 808 LocalLibraryServer.stop(); 957 809 System.exit(0); 958 810 } -
trunk/gli/src/org/greenstone/gatherer/GathererApplet.java
r8250 r8620 171 171 172 172 173 g_man = gatherer.init(size, go.gsdl_path, go.gsdl3_path, 173 g_man = gatherer.init(size, go.gsdl_path, go.gsdl3_path, go.local_library_path, 174 174 go.exec_path, go.debug, go.perl_path, 175 175 go.no_load, go.filename, go.site_name, -
trunk/gli/src/org/greenstone/gatherer/GathererProg.java
r7991 r8620 108 108 Splash splash = new Splash(); 109 109 GUIManager g_man 110 = gatherer.init(size, go.gsdl_path, go.gsdl3_path, 110 = gatherer.init(size, go.gsdl_path, go.gsdl3_path, go.local_library_path, 111 111 go.exec_path, go.debug, go.perl_path, 112 112 go.no_load, go.filename, go.site_name, -
trunk/gli/src/org/greenstone/gatherer/GetOpt.java
r8618 r8620 186 186 // Parse the file path of the local library server 187 187 else if (argument_name.equals(StaticStrings.LOCAL_LIBRARY_ARGUMENT)) { 188 exec_path = argument_value; 189 // If there is no colon in first five characters of 190 // the exec_path (which would either be an existing 191 // protocol, or a windows file path to say a local 192 // library), we can append the protocol http://. 193 if(argument_value.lastIndexOf(StaticStrings.COLON_CHARACTER, 5) == -1) { 194 exec_path = StaticStrings.HTTP_PROTOCOL_STR + argument_value; 195 } 196 else { 197 exec_path = argument_value; 198 } 199 // If the user has given us an address, but it ends 200 // with a '/' we assume we're using the greenstone 201 // library.cgi 202 if(exec_path.startsWith(StaticStrings.HTTP_PROTOCOL_STR) && exec_path.endsWith(StaticStrings.URL_SEPARATOR_CHARACTER)) { 203 exec_path = exec_path + StaticStrings.LIBRARY_STR; 204 } 188 local_library_path = argument_value; 189 190 // exec_path = argument_value; 191 // // If there is no colon in first five characters of 192 // // the exec_path (which would either be an existing 193 // // protocol, or a windows file path to say a local 194 // // library), we can append the protocol http://. 195 // if(argument_value.lastIndexOf(StaticStrings.COLON_CHARACTER, 5) == -1) { 196 // exec_path = StaticStrings.HTTP_PROTOCOL_STR + argument_value; 197 // } 198 // else { 199 // exec_path = argument_value; 200 // } 201 // // If the user has given us an address, but it ends 202 // // with a '/' we assume we're using the greenstone 203 // // library.cgi 204 // if(exec_path.startsWith(StaticStrings.HTTP_PROTOCOL_STR) && exec_path.endsWith(StaticStrings.URL_SEPARATOR_CHARACTER)) { 205 // exec_path = exec_path + StaticStrings.LIBRARY_STR; 206 // } 205 207 } 206 208 // Parse the path to PERL. If not provided its assumes -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java
r8601 r8620 38 38 import org.greenstone.gatherer.Gatherer; 39 39 import org.greenstone.gatherer.GathererApplet; 40 import org.greenstone.gatherer. util.GSDLSiteConfig;40 import org.greenstone.gatherer.LocalLibraryServer; 41 41 import org.greenstone.gatherer.util.Utility; 42 42 import org.w3c.dom.*; … … 200 200 public void save() { 201 201 // Release collection as necessary 202 String collection_name = Gatherer.c_man.getCollection().getName(); 202 203 boolean collection_released = false; 203 String col_name = Gatherer.c_man.getCollection().getName();204 204 boolean formats_changed = format_manager.formatsChanged(); 205 205 206 if (formats_changed && Gatherer.c_man.built() && Configuration.exec_file != null) {206 if (formats_changed && Gatherer.c_man.built() && LocalLibraryServer.isRunning() == true) { 207 207 // Release the collection 208 Gatherer.configServer(GSDLSiteConfig.RELEASE_COMMAND + col_name); 209 // This is very important -- it ensures that the above command has finished 210 Gatherer.configServer(""); 208 LocalLibraryServer.releaseCollection(collection_name); 211 209 collection_released = true; 212 210 } … … 218 216 if (formats_changed && Gatherer.c_man.built()) { 219 217 // upload etc/collect.cfg to server to reflect changes 220 Utility.zipup(col _name,Utility.CONFIG_FILE);221 GathererApplet.upload_url_zip(col _name,"etc");218 Utility.zipup(collection_name, Utility.CONFIG_FILE); 219 GathererApplet.upload_url_zip(collection_name, "etc"); 222 220 } 223 221 } … … 226 224 if (collection_released) { 227 225 // Now re-add collection to server to force format commands to be processed 228 Gatherer.configServer(GSDLSiteConfig.ADD_COMMAND + col_name); 229 // This is very important -- it ensures that the above command has finished 230 Gatherer.configServer(""); 226 LocalLibraryServer.addCollection(collection_name); 231 227 } 232 228 -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r8606 r8620 48 48 import org.greenstone.gatherer.Dictionary; 49 49 import org.greenstone.gatherer.Gatherer; 50 import org.greenstone.gatherer.LocalLibraryServer; 50 51 import org.greenstone.gatherer.ServletConfiguration; 51 52 import org.greenstone.gatherer.cdm.CollectionDesignManager; … … 72 73 import org.greenstone.gatherer.util.ArrayTools; 73 74 import org.greenstone.gatherer.util.Codec; 74 import org.greenstone.gatherer.util.GSDLSiteConfig;75 75 import org.greenstone.gatherer.util.StaticStrings; 76 76 import org.greenstone.gatherer.util.Utility; … … 1152 1152 else if(event.getType() == GShell.BUILD && event.getStatus() == GShell.OK) { 1153 1153 if(installCollection()) { 1154 // If we have a local library running (that we know about) then we ask it to add our newly create collection 1155 if (Configuration.exec_file != null) { 1156 Gatherer.configServer(GSDLSiteConfig.ADD_COMMAND + collection.getName()); 1157 // This is very important -- it ensures that the above command has finished 1158 Gatherer.configServer(""); 1154 // If we have a local library running then ask it to add our newly create collection 1155 if (LocalLibraryServer.isRunning() == true) { 1156 LocalLibraryServer.addCollection(collection.getName()); 1159 1157 } 1160 1158 else if (Gatherer.GS3) { … … 1356 1354 try { 1357 1355 // Ensure that the local library has released this collection so we can delete the index directory 1358 if (!Gatherer.GS3 && Configuration.exec_file != null) { 1359 Gatherer.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName()); 1360 1361 // This is very important -- it ensures that the above command has finished 1362 // This prevents the nasty "could not remove index directory" race condition! 1363 Gatherer.configServer(""); 1356 if (LocalLibraryServer.isRunning() == true) { 1357 LocalLibraryServer.releaseCollection(collection.getName()); 1364 1358 } 1365 1359 -
trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java
r8597 r8620 47 47 import org.greenstone.gatherer.Dictionary; 48 48 import org.greenstone.gatherer.Gatherer; 49 import org.greenstone.gatherer.LocalLibraryServer; 49 50 import org.greenstone.gatherer.gui.GLIButton; 50 51 import org.greenstone.gatherer.gui.ModalDialog; … … 52 53 import org.greenstone.gatherer.gui.tree.WorkspaceTree; 53 54 import org.greenstone.gatherer.util.ArrayTools; 54 import org.greenstone.gatherer.util.GSDLSiteConfig;55 55 import org.greenstone.gatherer.util.StaticStrings; 56 56 import org.greenstone.gatherer.util.Utility; … … 308 308 // Delete the selected collection. 309 309 310 // first of all we must release it from the local library 311 if (Configuration.exec_file != null) { 312 Gatherer.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getShortName()); 313 // This is very important -- it ensures that the above command has finished 314 Gatherer.configServer(""); 310 // First we must release it from the local library 311 if (LocalLibraryServer.isRunning() == true) { 312 LocalLibraryServer.releaseCollection(collection.getShortName()); 315 313 } 316 314 -
trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java
r8590 r8620 56 56 import org.greenstone.gatherer.shell.GShellListener; 57 57 import org.greenstone.gatherer.util.ArrayTools; 58 import org.greenstone.gatherer.util.GSDLSiteConfig;59 58 import org.greenstone.gatherer.util.StaticStrings; 60 59 import org.greenstone.gatherer.util.Utility;
Note:
See TracChangeset
for help on using the changeset viewer.