OSGi component handling e4 Events

Eclipse e4 has its own event broker for handling events. Under the hood it uses the OSGi event handling components like EventHandler.

Receiving e4 events

Internally Eclipse e4 wraps every object send via the map into a Map (if it is not by itself a Map). The passed object is added to the map with the key IEventBroker.DATA which resolves to the String “data”.

The OSGi component needs to set the topic which it should listen to in the component definition as the property event.topics and should implement the EventHandler interface from the OSGi runtime.

public void handleEvent(Event event) {
    Object data = event.getProperty(IEventBroker.DATA);

Sending e4 events

To send e4 events you just need to wrap your object into a map with the key “data”.

	private void postEvent(String topic, Object value) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(IEventBroker.DATA, value); 				

		Event event = new Event(topic, map);