Ignore:
Timestamp:
2017-05-01T18:23:39+12:00 (7 years ago)
Author:
ak19
Message:

Rewriting GShell.runLocal() to use SafeProcess instead of Process. This required overhaul of SafeProcess to correctly deal with interrupts as the build/import process launched in GShell can be cancelled from the CreatePane. SafeProcess now also keeps track of its internal process object and has static logging methods to simplify the changes required when swapping between the GS3 version and GS2 version of SafeProcess. May eventually call DebugStream methods from the log methods for GLI. Will add a DEBUG flag to allow verbose logging.

File:
1 edited

Legend:

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

    r29711 r31638  
    156156    public String homepage = null;
    157157
     158    /** Access to the GShell object that this CreatePane listens to events for.
     159     * A handle to the GShell is needed order to interrupt any processes the GShell runs
     160     * when the user cancels a build operation.
     161    */
     162    private GShell shell = null;
     163
    158164    /** The constructor creates important helper classes, and initializes all the components.
    159165     * @see org.greenstone.gatherer.collection.CollectionManager
     
    291297    }
    292298
     299    public void setGShell(GShell shell) {
     300    this.shell = shell;
     301    }
    293302
    294303    public void destroy() {
     
    840849    private class CancelButtonListener
    841850    implements ActionListener {
    842     /** This method attempts to cancel the current GShell task. It does this by first telling CollectionManager not to carry out any further action. This it turn tells the GShell to break from the current job immediately, without waiting for the processEnded message, and then kills the thread in an attempt to stop the process. The results of such an action are debatable.
     851    /** This method attempts to cancel the current GShell task. It does this by first telling CollectionManager not to carry out any further action.
     852     * Previously, this would in turn tell the GShell to break from the current job immediately, without waiting for the processEnded message, and then kills the thread in an attempt to stop the process. The results of such an action are debatable.
     853     * Now, pressing cancel will send an interrupt to the GShell thread, which is the thread in which the external process is run (via the SafeProcess object). Interrupting a running SafeProcess will then interrupt any worker threads and destroy the process, with SafeProcess cleaning up after itself after its worker threads finished cleaning up after themselves. Tested on Linux.
    843854     * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
    844855     * @see org.greenstone.gatherer.Gatherer
     
    867878        build_monitor.setStop(true);
    868879        build_monitor.reset();
     880        // Tell the GShell to cleanly stop running its external process
     881        if(CreatePane.this.shell != null) {
     882        // We can call GShell.cancel() even if the GShell thread is blocking when running a process,
     883        // because this CreatePane is running in its own separate GUI thread. This is because the
     884        // process blocking call (process.waitFor()) and cancel() are not sequential operations.
     885        CreatePane.this.shell.cancel();
     886        }
    869887
    870888        // Remove the collection lock.
Note: See TracChangeset for help on using the changeset viewer.