Changeset 5317


Ignore:
Timestamp:
2003-08-28T12:36:27+12:00 (21 years ago)
Author:
jmt12
Message:

Rewrote how jobs were added, to prevent stupid queue job then change options caused indeterminate download state

File:
1 edited

Legend:

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

    r4675 r5317  
    3838import java.awt.*;
    3939import java.io.*;
     40import java.net.*;
    4041import java.util.*;
    4142import javax.swing.*;
     
    4344import org.greenstone.gatherer.Gatherer;
    4445import org.greenstone.gatherer.collection.Job;
    45 import org.greenstone.gatherer.util.GURL;
    4646/** 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.
    4747 * @author John Thompson, Greenstone Digital Library, University of Waikato
     
    5050public class WGet
    5151    extends Thread {
     52
    5253    /** <i>true</i> if there is a task currently being carried out, <i>false</i> otherwise. */
    5354    private boolean busy = false;
     
    5657    /** <i>true</i> if successfully completed tasks should be automatically removed from the job queue. */
    5758    private boolean remove_complete_jobs = true;
    58     /** The panel that the task list will be shown it. */
     59
     60    private JPanel filler_pane = null;
     61    /** The panel that the task list will be shown in. */
    5962    private JPanel list_pane;
    6063    /** The job currently underway. */
     
    7780    job = null;
    7881    job_queue = new Vector();
     82    filler_pane = new JPanel();
    7983    list_pane = new JPanel();
    8084    list_pane.setLayout(new BoxLayout(list_pane, BoxLayout.Y_AXIS));
    81     //list_pane.setLayout(new GridLayout(1,1));
     85    //list_pane.setLayout(new GridLayout(height_count,1));
    8286    list_scroll = new JScrollPane(list_pane);
    8387    //list_scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     
    173177    if(delete_me.hasSignalledStop()) {
    174178        list_pane.remove(delete_me.getProgressBar());
     179        job_queue.remove(delete_me);
     180        // Unfortunately removing a task gets a bit more complicated as we have to resize the filler
     181        list_pane.remove(filler_pane);
     182        if(job_queue.size() > 0) {
     183        Dimension progress_bar_size = delete_me.getProgressBar().getPreferredSize();
     184        Dimension list_pane_size = list_pane.getSize();
     185        int height = list_pane_size.height - (job_queue.size() * progress_bar_size.height);
     186        progress_bar_size = null;
     187        if(height > 0) {
     188            filler_pane.setPreferredSize(new Dimension(list_pane_size.width, height));
     189            list_pane.add(filler_pane);
     190        }
     191        list_pane_size = null;
     192        }
    175193        list_pane.updateUI();
    176         job_queue.remove(delete_me);
    177194    }
    178195    else {
     
    227244
    228245    /** Creates a new mirroring job on the queue given the target url and the destination (private, public). All other details are harvested from the config file, but these two must be  captured from the GUI's current state.
    229       * @param url A <strong>GURL</strong> which points to the root url for the mirroring.
    230       * @param model The <strong>GTreeModel</strong> that any new records should be added to.
    231       * @param destination The destination file as a <strong>String</strong>.
     246      * @param url a URL which points to the root url for the mirroring
     247      * @param model the GTreeModel that any new records should be added to
     248      * @param destination the destination file as a String
    232249      * @see org.greenstone.gatherer.Configuration
    233250      * @see org.greenstone.gatherer.Gatherer
     
    236253      * @see org.greenstone.gatherer.util.GURL
    237254      */
    238     public void newJob(GURL url, TreeModel model, String destination) {
    239     if(url.valid()) {
    240                 // Create the job and fill in the details from gatherer.config.
    241         Gatherer.println("About to create a new job");
    242         Job new_job = new Job(model, Gatherer.config.get("mirroring.overwrite", false), Gatherer.config.get("mirroring.debug", false), Gatherer.config.get("mirroring.no_parents", false), Gatherer.config.get("mirroring.other_hosts", false), Gatherer.config.get("mirroring.page_requisites", false), Gatherer.config.get("mirroring.quiet", false), url, Gatherer.config.getInt("mirroring.depth", false), destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple);
    243                 // Add to job_queue job list.
    244         job_queue.add(new_job);
    245                 // Now add it to the visual component, job list.
    246         list_pane.add(new_job.getProgressBar());
    247                 //list_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
    248         list_pane.updateUI();
    249         new_job = null;
    250         synchronized(this) {
    251         notify(); // Just incase its sleeping.
    252         }
     255    public void newJob(TreeModel model, boolean overwrite, boolean no_parents, boolean other_hosts, boolean page_requisites, URL url, int depth, String destination) {
     256    // Create the job and fill in the details from gatherer.config.
     257    Gatherer.println("About to create a new job");
     258    // If it was decided not to download page requisites, then create the destination by basing it on the given destination, but appending the url host. If page requisites is used then WGet will do this for us
     259    if(!page_requisites) {
     260        destination = destination + url.getHost();
     261    }
     262    Job new_job = new Job(model, overwrite, Gatherer.config.get("mirroring.debug", false), no_parents, other_hosts, page_requisites, Gatherer.config.get("mirroring.quiet", false), url, depth, destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple);
     263    // Add to job_queue job list.
     264    job_queue.add(new_job);
     265    // Now add it to the visual component, job list.
     266    list_pane.remove(filler_pane);
     267    Dimension progress_bar_size = new_job.getProgressBar().getPreferredSize();
     268    Dimension list_pane_size = list_pane.getSize();
     269    int height = list_pane_size.height - (job_queue.size() * progress_bar_size.height);
     270    progress_bar_size = null;
     271    list_pane.add(new_job.getProgressBar());
     272    if(height > 0) {
     273        filler_pane.setPreferredSize(new Dimension(list_pane_size.width, height));
     274        list_pane.add(filler_pane);
     275    }
     276    list_pane_size = null;
     277    //list_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
     278    list_pane.updateUI();
     279    new_job = null;
     280    synchronized(this) {
     281        notify(); // Just incase its sleeping.
    253282    }
    254283    }
     
    287316        // If there are jobs job_queue and we have more room.
    288317        if(job_queue.size() > 0) {
    289         // Get the first job that isn't stopped.
    290         for(Enumeration e = job_queue.elements(); e.hasMoreElements();) {
    291             job = (Job) e.nextElement();
     318        int index = 0;
     319        while(index < job_queue.size()) {
     320            // Get the first job that isn't stopped.
     321            job = (Job) job_queue.get(index);
    292322            if(job.getState() == Job.RUNNING) {
    293323            Gatherer.println("Job " + job.toString() + " Begun.");
     
    303333            busy = false;
    304334            Gatherer.println("Job " + job.toString() + " complete.");
    305                 // And if the user has requested that complete jobs
    306                 // be removed, then remove it from the list.
    307             if(remove_complete_jobs) {
    308                 deleteJob(job);
    309             }
     335            // And if the user has requested that complete jobs
     336                // be removed, then remove it from the list.
     337            deleteJob(job);
    310338            job = null;
    311339            }
     340            index++;
    312341        }
    313342        }
Note: See TracChangeset for help on using the changeset viewer.