Changeset 38908 for main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/DownloadUrls.java
- Timestamp:
- 2024-04-06T22:41:44+13:00 (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/DownloadUrls.java
r38885 r38908 8 8 import javax.swing.ImageIcon; //**** 9 9 10 //import org.apache.log4j.*; 10 11 11 12 /** … … 21 22 22 23 public class DownloadUrls extends Thread { 24 23 25 // for GS3 24 26 String baseURL = null; … … 35 37 String document_root_ = null; 36 38 37 39 /** When this thread is asked to stop running, this variable will be set to true */ 40 private boolean stop_running = false; 41 42 /** When this thread is asked to stop downloading, this variable will be set to true. 43 * For now the behaviour is the same as stop_running=true on this thread, 44 * but in case it changes in the future, we have a separate variable. 45 * Also, calling stopRunning() is not the same as setting stop_running = true, so 46 * to be careful, a separate variable for stop_downloading could be safer when coding. 47 */ 48 private boolean stop_downloading = false; 49 38 50 /** CHRIS - Holds the contents of the collection's assoc directory */ 39 51 // File[] assocDir_ = null; … … 181 193 } 182 194 183 184 195 // some other thread can call this method to tell this thread to stop running 196 public void stopRunning() { 197 if (verbosity_ >= 3) { 198 System.err.println("**** DownloadUrls.stopRunning() called"); 199 } 200 201 stop_running = true; 202 // Interrupt this thread, even if it's not the one running 203 // Just want to make sure the DownloadURls' thread the CURL object runs in 204 // gets interrupted if it's what's currently running 205 if(!this.isInterrupted()) { 206 this.interrupt(); 207 } 208 if(!Thread.currentThread().isInterrupted()) { 209 Thread.currentThread().interrupt(); 210 } 211 } 212 213 public boolean isStopping() { 214 return stop_running; 215 } 185 216 186 217 … … 390 421 try{ 391 422 // if have completed the maximum number of downloads for the 392 // application then stop 423 // application then stop downloading 393 424 if (size == app_.maxDownloads()) { 394 stop(); 425 // NOTE: the app can continue displaying images forever after download is 426 // finished, until interrupted/stopped. 427 // So don't set stop_running=false just because downloads have finished. 428 //stop_running = true; // Don't do this! 429 //thread_running = false; 430 //thread.currentThread().interrupt(); 431 432 stop_downloading = true; 433 //stop(); // TODO, remove this, replacing with above 434 395 435 } 396 436 … … 398 438 catch (Exception e) { 399 439 thread_running_ = false; 400 stop(); 440 //stop(); // TODO 441 stop_downloading = true; 401 442 e.printStackTrace(); 402 443 } … … 412 453 public void rec_add_images(String new_url, int depth) 413 454 { 414 415 455 if (verbosity_ >= 2) { 416 456 System.err.println("*** Inspecting url: " + new_url); … … 424 464 425 465 // connect to the url 466 // stopRunning would have set the interrupted flag, and 467 // CURL checks for that in its loop, *outside* its potentially-blocking read() call 426 468 CURL curl = (app_.gsdlversion == 3) ? new CURL(new_url, app_.baseURL) : new CURL(new_url); 427 469 … … 445 487 } 446 488 // process each of the image links according to the parameters given. 447 for (int i = 0; i < src_links.size() ; i++)489 for (int i = 0; i < src_links.size() && !stop_running && !stop_downloading; i++) 448 490 { 449 491 URL url = (URL)src_links.get(i); … … 491 533 } 492 534 535 if(stop_running && verbosity_ >= 3) { 536 System.err.println("*** DownloadUrls.rec_add_images() - Asked to stop running"); 537 return; 538 } 539 493 540 // get all the <code><a href=</code> links into a vector 494 541 Vector href_links = curl.getHrefLinks(); … … 500 547 501 548 // process each of the href links according to the parameters given. 502 for (int i = 0; i < href_links.size() ; i++)549 for (int i = 0; i < href_links.size() && !stop_running && !stop_downloading; i++) 503 550 { 504 551 … … 546 593 System.err.println("Unable able to download "+new_url); 547 594 } 595 596 if(stop_running && verbosity_ >= 3) { 597 System.err.println("*** DownloadUrls.rec_add_images() thread has been told to stop."); 598 } 548 599 } 549 600 … … 566 617 return; 567 618 } 568 619 569 620 // open a url to the file written 570 621 URL u = new URL(starting_url_ + "externallinks"); … … 576 627 String l = r.readLine(); 577 628 // split the line of the space, first part is the image, second part the link 578 while (l != null ) {629 while (l != null && !stop_running && !stop_downloading) { 579 630 580 631 String tmp1 = new String(); … … 600 651 r.close(); 601 652 653 if(stop_running && verbosity_ >= 3) { 654 System.err.println("*** DownloadUrls.externalLinks(): Asked to stop running"); 655 } 656 602 657 } catch (Exception e) { 603 658 e.printStackTrace(); … … 612 667 visited_url_ = new Hashtable(); 613 668 visited_images_ = new Hashtable(); 614 615 669 670 rec_add_images(starting_url_,1); 616 671 download_images_.stopDownload(); 617 System.err.println("Download thread finished.");672 System.err.println("DownloadUrls.run() - download thread finished."); 618 673 } 619 674 }
Note:
See TracChangeset
for help on using the changeset viewer.