Interrupt getdown's thread when the applet gets a stop message, and pick up on that from getdown so we don't keep working silently in the background and launch

This commit is contained in:
Charlie Groves
2008-01-29 19:08:44 +00:00
parent 95ad066fc2
commit 818f737d25
4 changed files with 29 additions and 12 deletions
@@ -948,6 +948,7 @@ public class Application
* validated" resources filled in. * validated" resources filled in.
*/ */
public List<Resource> verifyResources (ProgressObserver obs, int[] alreadyValid) public List<Resource> verifyResources (ProgressObserver obs, int[] alreadyValid)
throws InterruptedException
{ {
List<Resource> rsrcs = getAllResources(); List<Resource> rsrcs = getAllResources();
List<Resource> failures = new ArrayList<Resource>(); List<Resource> failures = new ArrayList<Resource>();
@@ -960,6 +961,9 @@ public class Application
MetaProgressObserver mpobs = new MetaProgressObserver(obs, totalSize); MetaProgressObserver mpobs = new MetaProgressObserver(obs, totalSize);
for (Resource rsrc : rsrcs) { for (Resource rsrc : rsrcs) {
if (Thread.interrupted()) {
throw new InterruptedException("m.applet_stopped");
}
mpobs.startElement(rsrc.getLocal().length()); mpobs.startElement(rsrc.getLocal().length());
if (rsrc.isMarkedValid()) { if (rsrc.isMarkedValid()) {
@@ -377,13 +377,8 @@ public abstract class Getdown extends Thread
_app.releaseLock(); _app.releaseLock();
// Store the config modtime before waiting the delay amount of time // Store the config modtime before waiting the delay amount of time
long lastConfigModtime = config.lastModified(); long lastConfigModtime = config.lastModified();
try { Log.info("Waiting " + _delay + " minutes before beginning actual work");
Log.info("Waiting " + _delay + " minutes before beginning actual work"); Thread.sleep(_delay * 15 * 1000);
Thread.sleep(_delay * 15 * 1000);
} catch (InterruptedException ie) {
Log.warning("Who dares disturb my slumber?");
Log.logStackTrace(ie);
}
if (lastConfigModtime < config.lastModified()) { if (lastConfigModtime < config.lastModified()) {
Log.warning("getdown.txt was modified while getdown was waiting"); Log.warning("getdown.txt was modified while getdown was waiting");
throw new MultipleGetdownRunning(); throw new MultipleGetdownRunning();
@@ -431,8 +426,12 @@ public abstract class Getdown extends Thread
// Only launch if we aren't in silent mode. Some mystery program starting out // Only launch if we aren't in silent mode. Some mystery program starting out
// of the blue would be disconcerting. // of the blue would be disconcerting.
if (!_silent || _launchInSilent) { if (!_silent || _launchInSilent) {
// One last check for the lock before launching. It'll already be held if (Thread.interrupted()) {
// unless we're in silent mode. // One last interrupted check so we don't launch as the applet aborts
throw new InterruptedException("m.applet_stopped");
}
// And another final check for the lock. It'll already be held unless
// we're in silent mode.
_app.lockForUpdates(); _app.lockForUpdates();
launch(); launch();
} }
@@ -526,7 +525,7 @@ public abstract class Getdown extends Thread
* running with the necessary Java version. * running with the necessary Java version.
*/ */
protected void updateJava () protected void updateJava ()
throws IOException throws IOException, InterruptedException
{ {
Resource vmjar = _app.getJavaVMResource(); Resource vmjar = _app.getJavaVMResource();
if (vmjar == null) { if (vmjar == null) {
@@ -581,7 +580,7 @@ public abstract class Getdown extends Thread
* Called if the application is determined to be of an old version. * Called if the application is determined to be of an old version.
*/ */
protected void update () protected void update ()
throws IOException throws IOException, InterruptedException
{ {
// first clear all validation markers // first clear all validation markers
_app.clearValidationMarkers(); _app.clearValidationMarkers();
@@ -638,7 +637,7 @@ public abstract class Getdown extends Thread
* Called if the application is determined to require resource downloads. * Called if the application is determined to require resource downloads.
*/ */
protected void download (List<Resource> resources) protected void download (List<Resource> resources)
throws IOException throws IOException, InterruptedException
{ {
// create our user interface // create our user interface
createInterface(false); createInterface(false);
@@ -660,6 +659,12 @@ public abstract class Getdown extends Thread
} }
_lastCheck = percent; _lastCheck = percent;
} }
if (Thread.currentThread().isInterrupted()) {
// The applet interrupts when it stops, so abort the download and quit. Use
// isInterrupted so the containing code can call interrupted outside of here
// to check if this was the reason for aborting.
return false;
}
setStatus("m.downloading", percent, remaining, true); setStatus("m.downloading", percent, remaining, true);
if (percent > 0) { if (percent > 0) {
reportTrackingEvent("progress", percent); reportTrackingEvent("progress", percent);
@@ -700,6 +705,9 @@ public abstract class Getdown extends Thread
// start the download and wait for it to complete // start the download and wait for it to complete
if (!dl.download()) { if (!dl.download()) {
if (Thread.interrupted()) {
throw new InterruptedException("m.applet_stopped");
}
throw new MultipleGetdownRunning(); throw new MultipleGetdownRunning();
} }
} }
@@ -172,6 +172,9 @@ public class GetdownApplet extends JApplet
@Override // documentation inherited @Override // documentation inherited
public void stop () public void stop ()
{ {
// Interrupt the getdown thread to tell it to kill its current downloading or verifying
// before launching
_getdown.interrupt();
// release the lock if the applet window is closed or replaced // release the lock if the applet window is closed or replaced
_getdown._app.releaseLock(); _getdown._app.releaseLock();
} }
@@ -97,6 +97,8 @@ m.default_install_error = the support section of the website
m.another_getdown_running = Multiple instances of this application's \ m.another_getdown_running = Multiple instances of this application's \
installer are running. This one will stop and let another complete. installer are running. This one will stop and let another complete.
m.applet_stopped = Getdown's applet was told to stop working.
# application/digest errors # application/digest errors
m.missing_appbase = The configuration file is missing the 'appbase'. m.missing_appbase = The configuration file is missing the 'appbase'.