Class Event

java.lang.Object
org.pipservices4.rpc.commands.Event
All Implemented Interfaces:
org.pipservices4.components.exec.INotifiable, IEvent

public class Event extends Object implements IEvent
Concrete implementation of IEvent interface. It allows to send asynchronous notifications to multiple subscribed listeners.

### Example ###

 
 
 Event event = new Event("my_event");
 event.addListener(myListener);
 
 event.notify("123", Parameters.fromTuples(
   "param1", "ABC",
   "param2", 123
 ));
 
 
See Also:
  • Constructor Details

    • Event

      public Event(String name)
      Creates a new event and assigns its name.
      Parameters:
      name - the name of the event that is to be created.
      Throws:
      NullPointerException - an Error if the name is null.
  • Method Details

    • getName

      public String getName()
      Gets the name of the event.
      Specified by:
      getName in interface IEvent
      Returns:
      the name of this event.
    • getListeners

      public List<IEventListener> getListeners()
      Gets all listeners registered in this event.
      Specified by:
      getListeners in interface IEvent
      Returns:
      a list of listeners.
    • addListener

      public void addListener(IEventListener listener)
      Adds a listener to receive notifications when this event is fired.
      Specified by:
      addListener in interface IEvent
      Parameters:
      listener - the listener reference to add.
    • removeListener

      public void removeListener(IEventListener listener)
      Removes a listener, so that it no longer receives notifications for this event.
      Specified by:
      removeListener in interface IEvent
      Parameters:
      listener - the listener reference to remove.
    • notify

      public void notify(org.pipservices4.components.context.IContext context, org.pipservices4.components.exec.Parameters args) throws org.pipservices4.commons.errors.ApplicationException
      Fires this event and notifies all registered listeners.
      Specified by:
      notify in interface org.pipservices4.components.exec.INotifiable
      Parameters:
      context - (optional) a context to trace execution through call chain.
      args - the parameters to raise this event with.
      Throws:
      org.pipservices4.commons.errors.ApplicationException - if the event fails to be raised.