aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/Launcher.java
diff options
context:
space:
mode:
authorAndrew Su <asu@redhat.com>2011-03-17 15:10:32 -0400
committerAndrew Su <asu@redhat.com>2011-03-17 15:10:32 -0400
commit8b14e30c2894902f33653ecac38332cb4bb84f11 (patch)
tree32c6b79f79916e6938b18fd597860dc4c7e63633 /netx/net/sourceforge/jnlp/Launcher.java
parentb57ac4af342f216974001abcbf8e132f3c7d0327 (diff)
Ensure that javaws can not clear cache while plugin or javaws is running.
Diffstat (limited to 'netx/net/sourceforge/jnlp/Launcher.java')
-rw-r--r--netx/net/sourceforge/jnlp/Launcher.java78
1 files changed, 2 insertions, 76 deletions
diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java
index efd3c4a..09212b8 100644
--- a/netx/net/sourceforge/jnlp/Launcher.java
+++ b/netx/net/sourceforge/jnlp/Launcher.java
@@ -21,15 +21,10 @@ import static net.sourceforge.jnlp.runtime.Translator.R;
import java.applet.Applet;
import java.awt.Container;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
import java.util.LinkedList;
import java.util.List;
import java.util.jar.JarFile;
@@ -37,7 +32,6 @@ import java.util.jar.JarFile;
import net.sourceforge.jnlp.cache.CacheUtil;
import net.sourceforge.jnlp.cache.ResourceTracker;
import net.sourceforge.jnlp.cache.UpdatePolicy;
-import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.AppThreadGroup;
import net.sourceforge.jnlp.runtime.AppletInstance;
import net.sourceforge.jnlp.runtime.ApplicationInstance;
@@ -45,7 +39,6 @@ import net.sourceforge.jnlp.runtime.JNLPClassLoader;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.services.InstanceExistsException;
import net.sourceforge.jnlp.services.ServiceUtil;
-import net.sourceforge.jnlp.util.FileUtils;
import javax.swing.SwingUtilities;
import javax.swing.text.html.parser.ParserDelegator;
@@ -83,8 +76,6 @@ public class Launcher {
/** If the application should call System.exit on fatal errors */
private boolean exitOnFailure = true;
- /** a lock which is held to indicate that an instance of netx is running */
- private FileLock fileLock;
/**
* Create a launcher with the runtime's default update policy
@@ -198,6 +189,8 @@ public class Launcher {
public ApplicationInstance launch(JNLPFile file, Container cont) throws LaunchException {
TgThread tg;
+ JNLPRuntime.markNetxRunning();
+
//First checks whether offline-allowed tag is specified inside the jnlp
//file.
if (!file.getInformation().isOfflineAllowed()) {
@@ -387,13 +380,6 @@ public class Launcher {
if (!file.isApplication())
throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplication"), R("LNotApplicationInfo")));
- markNetxRunning();
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- markNetxStopped();
- }
- });
-
try {
try {
@@ -699,66 +685,6 @@ public class Launcher {
}
/**
- * Indicate that netx is running by creating the {@link JNLPRuntime#INSTANCE_FILE} and
- * acquiring a shared lock on it
- */
- private void markNetxRunning() {
- try {
- String message = "This file is used to check if netx is running";
-
- File netxRunningFile = new File(JNLPRuntime.getConfiguration()
- .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE));
- if (!netxRunningFile.exists()) {
- FileUtils.createParentDir(netxRunningFile);
- FileUtils.createRestrictedFile(netxRunningFile, true);
- FileOutputStream fos = new FileOutputStream(netxRunningFile);
- try {
- fos.write(message.getBytes());
- } finally {
- fos.close();
- }
- }
-
- FileInputStream is = new FileInputStream(netxRunningFile);
- FileChannel channel = is.getChannel();
- fileLock = channel.tryLock(0, Long.MAX_VALUE, true);
- if (fileLock != null && fileLock.isShared()) {
- if (JNLPRuntime.isDebug()) {
- System.out.println("Acquired shared lock on " +
- netxRunningFile.toString() + " to indicate javaws is running");
- }
- } else {
- fileLock = null;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
- /**
- * Indicate that netx is stopped by releasing the shared lock on
- * {@link JNLPRuntime#INSTANCE_FILE}.
- */
- private void markNetxStopped() {
- if (fileLock == null) {
- return;
- }
- try {
- fileLock.release();
- fileLock.channel().close();
- fileLock = null;
- if (JNLPRuntime.isDebug()) {
- String file = JNLPRuntime.getConfiguration()
- .getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE);
- System.out.println("Release shared lock on " + file);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
* Do hacks on per-application level to allow different AppContexts to work
*
* @see JNLPRuntime#doMainAppContextHacks