diff options
author | Jiri Vanek <jvanek@redhat.com> | 2012-09-05 12:30:30 +0200 |
---|---|---|
committer | Jiri Vanek <jvanek@redhat.com> | 2012-09-05 12:30:30 +0200 |
commit | 52b4eb32aaf143c8091d9a7d39e17a1453b82ca6 (patch) | |
tree | 026635d7666d5ec31609cfe6a96121acd062c3f6 /netx/net/sourceforge/jnlp/services | |
parent | 06b7548e1cc22689a92e77df742190621a111e9e (diff) |
Single instance support for jnlp-href and tests
Diffstat (limited to 'netx/net/sourceforge/jnlp/services')
-rw-r--r-- | netx/net/sourceforge/jnlp/services/XSingleInstanceService.java | 38 |
1 files changed, 31 insertions, 7 deletions
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); |