Changeset 3747 in josm
- Timestamp:
- 2010-12-27T19:40:35+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/GeorefImage.java
r3720 r3747 26 26 private static final long serialVersionUID = 1L; 27 27 28 public enum State { IMAGE, NOT_IN_CACHE, FAILED} ;28 public enum State { IMAGE, NOT_IN_CACHE, FAILED} 29 29 30 30 private WMSLayer layer; -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r3733 r3747 90 90 private final List<WMSRequest> requestQueue = new ArrayList<WMSRequest>(); 91 91 private final List<WMSRequest> finishedRequests = new ArrayList<WMSRequest>(); 92 /** 93 * List of request currently being processed by download threads 94 */ 95 private final List<WMSRequest> processingRequests = new ArrayList<WMSRequest>(); 92 96 private final Lock requestQueueLock = new ReentrantLock(); 93 97 private final Condition queueEmpty = requestQueueLock.newCondition(); … … 420 424 WMSRequest item = it.next(); 421 425 int priority = getRequestPriority(item); 422 if (priority == -1 ) {426 if (priority == -1 || finishedRequests.contains(item) || processingRequests.contains(item)) { 423 427 it.remove(); 424 428 } else { … … 446 450 if (canceled) 447 451 return null; 448 else 449 return requestQueue.remove(0); 452 else { 453 WMSRequest request = requestQueue.remove(0); 454 processingRequests.add(request); 455 return request; 456 } 450 457 451 458 } finally { … … 459 466 requestQueueLock.lock(); 460 467 try { 468 processingRequests.remove(request); 461 469 finishedRequests.add(request); 462 470 } finally { … … 468 476 requestQueueLock.lock(); 469 477 try { 470 if (!requestQueue.contains(request) ) {478 if (!requestQueue.contains(request) && !finishedRequests.contains(request) && !processingRequests.contains(request)) { 471 479 requestQueue.add(request); 472 480 queueEmpty.signalAll(); … … 491 499 } 492 500 } finally { 501 requestQueueLock.unlock(); 493 502 finishedRequests.clear(); 494 requestQueueLock.unlock();495 503 } 496 504 } … … 788 796 protected Grabber getGrabber(){ 789 797 if(getInfo().getImageryType() == ImageryType.HTML) 790 return new HTMLGrabber(mv, this , Grabber.cache);798 return new HTMLGrabber(mv, this); 791 799 else if(getInfo().getImageryType() == ImageryType.WMS) 792 return new WMSGrabber(mv, this , Grabber.cache);800 return new WMSGrabber(mv, this); 793 801 else throw new IllegalStateException("getGrabber() called for non-WMS layer type"); 794 802 } -
trunk/src/org/openstreetmap/josm/io/imagery/Grabber.java
r3720 r3747 23 23 protected volatile boolean canceled; 24 24 25 Grabber(MapView mv, WMSLayer layer , CacheFiles cache) {25 Grabber(MapView mv, WMSLayer layer) { 26 26 this.mv = mv; 27 27 this.layer = layer; … … 50 50 } 51 51 52 abstract void fetch(WMSRequest request ) throws Exception; // the image fetch code52 abstract void fetch(WMSRequest request, int attempt) throws Exception; // the image fetch code 53 53 54 54 int width(){ … … 86 86 if (!layer.requestIsValid(request)) 87 87 return; 88 fetch(request );88 fetch(request, i); 89 89 break; // break out of the retry loop 90 90 } catch (Exception e) { -
trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java
r3720 r3747 14 14 import org.openstreetmap.josm.gui.MapView; 15 15 import org.openstreetmap.josm.gui.layer.WMSLayer; 16 import org.openstreetmap.josm.io.CacheFiles;17 16 18 17 public class HTMLGrabber extends WMSGrabber { 19 18 public static final StringProperty PROP_BROWSER = new StringProperty("imagery.wms.browser", "webkit-image {0}"); 20 19 21 public HTMLGrabber(MapView mv, WMSLayer layer , CacheFiles cache) {22 super(mv, layer , cache);20 public HTMLGrabber(MapView mv, WMSLayer layer) { 21 super(mv, layer); 23 22 } 24 23 25 24 @Override 26 protected BufferedImage grab(URL url ) throws IOException {25 protected BufferedImage grab(URL url, int attempt) throws IOException { 27 26 String urlstring = url.toExternalForm(); 28 27 29 System.out.println("Grabbing HTML " + url);28 System.out.println("Grabbing HTML " + (attempt > 1? "(attempt " + attempt + ") ":"") + url); 30 29 31 30 ArrayList<String> cmdParams = new ArrayList<String>(); -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r3720 r3747 27 27 import org.openstreetmap.josm.data.coor.EastNorth; 28 28 import org.openstreetmap.josm.data.coor.LatLon; 29 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 29 30 import org.openstreetmap.josm.data.imagery.ImageryInfo; 30 import org.openstreetmap.josm.data.imagery.GeorefImage.State;31 31 import org.openstreetmap.josm.data.projection.Mercator; 32 32 import org.openstreetmap.josm.gui.MapView; 33 33 import org.openstreetmap.josm.gui.layer.WMSLayer; 34 import org.openstreetmap.josm.io.CacheFiles;35 34 import org.openstreetmap.josm.io.OsmTransferException; 36 35 import org.openstreetmap.josm.io.ProgressInputStream; … … 42 41 private final boolean urlWithPatterns; 43 42 44 public WMSGrabber(MapView mv, WMSLayer layer , CacheFiles cache) {45 super(mv, layer , cache);43 public WMSGrabber(MapView mv, WMSLayer layer) { 44 super(mv, layer); 46 45 this.baseURL = layer.getInfo().getURL(); 47 46 /* URL containing placeholders? */ … … 50 49 51 50 @Override 52 void fetch(WMSRequest request ) throws Exception{51 void fetch(WMSRequest request, int attempt) throws Exception{ 53 52 URL url = null; 54 53 try { … … 57 56 b.max.east(), b.max.north(), 58 57 width(), height()); 59 request.finish(State.IMAGE, grab(url ));58 request.finish(State.IMAGE, grab(url, attempt)); 60 59 61 60 } catch(Exception e) { … … 165 164 } 166 165 167 protected BufferedImage grab(URL url ) throws IOException, OsmTransferException {168 System.out.println("Grabbing WMS " + url);166 protected BufferedImage grab(URL url, int attempt) throws IOException, OsmTransferException { 167 System.out.println("Grabbing WMS " + (attempt > 1? "(attempt " + attempt + ") ":"") + url); 169 168 170 169 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); … … 193 192 InputStream in = conn.getInputStream(); 194 193 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 195 196 String line = null; 197 while( (line = br.readLine()) != null) { 198 // filter non-ASCII characters and control characters 199 exception.append(line.replaceAll("[^\\p{Print}]", "")); 200 exception.append('\n'); 201 } 202 return exception.toString(); 194 try { 195 String line = null; 196 while( (line = br.readLine()) != null) { 197 // filter non-ASCII characters and control characters 198 exception.append(line.replaceAll("[^\\p{Print}]", "")); 199 exception.append('\n'); 200 } 201 return exception.toString(); 202 } finally { 203 br.close(); 204 } 203 205 } 204 206 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSRequest.java
r3720 r3747 4 4 import java.awt.image.BufferedImage; 5 5 6 import org.openstreetmap.josm.data.imagery.GeorefImage;7 6 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 8 7
Note:
See TracChangeset
for help on using the changeset viewer.