diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 5371c92..7c8b562 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -154,7 +154,7 @@ public class Application */ public Application (File appdir, String appid) { - this(appdir, appid, null); + this(appdir, appid, null, false); } /** @@ -166,13 +166,15 @@ public class Application * appid.apparg to configure itself but all other parameters will be the same as * the primary application. * @param signers an array of possible signers of this application. Used to verify the digest. + * @param useLock - if true, attempt to acquire a lockfile while active updating is occuring. */ - public Application (File appdir, String appid, Object[] signers) + public Application (File appdir, String appid, Object[] signers, boolean useLock) { _appdir = appdir; _appid = appid; _signers = signers; _config = getLocalPath(CONFIG_FILE); + _locking = useLock; } /** @@ -1028,12 +1030,12 @@ public class Application } /** - * @return true if gettingdown.lock was locked or was already locked by this application. + * @return true if gettingdown.lock was unlocked, already locked by this application or if + * we're not locking at all. */ public synchronized boolean lockForUpdates () { - /* TEMP disable locking - if (_lock != null && _lock.isValid()) { + if (!_locking || (_lock != null && _lock.isValid())) { return true; } try { @@ -1049,9 +1051,8 @@ public class Application Log.warning("Unable to create lock [message=" + e.getMessage() + "]"); Log.logStackTrace(e); } + Log.info("Able to lock for updates: " + (_lock != null)); return _lock != null; - */ - return true; } /** @@ -1059,8 +1060,8 @@ public class Application */ public synchronized void releaseLock () { - /* TEMP disable locking if (_lock != null) { + Log.info("Releasing lock"); try { _lock.release(); } catch (IOException e) { @@ -1076,7 +1077,6 @@ public class Application _lockChannel = null; _lock = null; } - */ } /** @@ -1317,4 +1317,7 @@ public class Application /** Channel to the file underying _lock. Kept around solely so the lock doesn't close. */ protected FileChannel _lockChannel; + + /** True if we're using the locks, false means we're allowing multiple getdowns to run. */ + protected boolean _locking; } diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 05eff9e..834130c 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -117,7 +117,7 @@ public abstract class Getdown extends Thread updateStatus(errmsg); _dead = true; } - _app = new Application(appDir, appId, signers); + _app = new Application(appDir, appId, signers, useLocks()); _startup = System.currentTimeMillis(); } @@ -479,6 +479,7 @@ public abstract class Getdown extends Thread // Since we're dead, clear off the 'time remaining' label along with displaying the // error message setStatus(msg, 0, -1L, true); + _app.releaseLock(); _dead = true; } } @@ -712,6 +713,7 @@ public abstract class Getdown extends Thread try { if (invokeDirect()) { + _app.releaseLock(); _app.invokeDirect(getApplet()); } else { @@ -897,6 +899,16 @@ public abstract class Getdown extends Thread return Boolean.getBoolean("direct"); } + /** + * If this method returns true we will acquire a lock when starting to update files to prevent + * other instances of getdown from running. + */ + protected boolean useLocks () + { + // allow passing -Dlock=true to turn on lock usage + return Boolean.getBoolean("lock"); + } + /** * Provides access to the applet that we'll pass on to our application when we're in "invoke * direct" mode. diff --git a/src/java/com/threerings/getdown/launcher/GetdownApplet.java b/src/java/com/threerings/getdown/launcher/GetdownApplet.java index 9a5d56e..5d5fec9 100644 --- a/src/java/com/threerings/getdown/launcher/GetdownApplet.java +++ b/src/java/com/threerings/getdown/launcher/GetdownApplet.java @@ -111,6 +111,9 @@ public class GetdownApplet extends JApplet protected boolean invokeDirect () { return "true".equalsIgnoreCase(getParameter("direct")); } + protected boolean useLocks () { + return "true".equalsIgnoreCase(getParameter("lock")); + } protected JApplet getApplet () { return GetdownApplet.this; } @@ -169,7 +172,8 @@ public class GetdownApplet extends JApplet @Override // documentation inherited public void stop () { - // TODO + // release the lock if the applet window is closed or replaced + _getdown._app.releaseLock(); } /**