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.
publicEvent(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.
publicvoid addListener(IEventListener listener)
- listener: IEventListener - listener reference to add.
getListeners
Gets all listeners registred in this event.
publicList<IEventListener> getListeners()
- returns: List<IEventListener> - list of listeners.
getName
Gets the name of the event.
publicString 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.
publicvoid removeListener(IEventListener listener)
- listener: IEventListener - listener reference to remove.
Example:
{
Event event = new Event("my_event");
event.addListener(myListener);
event.notify("123", Parameters.fromTuples(
"param1", "ABC",
"param2", 123
));
}