Ignore:
Timestamp:
2015-07-24T21:55:14+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed #11716. Concurrency bug related with semiautomatic mode when closing the layer

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/build.gradle

    r31395 r31404  
    138138
    139139task runJosm(type: Exec) {
    140  commandLine 'josm'
     140 commandLine 'java', '-jar', '/home/nokutu/josm/core/dist/josm-custom.jar'
    141141}
    142142runJosm.dependsOn installPluginToJosm
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31401 r31404  
    2929  private final List<MapillaryAbstractImage> multiSelectedImages;
    3030
    31   private List<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
     31  private CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
    3232
    3333  /**
     
    5252    }
    5353    return INSTANCE;
     54  }
     55
     56  /**
     57   * Destroys the unique instance.
     58   */
     59  public void destroy() {
     60    INSTANCE = null;
    5461  }
    5562
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31401 r31404  
    5454import java.util.List;
    5555import java.util.ArrayList;
     56import java.util.concurrent.CopyOnWriteArrayList;
    5657
    5758/**
     
    8384
    8485  /** The bounds of the areas for which the pictures have been downloaded */
    85   public ArrayList<Bounds> bounds;
     86  public CopyOnWriteArrayList<Bounds> bounds;
    8687
    8788  /** Mode of the layer */
     
    9899    super(tr("Mapillary Images"));
    99100    data = MapillaryData.getInstance();
    100     bounds = new ArrayList<>();
     101    bounds = new CopyOnWriteArrayList<>();
    101102    init();
    102103  }
     
    120121        MapillaryMainDialog.getInstance().getButton().doClick();
    121122    }
    122 
    123123    createHatchTexture();
    124124    data.dataUpdated();
     
    138138    }
    139139    this.mode = mode;
    140     Main.map.mapView.setNewCursor(mode.cursor, this);
    141     Main.map.mapView.addMouseListener(mode);
    142     Main.map.mapView.addMouseMotionListener(mode);
    143     NavigatableComponent.addZoomChangeListener(mode);
    144     updateHelpText();
     140    if (mode != null) {
     141      Main.map.mapView.setNewCursor(mode.cursor, this);
     142      Main.map.mapView.addMouseListener(mode);
     143      Main.map.mapView.addMouseMotionListener(mode);
     144      NavigatableComponent.addZoomChangeListener(mode);
     145      updateHelpText();
     146    }
    145147  }
    146148
     
    168170  @Override
    169171  public void destroy() {
     172    setMode(null);
     173    MapillaryDownloader.stopAll();
    170174    MapillaryMainDialog.getInstance().setImage(null);
    171175    MapillaryMainDialog.getInstance().updateImage();
    172     data.getImages().clear();
    173     MapillaryLayer.INSTANCE = null;
    174     MapillaryData.INSTANCE = null;
    175176    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false);
    176177    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false);
     
    180181    if (Main.map.mapView.getEditLayer() != null)
    181182      Main.map.mapView.getEditLayer().data.removeDataSetListener(this);
     183    MapillaryLayer.INSTANCE = null;
    182184    super.destroy();
    183185  }
     
    593595    else
    594596      ret += tr("No images found");
    595     ret += " -- " + tr(mode.toString());
    596 
     597    if (mode != null)
     598      ret += " -- " + tr(mode.toString());
    597599    Main.map.statusLine.setHelpText(ret);
    598600  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31401 r31404  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.util.concurrent.ArrayBlockingQueue;
    56import java.util.concurrent.ConcurrentHashMap;
    6 import java.util.concurrent.Executor;
    7 import java.util.concurrent.Executors;
     7import java.util.concurrent.ThreadPoolExecutor;
     8import java.util.concurrent.TimeUnit;
    89
    910import javax.swing.JOptionPane;
     
    3435  public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm";
    3536  /** Executor that will run the petitions */
    36   public final static Executor EXECUTOR = Executors.newSingleThreadExecutor();
     37  public final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(1,
     38      1, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50));
    3739
    3840  /**
     
    5153    queryStringParts.put("max_lat", maxLatLon.lat());
    5254    queryStringParts.put("max_lon", maxLatLon.lon());
     55    run(new MapillarySquareDownloadManagerThread(queryStringParts,
     56        MapillaryLayer.getInstance()));
     57  }
    5358
    54     try {
    55       EXECUTOR.execute(new MapillarySquareDownloadManagerThread(
    56           queryStringParts, MapillaryLayer.getInstance()));
    57     } catch (Exception e) {
    58       Main.error(e);
    59     }
     59  private static void run(Thread t) {
     60    EXECUTOR.execute(t);
    6061  }
    6162
     
    130131    }
    131132  }
     133
     134  /**
     135   * Stops all running threads.
     136   */
     137  public static void stopAll() {
     138    EXECUTOR.shutdownNow();
     139  }
    132140}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31401 r31404  
    8383      }
    8484    } catch (InterruptedException e) {
    85       Main.error(e);
     85      Main.error("Mapillary download interrupted (probably because of closing the layer).");
    8686    }
    8787    layer.updateHelpText();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31401 r31404  
    2727
    2828  protected MapillaryData data = MapillaryData.getInstance();
    29 
    30   /** If in semiautomatic mode, the last Epoch time when there was a download */
    31   private long lastDownload;
     29  private static final SemiautomaticThread semiautomaticThread = new SemiautomaticThread();
    3230
    3331  /**
     
    6361
    6462  @Override
    65   public synchronized void zoomChanged() {
     63  public void zoomChanged() {
    6664    if (Main.pref.get("mapillary.download-mode").equals(
    6765        MapillaryDownloader.MODES[1])
    6866        || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC) {
    69       if (Calendar.getInstance().getTimeInMillis() - lastDownload >= 2000) {
    70         lastDownload = Calendar.getInstance().getTimeInMillis();
    71         MapillaryDownloader.completeView();
    72       } else {
    73         new Thread() {
    74           @Override
    75           public synchronized void run() {
    76             try {
    77               wait(100);
    78             } catch (InterruptedException e) {
    79             }
    80             zoomChanged();
     67      if (!semiautomaticThread.isAlive())
     68        semiautomaticThread.start();
     69      semiautomaticThread.moved();
     70    }
     71  }
     72
     73  private static class SemiautomaticThread extends Thread {
     74
     75    /** If in semiautomatic mode, the last Epoch time when there was a download */
     76    private long lastDownload;
     77
     78    private boolean moved = false;
     79
     80    @Override
     81    public void run() {
     82      while (true) {
     83        if (moved
     84            && Calendar.getInstance().getTimeInMillis() - lastDownload >= 2000) {
     85          lastDownload = Calendar.getInstance().getTimeInMillis();
     86          MapillaryDownloader.completeView();
     87          moved = false;
     88          MapillaryData.getInstance().dataUpdated();
     89        }
     90        synchronized (this) {
     91          try {
     92            wait(100);
     93          } catch (InterruptedException e) {
     94            Main.error(e);
    8195          }
    82         }.start();
     96        }
    8397      }
     98    }
     99
     100    public void moved() {
     101      moved = true;
    84102    }
    85103  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31401 r31404  
    1818import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage;
    1919import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
     20import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    2021import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    2122
     
    4142  public SelectMode() {
    4243    record = MapillaryRecord.getInstance();
     44    if (Main.pref.get("mapillary.download-mode").equals(
     45        MapillaryDownloader.MODES[1]))
     46      zoomChanged();
    4347  }
    4448
Note: See TracChangeset for help on using the changeset viewer.