Ignore:
Timestamp:
2017-05-18T20:38:56+12:00 (7 years ago)
Author:
ak19
Message:

Major changes to SafeProcess and classes of the download package, by bringing the final GLI (and final Greenstone) class DownloadJob over to use SafeProcess. Significant changes to SafeProcess: 1. Introduction of cancelRunningProcess as a new method, so that callers don't need to know how cancelling a process is implemented (as an interrupt) nor do they need to know what thread they ought to interrupt (which should be the thread that launched SafeProcess), nor do they need to know of the complexity surrounding the join() blocking call which should not be interrupted. 2. Introduction of the SafeProcess.MainHandler interface that provides methods that allow implementers to write hooks to various stages of the SafeProcess' internal process' life cycle. 3. moved process cleanUp() code into a reusable method within SafeProcess. Significant changes to DownloadJob and its associated DownloadProgressBar and DownloadScrollPane classes: 1. Unused member vars removed or commented out and those that can be declared final are now declared so, as a programming pricinple for thread safety, since DownloadJob and the other download classes will have to interact with multiple threads and could be called by different threads. 2. Replaced existing actionPerformed() and callDownload() of DownloadJob with SafeProcess and implemented the necessary Hooks in the SafeProcess.MainHandler() interface to ensure that perl is still told to terminate wget on a cancel action. 3. Replaced DownloadScrollPane's deleteDownloadJob() with a new version that now more responsively removes its DownloadProgressBar (with controls) for a DownloadJob. It's called by the SafeProcess.MainHandler interface hooks implemented by DownloadJob, so DownloadScrollPane no longer needs to wait() to be notify()ed when a process has cleaned up on premature termination by a cancel action. 4. Made the necessary methods in DownloadProgressBar synchronized for thread safety. 5. GShell now uses SafeProcess' new cancelRunningProcess() method in place of directly calling interrupt on the (GShell) thread that launched SafeProcess.

File:
1 edited

Legend:

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

    r18221 r31692  
    4444import javax.swing.tree.*;
    4545import org.greenstone.gatherer.*;
     46import org.greenstone.gatherer.util.SafeProcess;
    4647
    4748/** This class provides access to the functionality of the WGet program, either by calling it via a shell script or by the JNI. It maintains a queue of pending jobs, and the component for showing these tasks to the user.
     
    7879    }
    7980
    80     public void deleteDownloadJob(DownloadJob delete_me) {
     81    /**
     82     * To be used with DownloadJob.java's old_callDownload() and old_actionPerformed()
     83     * OR by uncommenting the "synchronized(this)" section in Download.java at the end of
     84     * its new callDownload() along with commenting out "mummy.deleteCurrentDownloadJob(this);"
     85     * in Download.java's doneCleanup().
     86    */
     87    public void old_deleteDownloadJob(DownloadJob delete_me) {
    8188    if (delete_me == job) {
    8289        try {
     
    8693        synchronized(delete_me) {
    8794            if (!delete_me.hasSignalledStop()) { // don't wait if DownloadJob.COMPLETED
     95            ///SafeProcess.log("**************** download scrollpane waiting for downloadjob to stop");
    8896            delete_me.wait();
    8997            }
     
    93101        }       
    94102    }
     103
     104    ///System.err.println("**************** Deleting job from download scroll pane");
    95105    // Close button pressed, get rid of this download's dedicated pane
    96106    finishedDownloadJob(delete_me, true);
    97107    }
     108
     109    /**
     110     * If called to delete the current download job, this method won't do anything.
     111     * But if called on any inactive download job, its display is removed.
     112    */
     113    public void deleteDownloadJob(DownloadJob delete_me) {
     114    if (delete_me != job) {
     115
     116        SafeProcess.log("**************** Deleting job from download scroll pane");
     117        // Close button pressed, get rid of this download's dedicated pane
     118        finishedDownloadJob(delete_me, true);
     119    } // else don't do anything, we'll be contacted again when the current job can be deleted
     120
     121    }
     122
     123    /**
     124     * To be called when we're ready to delete the current download job,
     125     * else this method won't do anything
     126    */
     127    public void deleteCurrentDownloadJob(DownloadJob delete_me) {
     128    if (delete_me == job) {
     129        SafeProcess.log("**************** Deleting current job from download scroll pane");
     130        // Close button pressed, get rid of this download's dedicated pane
     131        finishedDownloadJob(delete_me, true);
     132    }
     133    }
     134
    98135
    99136    /** To be called when a download job has terminated naturally or was prematurely stopped
Note: See TracChangeset for help on using the changeset viewer.