From 818f737d255e636a91e8a4eeabaff8f0ba537a77 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Tue, 29 Jan 2008 19:08:44 +0000 Subject: [PATCH] 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 --- .../threerings/getdown/data/Application.java | 4 +++ .../threerings/getdown/launcher/Getdown.java | 32 ++++++++++++------- .../getdown/launcher/GetdownApplet.java | 3 ++ .../threerings/getdown/messages.properties | 2 ++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 50d8151..67df725 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -948,6 +948,7 @@ public class Application * validated" resources filled in. */ public List verifyResources (ProgressObserver obs, int[] alreadyValid) + throws InterruptedException { List rsrcs = getAllResources(); List failures = new ArrayList(); @@ -960,6 +961,9 @@ public class Application MetaProgressObserver mpobs = new MetaProgressObserver(obs, totalSize); for (Resource rsrc : rsrcs) { + if (Thread.interrupted()) { + throw new InterruptedException("m.applet_stopped"); + } mpobs.startElement(rsrc.getLocal().length()); if (rsrc.isMarkedValid()) { diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 834130c..ac2187b 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -377,13 +377,8 @@ public abstract class Getdown extends Thread _app.releaseLock(); // Store the config modtime before waiting the delay amount of time long lastConfigModtime = config.lastModified(); - try { - Log.info("Waiting " + _delay + " minutes before beginning actual work"); - Thread.sleep(_delay * 15 * 1000); - } catch (InterruptedException ie) { - Log.warning("Who dares disturb my slumber?"); - Log.logStackTrace(ie); - } + Log.info("Waiting " + _delay + " minutes before beginning actual work"); + Thread.sleep(_delay * 15 * 1000); if (lastConfigModtime < config.lastModified()) { Log.warning("getdown.txt was modified while getdown was waiting"); 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 // of the blue would be disconcerting. if (!_silent || _launchInSilent) { - // One last check for the lock before launching. It'll already be held - // unless we're in silent mode. + if (Thread.interrupted()) { + // 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(); launch(); } @@ -526,7 +525,7 @@ public abstract class Getdown extends Thread * running with the necessary Java version. */ protected void updateJava () - throws IOException + throws IOException, InterruptedException { Resource vmjar = _app.getJavaVMResource(); 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. */ protected void update () - throws IOException + throws IOException, InterruptedException { // first clear all validation markers _app.clearValidationMarkers(); @@ -638,7 +637,7 @@ public abstract class Getdown extends Thread * Called if the application is determined to require resource downloads. */ protected void download (List resources) - throws IOException + throws IOException, InterruptedException { // create our user interface createInterface(false); @@ -660,6 +659,12 @@ public abstract class Getdown extends Thread } _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); if (percent > 0) { reportTrackingEvent("progress", percent); @@ -700,6 +705,9 @@ public abstract class Getdown extends Thread // start the download and wait for it to complete if (!dl.download()) { + if (Thread.interrupted()) { + throw new InterruptedException("m.applet_stopped"); + } throw new MultipleGetdownRunning(); } } diff --git a/src/java/com/threerings/getdown/launcher/GetdownApplet.java b/src/java/com/threerings/getdown/launcher/GetdownApplet.java index 5d5fec9..7e35a87 100644 --- a/src/java/com/threerings/getdown/launcher/GetdownApplet.java +++ b/src/java/com/threerings/getdown/launcher/GetdownApplet.java @@ -172,6 +172,9 @@ public class GetdownApplet extends JApplet @Override // documentation inherited 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 _getdown._app.releaseLock(); } diff --git a/src/java/com/threerings/getdown/messages.properties b/src/java/com/threerings/getdown/messages.properties index 2febcfc..5b32e54 100644 --- a/src/java/com/threerings/getdown/messages.properties +++ b/src/java/com/threerings/getdown/messages.properties @@ -97,6 +97,8 @@ m.default_install_error = the support section of the website m.another_getdown_running = Multiple instances of this application's \ 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 m.missing_appbase = The configuration file is missing the 'appbase'.