Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

org.apache.cloudstack.framework.events.Event event = new Event(....define the paras params as required....)

s_eventBus.publish(event);

 

Subscribing to events

 

To subscribe to events your component can do as described below.

 

Implement interface EventSubscriber where 'onEvent' is callback function that receives callback on an event occurs. To subscribe to the events, create the 'EventTopic' that defined the events that your component is interested in subscribing to and register with event bus.

For e.g if your component is interested in subscribing to all the action events corresponding to VM resource then you would create EventTopic as below and subscribe with the event bus.

 

public class VmActionEventHandler implements EventSubscriber {

    @Override
    public void onEvent(Event event) {

        // handle the event here
    }
}

 

EventTopic topic = new EventTopic(EventCategory.ACTION_EVENT.getName(), VirtualMachine.class.getName(), null, null, null);

_eventBus.subscribe(topic, new VmActionEventHandler());