Event

Concrete implementation of the IEvent interface.

Implements: IEvent

Description

The Event class allows you to create events.

Important points

  • It allows you to send asynchronous notifications to multiple subscribed listeners.

Constructors

Creates a new event and assigns its name.
Throws an Error if the name is null.

public Event(String name)

  • name: String - name of the event that is to be created.

Instance methods

addListener

Adds a listener to receive notifications when this event is fired.

public void addListener(IEventListener listener)

getListeners

Gets all listeners registred in this event.

public List<IEventListener> getListeners()

getName

Gets the name of the event.

public String getName()

  • returns: String - name of this event.

notify

Fires this event and notifies all registred listeners.
Throws an InvocationException if the event fails to be raised.

publicvoid notify(IContext context, Parameters args) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through a call chain.
  • args: Parameters - parameters to raise this event with.

removeListener

Removes a listener, so that it no longer receives notifications for this event.

public void removeListener(IEventListener listener)

Example:

{
  Event event = new Event("my_event");
  event.addListener(myListener);
  
  event.notify("123", Parameters.fromTuples(
    "param1", "ABC",
    "param2", 123
  ));
  }

See also