Reenable locking, but only when -Dlock=true is passed on the command line or a

lock="true" param is passed to the applet.

Release the lock when launching the application directly from getdown,
navigating away from the applet and borking.  Hopefully one of the first two
releases will allow invoking directly to work in an applet, but applets seem to
share the lock on my Mac, so I haven't been able to test it.
This commit is contained in:
Charlie Groves
2008-01-28 02:22:41 +00:00
parent 305446e7f3
commit ef42ff053a
3 changed files with 30 additions and 11 deletions
@@ -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
* <code>appid.apparg</code> 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;
}
@@ -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.
@@ -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();
}
/**