Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4912616

SingleInstanceService.removeSingleInstanceListener() does not remove listener

XMLWordPrintable

    • sparc
    • generic



      Name: dfR10049 Date: 08/26/2003


      SingleInstanceService.removeSingleInstanceListener() has no effect.
      After the following code:
          service.addSingleInstanceListener(listener);
          service.removeSingleInstanceListener(listener);
      newActivation() method of 'listener' should not be invoked if new
      instance of the same application is stared. But it is not truth for javaws.

      This bug is reproducible only with JDK1.5.0 b16 build.
      With b15 listener is removed by removeSingleInstanceListener() method.

      Example demonstrating the bug:

      -----8<----------- Single.java ---------------
      import java.awt.*;
      import javax.jnlp.*;

      public class Single {

          public static void main(String args[]) {
              Single sing = new Single();
              sing.test();
              System.exit(0);
          }

          static void showFrame(String s, long time) {
                  Frame f = new Frame();
                  TextField tf = new TextField(s);
                  f.add(tf);
                  f.setSize(300, 300);
                  f.setVisible(true);
                  try {
                      Thread.currentThread().sleep(time);
                  } catch (Exception e) {
                      //
                  }
                  f.setVisible(false);
          }


          void test() {
              try {
                  String name = "javax.jnlp.SingleInstanceService";
                  SingleInstanceService service = (SingleInstanceService)
                          ServiceManager.lookup(name);
                  Singleton listener1 = new Singleton(false, "S1");
                  Singleton listener2 = new Singleton(true, "S2");
                  service.addSingleInstanceListener(listener1);
                  service.addSingleInstanceListener(listener2);
                  service.removeSingleInstanceListener(listener2);

                  showFrame("Application statred", 2000);
                  Thread.currentThread().sleep(40000);
                  showFrame("Exit application", 2000);
              } catch (Exception e) {
                  showFrame("Unexpected: " + e, 6000);
              }
          }

      }

          class Singleton implements SingleInstanceListener {

              boolean isRemoved = false;
              String name = null;

              Singleton(boolean isRemoved, String name) {
                 this.isRemoved = isRemoved;
                 this.name = name;
              }

              public void newActivation(String[] args) {
                  String s = "listener " + name + " is activated with args:";
                  for (int i = 0; i < args.length; i++) {
                       s += i + " : " + args[i] + "\n";
                  }
                  Single.showFrame(s, 5000);
                  if (isRemoved)
                      Single.showFrame("Test fails", 5000);
              }
          }

      -----8<----------- sing.jnlp ---------------
      <?xml version="1.0" encoding="UTF-8"?>
      <jnlp spec="0.2+"
        codebase="file:///home/fda/jnlp/">
        <information>
          <title>Singleton test</title>
          <vendor>Sun Microsystems, Inc.</vendor>
          <homepage href="index.html"/>
        </information>
        <resources>
          <j2se version="1.5"/>
          <jar href="sing.jar"/>
        </resources>
        <application-desc main-class="Single">
          <argument>ABC</argument>
          <argument>XYZ</argument>
        </application-desc>

      </jnlp>

      ----------------------------------------------------

      To reproduce the bug two instances of javaws with the 'sing.jnlp' should
      be started with interval ~10 seconds.

      ======================================================================

            Unassigned Unassigned
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: