diff options
Diffstat (limited to 'netx/net/sourceforge/jnlp')
-rw-r--r-- | netx/net/sourceforge/jnlp/Launcher.java | 19 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/resources/Messages.properties | 3 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/services/XSingleInstanceService.java | 38 |
3 files changed, 52 insertions, 8 deletions
diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java index 15b1e56..1692b0e 100644 --- a/netx/net/sourceforge/jnlp/Launcher.java +++ b/netx/net/sourceforge/jnlp/Launcher.java @@ -536,6 +536,9 @@ public class Launcher { try { ServiceUtil.checkExistingSingleInstance(file); } catch (InstanceExistsException e) { + if (JNLPRuntime.isDebug()) { + System.out.println("Single instance application is already running."); + } return null; } @@ -653,11 +656,17 @@ public class Launcher { throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo"))); try { + ServiceUtil.checkExistingSingleInstance(file); AppletInstance applet = createApplet(file, enableCodeBase, cont); applet.initialize(); applet.getAppletEnvironment().startApplet(); // this should be a direct call to applet instance return applet; + } catch (InstanceExistsException ieex) { + if (JNLPRuntime.isDebug()) { + System.out.println("Single instance applet is already running."); + } + throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists"))); } catch (LaunchException lex) { throw launchError(lex); } catch (Exception ex) { @@ -673,9 +682,17 @@ public class Launcher { throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplet"), R("LNotAppletInfo"))); try { + ServiceUtil.checkExistingSingleInstance(file); + AppletInstance applet = createApplet(file, enableCodeBase, cont); applet.initialize(); return applet; + + } catch (InstanceExistsException ieex) { + if (JNLPRuntime.isDebug()) { + System.out.println("Single instance applet is already running."); + } + throw launchError(new LaunchException(file, ieex, R("LSFatal"), R("LCLaunching"), R("LCouldNotLaunch"), R("LSingleInstanceExists"))); } catch (LaunchException lex) { throw launchError(lex); } catch (Exception ex) { @@ -688,6 +705,8 @@ public class Launcher { * a thread in the application's thread group. */ protected ApplicationInstance launchInstaller(JNLPFile file) throws LaunchException { + // TODO Check for an existing single instance once implemented. + // ServiceUtil.checkExistingSingleInstance(file); throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCNotSupported"), R("LNoInstallers"), R("LNoInstallersInfo"))); } diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 3c42cb8..1f3a1e5 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -82,7 +82,8 @@ LSignedAppJarUsingUnsignedJar=Signed application using unsigned jars. LSignedAppJarUsingUnsignedJarInfo=The main application jar is signed, but some of the jars it is using aren't.
LSignedJNLPFileDidNotMatch=The signed JNLP file did not match the launching JNLP file.
LNoSecInstance=Error: No security instance for {0}. The application may have trouble continuing
-LCertFoundIn={0} found in cacerts ({1})
+LCertFoundIn={0} found in cacerts ({1}) +LSingleInstanceExists=Another instance of this applet already exists and only one may be run at the same time.
JNotApplet=File is not an applet.
JNotApplication=File is not an application.
diff --git a/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java b/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java index 1a40794..35da018 100644 --- a/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java +++ b/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java @@ -24,11 +24,14 @@ import java.net.Socket; import java.net.UnknownHostException; import java.util.LinkedList; import java.util.List; +import java.util.Map.Entry; +import java.util.Set; import javax.jnlp.SingleInstanceListener; import javax.management.InstanceAlreadyExistsException; import net.sourceforge.jnlp.JNLPFile; +import net.sourceforge.jnlp.PluginBridge; import net.sourceforge.jnlp.runtime.JNLPRuntime; /** @@ -104,13 +107,14 @@ public class XSingleInstanceService implements ExtendedSingleInstanceService { * @throws InstanceAlreadyExistsException if the instance already exists */ public void initializeSingleInstance() { - if (!initialized) { - // this is called after the application has started. so safe to use - // JNLPRuntime.getApplication() - checkSingleInstanceRunning(JNLPRuntime.getApplication().getJNLPFile()); + // this is called after the application has started. so safe to use + // JNLPRuntime.getApplication() + JNLPFile jnlpFile = JNLPRuntime.getApplication().getJNLPFile(); + if (!initialized || jnlpFile instanceof PluginBridge) { + // Either a new process or a new applet being handled by the plugin. + checkSingleInstanceRunning(jnlpFile); initialized = true; SingleInstanceLock lockFile; - JNLPFile jnlpFile = JNLPRuntime.getApplication().getJNLPFile(); lockFile = new SingleInstanceLock(jnlpFile); if (!lockFile.isValid()) { startListeningServer(lockFile); @@ -127,6 +131,7 @@ public class XSingleInstanceService implements ExtendedSingleInstanceService { * @throws InstanceExistsException if an instance of this application * already exists */ + @Override public void checkSingleInstanceRunning(JNLPFile jnlpFile) { SingleInstanceLock lockFile = new SingleInstanceLock(jnlpFile); if (lockFile.isValid()) { @@ -134,9 +139,28 @@ public class XSingleInstanceService implements ExtendedSingleInstanceService { if (JNLPRuntime.isDebug()) { System.out.println("Lock file is valid (port=" + port + "). Exiting."); } + + String[] args = null; + if (jnlpFile.isApplet()) { + // FIXME Proprietary plug-in is unclear about how to handle + // applets and their parameters. + //Right now better to forward at least something + Set<Entry<String, String>> currentParams = jnlpFile.getApplet().getParameters().entrySet(); + args = new String[currentParams.size() * 2]; + int i = 0; + for (Entry<String, String> entry : currentParams) { + args[i] = entry.getKey(); + args[i+1] = entry.getValue(); + i += 2; + } + } else if (jnlpFile.isInstaller()) { + // TODO Implement this once installer service is available. + } else { + args = jnlpFile.getApplication().getArguments(); + } + try { - sendProgramArgumentsToExistingApplication(port, jnlpFile.getApplication() - .getArguments()); + sendProgramArgumentsToExistingApplication(port, args); throw new InstanceExistsException(String.valueOf(port)); } catch (IOException e) { throw new RuntimeException(e); |