Changeset 31446 in osm


Ignore:
Timestamp:
2015-08-04T11:35:27+02:00 (9 years ago)
Author:
nokutu
Message:

Updted build.gradle, .gitignore and uploads are now processed in a different thread.

Location:
applications/editors/josm/plugins/mapillary
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/.gitignore

    r31392 r31446  
    44/build/
    55/.gradle/
    6 
     6/.settings
    77/test/data/preferences/
  • applications/editors/josm/plugins/mapillary/build.gradle

    r31426 r31446  
    3333
    3434  packIntoJar 'com.amazonaws:aws-java-sdk-s3:1.10.8'
     35  packIntoJar 'org.apache.httpcomponents:httpmime:4.5'
    3536
    3637  testCompile 'junit:junit:4.12'
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31445 r31446  
    5656        && (int) pane.getValue() == JOptionPane.OK_OPTION) {
    5757      if (dialog.sequence.isSelected()) {
    58         try {
    59           OAuthUtils.uploadSequence(MapillaryData.getInstance().getSelectedImage().getSequence());
    60         } catch (InvalidKeyException e) {
    61           Main.error(e);
    62         } catch (UnsupportedEncodingException e) {
    63           Main.error(e);
    64         } catch (NoSuchAlgorithmException e) {
    65           Main.error(e);
    66         }
     58        OAuthUtils.uploadSequence(MapillaryData.getInstance()
     59            .getSelectedImage().getSequence());
    6760      }
    6861    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java

    r31445 r31446  
    1515import java.security.NoSuchAlgorithmException;
    1616import java.util.HashMap;
     17import java.util.List;
    1718import java.util.UUID;
     19import java.util.concurrent.ArrayBlockingQueue;
     20import java.util.concurrent.ThreadPoolExecutor;
     21import java.util.concurrent.TimeUnit;
    1822
    1923import javax.imageio.ImageIO;
     
    155159      entityBuilder.addPart(key, new StringBody(hash.get(key),
    156160          ContentType.TEXT_PLAIN));
    157       System.out.println(key + " => " + hash.get(key));
    158161    }
    159162    entityBuilder.addPart("file", new FileBody(file));
     
    162165    httpPost.setEntity(entity);
    163166
    164     System.out.println(httpPost);
    165167    HttpResponse response = httpClient.execute(httpPost);
    166     System.out.println(response.toString());
     168    if (response.getStatusLine().toString().contains("204"))
     169      System.out.println("Succesfully uploaded image");
     170    file.delete();
    167171  }
    168172
     
    177181   * @throws InvalidKeyException
    178182   */
    179   public static void uploadSequence(MapillarySequence sequence)
    180       throws InvalidKeyException, UnsupportedEncodingException,
    181       NoSuchAlgorithmException {
    182     UUID uuid = UUID.randomUUID();
    183 
    184     for (MapillaryAbstractImage img : sequence.getImages()) {
    185       if (!(img instanceof MapillaryImportedImage))
    186         throw new IllegalArgumentException(
    187             "The sequence contains downloaded images.");
     183  public static void uploadSequence(MapillarySequence sequence) {
     184    new SequenceUploadThread(sequence.getImages()).start();
     185  }
     186
     187  private static class SequenceUploadThread extends Thread {
     188    private List<MapillaryAbstractImage> images;
     189    private UUID uuid;
     190    ThreadPoolExecutor ex;
     191
     192    private SequenceUploadThread(List<MapillaryAbstractImage> images) {
     193      this.images = images;
     194      this.uuid = UUID.randomUUID();
     195      this.ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,
     196          new ArrayBlockingQueue<Runnable>(5));
     197    }
     198
     199    @Override
     200    public void run() {
     201      for (MapillaryAbstractImage img : this.images) {
     202        if (!(img instanceof MapillaryImportedImage))
     203          throw new IllegalArgumentException(
     204              "The sequence contains downloaded images.");
     205        this.ex.execute(new SingleUploadThread((MapillaryImportedImage) img,
     206            this.uuid));
     207      }
     208    }
     209  }
     210
     211  private static class SingleUploadThread extends Thread {
     212
     213    private MapillaryImportedImage image;
     214    private UUID uuid;
     215
     216    private SingleUploadThread(MapillaryImportedImage image, UUID uuid) {
     217      this.image = image;
     218      this.uuid = uuid;
     219    }
     220
     221    @Override
     222    public void run() {
    188223      try {
    189         upload((MapillaryImportedImage) img, uuid);
    190       } catch (IOException e) {
     224        OAuthUtils.upload(this.image, this.uuid);
     225      } catch (InvalidKeyException | NoSuchAlgorithmException | IOException e) {
    191226        Main.error(e);
    192227      }
     
    226261    outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat());
    227262    File tempFile = new File(c + ".tmp");
     263    c++;
    228264    OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile));
    229265
Note: See TracChangeset for help on using the changeset viewer.