Class Signal4<A1,A2,A3,A4>

java.lang.Object
eu.webtoolkit.jwt.AbstractSignal
eu.webtoolkit.jwt.Signal4<A1,A2,A3,A4>

public class Signal4<A1,A2,A3,A4> extends AbstractSignal
A signal that propagates events to listeners, and is capable of passing 4 argument.

A signal implements the Observer pattern, allowing one or more listeners to listen for events generated on the signal. The event may propagate 4 arguments to the listeners.

For a usage example take a look the documentation of Signal2.

  • Constructor Details

    • Signal4

      public Signal4()
      Creates a new signal.
  • Method Details

    • addListener

      public AbstractSignal.Connection addListener(WObject listenerOwner, Signal4.Listener<A1,A2,A3,A4> listener)
      Adds a listener for this signal.

      Each listener will be triggered whenever the signal is triggered.

      Parameters:
      listenerOwner - the enclosing object for a listener implemented using an (anonymous) inner class
      listener - the listener
      Returns:
      a connection object that may be used to control the connection
      See Also:
    • removeListener

      public void removeListener(Signal4.Listener<A1,A2,A3,A4> listener)
      Removes a listener.
      Parameters:
      listener - a listener that was previously added
    • trigger

      public void trigger(A1 arg1, A2 arg2, A3 arg3, A4 arg4)
      Triggers the signal.

      The arguments are passed to the listeners.

      Parameters:
      arg1 - Argument 1.
      arg2 - Argument 2.
      arg3 - Argument 3.
      arg4 - Argument 4.
    • addListener

      public AbstractSignal.Connection addListener(WObject listenerOwner, Signal.Listener listener)
      Description copied from class: AbstractSignal
      Adds a listener for this signal.

      Each listener will be notified when the signal is triggered.

      An owner object may be passed when the listener is implemented using an (anonymous) inner class. In that case the owner object should be the enclosing object of the listener object, and this is used to bind the lifetime of the listener. To avoid the owner object from not being garbage collected when it is no longer used, only the owner object will add a reference to the listener, while the signal will use a weak reference.

      This avoids the most common reason for memory leaks in Java implementations of the Observer pattern: the owner object will not get garbage collected because of the (anonymous) listener object having a reference to it, even if the receiver object is no longer referenced from anywhere. When the owner object is not null, the listener is stored using a strong reference in the owner object, and using a weak reference in the signal.

      Specified by:
      addListener in class AbstractSignal
      Parameters:
      listenerOwner - if not null, the enclosing object for a listener implemented using an inner class
      listener - the listener
      Returns:
      a connection object that may be used to control the connection
    • removeListener

      public void removeListener(Signal.Listener listener)
      Description copied from class: AbstractSignal
      Removes a listener.

      Specified by:
      removeListener in class AbstractSignal
      Parameters:
      listener - a listener that was previously added.
    • getArgumentCount

      protected int getArgumentCount()
      Description copied from class: AbstractSignal
      Returns the number of parameters (excluding an 'event').
      Specified by:
      getArgumentCount in class AbstractSignal