Changeset 31814 for main/trunk/gli/src


Ignore:
Timestamp:
2017-07-21T18:49:00+12:00 (7 years ago)
Author:
ak19
Message:

Combining the shutdown hooks for GS2 and GS3

File:
1 edited

Legend:

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

    r31813 r31814  
    380380                Configuration.setString("general.library_url", true, library_url_string);
    381381            }
    382             else { // local greenstone: Start up the local library server, if that's what we want
     382            else { // local greenstone: add shutdown hooks to forcibly stop the server on irregular termination
     383                // And start up the local library server, if that's what we want
     384
     385                // The Java virtual machine shuts down in response to two kinds of events:
     386                // - The program exits normally, when the last non-daemon thread exits or when the exit (equivalently, System.exit) method is invoked, or
     387                // - The virtual machine is terminated in response to a user interrupt, such as typing ^C, or a system-wide event, such as user logoff or system shutdown.
     388                // https://coderanch.com/t/328888/java/Killing-process-spawned-Runtime-exec
     389                // So here we add a shutdown hook to take care of Ctrl-C situations where GLI is irregularly terminated
     390                // Sadly, the shutdownhook never gets called on Windows, whether GS2 or GS3,
     391                // when a Ctrl-C is sent to the DOS prompt that launched GLI. Because GLI on Windows
     392                // currently waits to respond to a Ctrl-C until AFTER GLI is already (properly) exited
     393                Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
     394                    public void run() {
     395                   
     396                    if(Gatherer.exit != true) { // unexpected termination, such as Ctrl-C won't set Gatherer.exit
     397                        // so still need to at least issue the call to stop any running GS server
     398                       
     399                        System.err.println("ShutDownHook called...");
     400                        System.err.println("Attempting to forcibly terminate the GS server...");
     401
     402                        if (GS3) { // issue the ant call to stop any running GS3
     403                        // (tomcat and networked Derby Server) by calling GS3ServerThread.stopServer()
     404                        GS3ServerThread.stopServer();
     405                        } else { // issue the call to stop any running GS2 local library server
     406                        if (LocalLibraryServer.isRunning() == true) {
     407                            LocalLibraryServer.forceStopServer();
     408                        }
     409                        }
     410                    }
     411                    }
     412                }));
     413                   
     414               
    383415                if (!GS3) {     
    384                     isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);
    385 
    386                     // Add a shutdown hook to take care of Ctrl-C situations
    387                     // Sadly, neither the shutdownhook for GS3 nor for GS2 ever gets called on Windows
    388                     // when a Ctrl-C is sent to the DOS prompt that launched GLI:
    389                     // GLI on Windows currently waits to respond to a Ctrl-C until after GLI is already (properly) exited
    390                     Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    391                         public void run() {
    392 
    393                             if(Gatherer.exit != true) { // unexpected termination, such as Ctrl-C won't set Gatherer.exit
    394                             // so still need to at least issue the call to stop any running GS2 local library server
    395                             System.err.println("ShutDownHook called...");
    396                             System.err.println("Attempting to forcibly terminate the GS2 server...");
    397                            
    398                             if (LocalLibraryServer.isRunning() == true) {
    399                                 LocalLibraryServer.forceStopServer();
    400                             }
    401 
    402                            
    403                             } else {
    404                             System.err.println("Gatherer.exit is false");
    405                             }
    406                         }
    407                         }));
     416                    isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);               
    408417                   
    409418                }
    410                 else if (!isGsdlRemote) { // local GS3, start the local tomcat
     419                else { // local GS3, start the local tomcat
    411420                   
    412421                    GS3ServerThread thread = new GS3ServerThread(gsdl3_src_path, "restart");
    413422                    thread.start();
    414423   
    415                     // The Java virtual machine shuts down in response to two kinds of events:
    416                     // - The program exits normally, when the last non-daemon thread exits or when the exit (equivalently, System.exit) method is invoked, or
    417                     // - The virtual machine is terminated in response to a user interrupt, such as typing ^C, or a system-wide event, such as user logoff or system shutdown.
    418                     // https://coderanch.com/t/328888/java/Killing-process-spawned-Runtime-exec
    419                     Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    420                         public void run() {                         
    421 
    422                             if(Gatherer.exit != true) { // unexpected termination, such as Ctrl-C won't set Gatherer.exit
    423                             // so still need to at least issue the ant call to stop any running GS3
    424                             // (tomcat and networked Derby Server) by calling GS3ServerThread.stopServer()
    425                             System.err.println("ShutDownHook called...");
    426                             System.err.println("Attempting to forcibly terminate the GS3 server...");
    427                             GS3ServerThread.stopServer();
    428                             }
    429                         }
    430                         }));
    431                    
    432424
    433425
Note: See TracChangeset for help on using the changeset viewer.