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

RFE: built-in support for listener registration and event firing

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P5 P5
    • None
    • 1.4.2
    • specification
    • x86
    • windows_2000

      Name: jl125535 Date: 08/19/2003


      A DESCRIPTION OF THE REQUEST :
      I propose a mechanism which has the benefit both to distinguish event registering and raising from other methods and to remove from the developer the need to rewrite anytime the broadcast loop.

      Suppose we have an EventListener interface

      ------------------
      import java.awt.event.ActionListener
      ...
      ------------------


      I propose that the declaration of the event may be done
      through a new keyword, "broadcast".

      --------------------------------
      import java.awt.event.ActionListener

      //a class that raises action events
      class MySource
      {
      public broadcast ActionListener actionHandler;
      }
      ------------------

      The MySource developer would not intantiate the any ActionListener. The
      keyword broadcast tells the compiler (or the jvm) that actionHandler is a bag
      of ActionListener. The MySource developer would not write any code to register
      listeners nor any loop to dispatch the event. The broadcast keyword may be used
      only with interfaces that extends the EventListener interface.

      A client would register through the following mechanism:

      ---------------------------
      import java.awt.event.ActionListener

      //a class that raises action events
      class MyListener implements ActionListener
      {
      MySource source = new MySource ();
      MyListener ()
      {
      source.actionHandler += this;
      }
      }
      -----------------------------

      The MySource developer would trigger the event through the following mechanism
      (no loop, simply use of the listener interface):

      --------------------------------
      import java.awt.event.ActionListener
      import java.awt.event.ActionEvent

      //a class that raises action events
      class MySource
      {
      public broadcast ActionListener actionHandler;

      void aMethod ()
      {
      actionHandler.actionPerformed (new ActionEvent (this));
      }

      }
      ------------------


      Conclusion. This mechanism would lay aside event declaration and registration
      from normal methods, making the code more clear. It would also simplify
      greatly event declaration on a class (which now involves to implement addXXX removeXXX fireXXX
      method for any event we want to raise).



      JUSTIFICATION :
      Two benefits -
      1) Distinguish event registering and raising from other methods
      2) Remove the need to rewrite anytime the broadcast loop.

      Javadoc documentation would present distinct event documentation
      from fields and methods
      (Incident Review ID: 182979)
      ======================================================================

            abuckley Alex Buckley
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: