[RFC][icedtea-web] Fix for single instance service with applets using jnlp_href

Jiri Vanek jvanek at redhat.com
Mon Mar 12 03:42:00 PDT 2012


On 01/31/2012 09:07 PM, Danesh Dadachanji wrote:
> Hi,
>
I must confess I can not guess motivation for this and not even find 100% what is it doing and why.
Can you please  write little bit (..much...;) ) more about background of this patch?

My current thoughts - when two completely same appelts are on the page, they are not lunched - correct? Why this restriction?

> Attached is a patch to fix SingleInstanceService to work when applets use jnlp_href.
>
> If a single instance exists, it'll throw a fatal exception for the second applet and stop running it. The applet passes the args along while checking. However, proprietary documentation is unclear about which args are passed so for now I have left it as a FIXME until that's cleared up.
I believe applets parameters inside tag/jnlp descriptor  are correct  way.
>
> ChangeLog:
> +2012-01-31  Danesh Dadachanji <ddadacha at redhat.com>
> +
> +    Fixed SingleInstanceService to work with jnlp_href.
> +    * netx/net/sourceforge/jnlp/Launcher.java
> +    (launchApplication): Print existing single instance in debug mode.
> +    (launchApplet): Added check for single instance, throws launchError if
> +    single instance already exists.
> +    (getApplet): Same as above.
> +    (launchInstaller): Added TODO reminder for when it is implemented.
> +    * netx/net/sourceforge/jnlp/resources/Messages.properties:
> +    Added LSingleInstanceExists.
> +    * netx/net/sourceforge/jnlp/services/XSingleInstanceService.java
> +    (initializeSingleInstance): Modified to always initialize if the applet is
> +    being run by the plugin.
> +    (checkSingleInstanceRunning): Modified args passed to SingleInstanceListener.
> +    Marked applets' args as FIXME, for now it passes an empty args array.
> +
>
> Okay for HEAD?
>
> Cheers,
> Danesh
>
>
> single-instance-service-01.patch
>
>
> diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java
> --- 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.");

* Why not also stacktraces?

> +            }
> +            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
> --- a/netx/net/sourceforge/jnlp/resources/Messages.properties
> +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties
> @@ -81,6 +81,7 @@ LUnsignedJarWithSecurityInfo=Application
>   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.
> +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
> --- a/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java
> +++ b/netx/net/sourceforge/jnlp/services/XSingleInstanceService.java
> @@ -29,6 +29,9 @@ import javax.jnlp.SingleInstanceListener
>   import javax.management.InstanceAlreadyExistsException;
>
>   import net.sourceforge.jnlp.JNLPFile;
> +import net.sourceforge.jnlp.PluginBridge;
> +import net.sourceforge.jnlp.runtime.AppletInstance;
> +import net.sourceforge.jnlp.runtime.ApplicationInstance;
>   import net.sourceforge.jnlp.runtime.JNLPRuntime;
>
>   /**
> @@ -104,13 +107,14 @@ public class XSingleInstanceService impl
>        * @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);
> @@ -134,9 +138,21 @@ public class XSingleInstanceService impl
>               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. Potentially use
> +                // jnlpFile.getApplet().getParameters();
> +                args = new String[0];
> +            } 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);




More information about the distro-pkg-dev mailing list