Changeset 31473 in osm for applications/editors


Ignore:
Timestamp:
2015-08-10T12:42:05+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed bug with upload. ThreadPoolExecutor was rejecting more than 5 uploads.
Added a dialog that is shown when all the downloads are finished.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31456 r31473  
    145145      if (lat_ref == null || lat == null || lon == null || lon_ref == null
    146146          || datetimeOriginal == null)
    147         throw new IllegalArgumentException(
    148             "The picture has not correct EXIF tags");
     147        return;
    149148
    150149      double latValue = 0;
     
    182181
    183182  /**
    184    * Comparator that comperes two {@link MapillaryAbstractImage} objects
     183   * Comparator that compares two {@link MapillaryAbstractImage} objects
    185184   * depending on the time they were taken.
    186185   *
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31472 r31473  
    4949  public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    5050  /** Executor that will run the petitions. */
    51   private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
    52       100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50));
     51  private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
     52      new ArrayBlockingQueue<Runnable>(100));;
    5353
    5454  /**
     
    229229      EXECUTOR.awaitTermination(30, TimeUnit.SECONDS);
    230230    } catch (InterruptedException e) {
    231       // TODO Auto-generated catch block
    232       e.printStackTrace();
     231      Main.error(e);
    233232    }
    234233    EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
    235         new ArrayBlockingQueue<Runnable>(50));
     234        new ArrayBlockingQueue<Runnable>(100));
    236235  }
    237236}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31454 r31473  
    1111import java.awt.event.ActionListener;
    1212import java.awt.event.MouseEvent;
    13 import java.io.IOException;
    1413import java.net.MalformedURLException;
    15 import java.net.URISyntaxException;
    1614import java.net.URL;
    1715
     
    2321import org.openstreetmap.josm.Main;
    2422import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    25 
    26 import java.awt.Desktop;
     23import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2724
    2825/**
     
    176173    if (this.url == null)
    177174      return;
    178     Desktop desktop = Desktop.getDesktop();
    179     if (desktop.isSupported(Desktop.Action.BROWSE)) {
    180       try {
    181         desktop.browse(this.url.toURI());
    182       } catch (IOException | URISyntaxException e1) {
    183         Main.error(e1);
    184       }
    185     } else {
    186       Runtime runtime = Runtime.getRuntime();
    187       try {
    188         runtime.exec("xdg-open " + this.url);
    189       } catch (IOException exc) {
    190         exc.printStackTrace();
    191       }
    192     }
     175    MapillaryUtils.browse(this.url);
    193176  }
    194177}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31465 r31473  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.Desktop;
    65import java.awt.FlowLayout;
    76import java.awt.event.ActionEvent;
    8 import java.io.IOException;
    9 import java.net.URI;
    10 import java.net.URISyntaxException;
     7import java.net.MalformedURLException;
     8import java.net.URL;
    119
    1210import javax.swing.AbstractAction;
     
    2523import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    2624import org.openstreetmap.josm.plugins.mapillary.oauth.OAuthPortListener;
     25import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2726
    2827/**
     
    146145
    147146      String url = "http://www.mapillary.com/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&response_type=token&scope=user:read%20public:upload%20public:write";
    148       Desktop desktop = Desktop.getDesktop();
    149       if (desktop.isSupported(Desktop.Action.BROWSE)) {
    150         try {
    151           desktop.browse(new URI(url));
    152         } catch (IOException | URISyntaxException e1) {
    153           Main.error(e1);
    154         }
    155       } else {
    156         Runtime runtime = Runtime.getRuntime();
    157         try {
    158           runtime.exec("xdg-open " + url);
    159         } catch (IOException exc) {
    160           exc.printStackTrace();
    161         }
     147      try {
     148        MapillaryUtils.browse(new URL(url));
     149      } catch (MalformedURLException e) {
     150        Main.error(e);
    162151      }
    163152    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31457 r31473  
    125125    HttpEntity entity = entityBuilder.build();
    126126    httpPost.setEntity(entity);
    127 
    128127    HttpResponse response = httpClient.execute(httpPost);
    129128    if (response.getStatusLine().toString().contains("204")) {
    130129      PluginState.imageUploaded();
    131     }
     130      Main.info(PluginState.getUploadString() + " (Mapillary)");
     131    } else
     132      Main.info("Upload error");
    132133    file.delete();
    133134    MapillaryUtils.updateHelpText();
     
    153154      this.images = images;
    154155      this.uuid = UUID.randomUUID();
    155       this.ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,
    156           new ArrayBlockingQueue<Runnable>(5));
     156      this.ex = new ThreadPoolExecutor(1, 1, 25, TimeUnit.SECONDS,
     157          new ArrayBlockingQueue<Runnable>(100));
    157158    }
    158159
    159160    @Override
    160161    public void run() {
    161       PluginState.startUpload();
    162162      PluginState.imagesToUpload(this.images.size());
    163163      MapillaryUtils.updateHelpText();
     
    168168        this.ex.execute(new SingleUploadThread((MapillaryImportedImage) img,
    169169            this.uuid));
     170        while (this.ex.getQueue().remainingCapacity() == 0)
     171          try {
     172            Thread.sleep(100);
     173          } catch (InterruptedException e) {
     174            Main.error(e);
     175          }
    170176      }
    171177      this.ex.shutdown();
    172       PluginState.finishUpload();
    173178    }
    174179  }
     
    187192    public void run() {
    188193      upload(this.image, this.uuid);
    189 
    190194    }
    191195  }
     
    212216    TiffOutputDirectory gpsDirectory = null;
    213217    // If the image is imported, loads the rest of the EXIF data.
    214     ImageMetadata metadata = Imaging.getMetadata(image.getFile());
    215     final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     218    JpegImageMetadata jpegMetadata = null;
     219    try {
     220      ImageMetadata metadata = Imaging.getMetadata(image.getFile());
     221      jpegMetadata = (JpegImageMetadata) metadata;
     222    } catch (Exception e) {
     223    }
    216224    if (null != jpegMetadata) {
    217225      final TiffImageMetadata exif = jpegMetadata.getExif();
     
    239247
    240248    outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat());
    241     File tempFile = new File(c + ".tmp");
     249    File tempFile = File.createTempFile("imagetoupload_" + c, ".tmp");
    242250    c++;
    243251    OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31457 r31473  
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.Desktop;
     6import java.io.IOException;
     7import java.net.URISyntaxException;
     8import java.net.URL;
    49
    510import org.apache.commons.imaging.common.RationalNumber;
     
    9196    return result;
    9297  }
     98
     99  /**
     100   * @param url
     101   */
     102  public static void browse(URL url) {
     103    Desktop desktop = Desktop.getDesktop();
     104    if (desktop.isSupported(Desktop.Action.BROWSE)) {
     105      try {
     106        desktop.browse(url.toURI());
     107      } catch (IOException | URISyntaxException e1) {
     108        Main.error(e1);
     109      }
     110    } else {
     111      Runtime runtime = Runtime.getRuntime();
     112      try {
     113        runtime.exec("xdg-open " + url);
     114      } catch (IOException exc) {
     115        exc.printStackTrace();
     116      }
     117    }
     118  }
    93119}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java

    r31449 r31473  
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.Dimension;
     6
     7import javax.swing.JDialog;
     8import javax.swing.JOptionPane;
     9import javax.swing.SwingUtilities;
     10
     11import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.plugins.mapillary.gui.FinishedUploadDialog;
    413
    514/**
     
    1019
    1120  private static int runningDownloads = 0;
    12   private static int runningUploads = 0;
    13   private static int imagesToUpload = 0;
    14   private static int imagesUploaded = 0;
     21  /** Images that have to be uploaded. */
     22  public static int imagesToUpload = 0;
     23  /** Images that have been uploaded. */
     24  public static int imagesUploaded = 0;
    1525
    1626  /**
     
    3848
    3949  /**
    40    * Called when an upload is starting.
    41    */
    42   public static void startUpload() {
    43     runningUploads++;
    44   }
    45 
    46   /**
    4750   * Called when an upload is finished.
    4851   */
    4952  public static void finishUpload() {
    50     runningUploads--;
    5153    if (imagesUploaded >= imagesToUpload) {
    5254      imagesUploaded = 0;
     
    6163   */
    6264  public static boolean isUploading() {
    63     return runningUploads > 0;
     65    return imagesToUpload > imagesUploaded;
    6466  }
    6567
     
    7981  public static void imageUploaded() {
    8082    imagesUploaded++;
     83    if (imagesToUpload == imagesUploaded) {
     84      finishedUploadDialog();
     85    }
     86  }
     87
     88  private static void finishedUploadDialog() {
     89    if (!SwingUtilities.isEventDispatchThread()) {
     90      SwingUtilities.invokeLater(new Runnable() {
     91        @Override
     92        public void run() {
     93          finishedUploadDialog();
     94        }
     95      });
     96    } else {
     97      JOptionPane pane = new JOptionPane();
     98      pane.setMessage(new FinishedUploadDialog());
     99      JDialog dlg = pane.createDialog(Main.parent, tr("Finished upload"));
     100      dlg.setVisible(true);
     101    }
    81102  }
    82103
     
    87108   */
    88109  public static String getUploadString() {
    89     return tr("Downloading: {0}", "(" + imagesUploaded + "/" + imagesToUpload
     110    return tr("Uploading: {0}", "(" + imagesUploaded + "/" + imagesToUpload
    90111        + ")");
    91112  }
Note: See TracChangeset for help on using the changeset viewer.