I need to send an event with the EventBroker of the eclipse e4 framework. Everything is working ( String, List ...) except a Map Instance.
Map<String, String> test = new LinkedHashMap<>();
test.put("test1", "1");
test.put("test2", "2");
broker.send(EventConstants.EXTENDED_SEARCH_ACTICE_HEADER, test);
And the receiving part
@Inject
@Optional
public void onExtendedSearchActiveHeaderEvent(
@UIEventTopic(EventConstants.EXTENDED_SEARCH_ACTICE_HEADER) Map<String, String> test) {
System.out.println(test.size());
}
Exception while dispatching event org.osgi.service.event.Event
Followed - of course - a NullPointer Exception
The event broker send
(and post
) methods treat a Map
argument specially and expect it to contain the complete event. This has the side effect that the @UIEventTopic
does not think there is any Map
data.
To deal with this use:
Map<String, Object> eventMap = new HashMap<String, Object>();
// Your map goes under the `IEventBroker.DATA` key
eventMap.put(IEventBroker.DATA, test);
broker.send(EventConstants.EXTENDED_SEARCH_ACTICE_HEADER, eventMap);