Ignore:
Timestamp:
27.10.2009 01:21:32 (3 years ago)
Author:
Gubaer
Message:

Cleanup in download logic (less global, more encapsulation)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java

    r2322 r2327  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.util.ArrayList; 
    67import java.util.LinkedHashSet; 
     8import java.util.List; 
    79import java.util.concurrent.Future; 
    810 
     
    1618public class PostDownloadHandler implements Runnable { 
    1719    private DownloadTask task; 
    18     private Future<?> future; 
     20    private List<Future<?>> futures; 
    1921 
    2022    /** 
     
    2527    public PostDownloadHandler(DownloadTask task, Future<?> future) { 
    2628        this.task = task; 
    27         this.future = future; 
     29        this.futures = new ArrayList<Future<?>>(); 
     30        if (future != null) { 
     31            this.futures.add(future); 
     32        } 
    2833    } 
    2934 
     35    /** 
     36     * constructor 
     37     * @param task the asynchronous download task 
     38     * @param future the future on which the completion of the download task can be synchronized 
     39     */ 
     40    public PostDownloadHandler(DownloadTask task, Future<?> ... futures) { 
     41        this.task = task; 
     42        this.futures = new ArrayList<Future<?>>(); 
     43        if (futures == null) return; 
     44        for (Future<?> future: futures) { 
     45            this.futures.add(future); 
     46        } 
     47    } 
     48     
     49 
     50    /** 
     51     * constructor 
     52     * @param task the asynchronous download task 
     53     * @param future the future on which the completion of the download task can be synchronized 
     54     */ 
     55    public PostDownloadHandler(DownloadTask task, List<Future<?>> futures) { 
     56        this.task = task; 
     57        this.futures = new ArrayList<Future<?>>(); 
     58        if (futures == null) return; 
     59        this.futures.addAll(futures); 
     60    } 
     61     
    3062    public void run() { 
    31         // wait for the download task to complete 
     63        // wait for all downloads task to finish (by waiting for the futures 
     64        // to return a value) 
    3265        // 
    33         try { 
    34             future.get(); 
    35         } catch(Exception e) { 
    36             e.printStackTrace(); 
    37             return; 
     66        for (Future<?> future: futures) { 
     67            try { 
     68                future.get(); 
     69            } catch(Exception e) { 
     70                e.printStackTrace(); 
     71                return; 
     72            } 
    3873        } 
    3974 
Note: See TracChangeset for help on using the changeset viewer.