Let me ask two related questions that can boil down to one good application design; -)
- What is the best practice for using event-based communications in the e4 RCP application?
- How can I write simple unit tests (using JUnit) for classes that send / receive events using dependency injection and IEventBroker?
Let's be more specific: let's say I'm developing an Eclipse e4 RCP application consisting of several plugins that need to exchange data. For communication, I want to use the event service provided by org.eclipse.e4.core.services.events.IEventBroker, so my plugins remain loosely coupled. I use dependency injection to inject an event broker into a class that dispatches events:
@Inject static IEventBroker broker;
private void sendEvent() {
broker.post(MyEventConstants.SOME_EVENT, payload)
}
On the receiver side, I have a method like:
@Inject
@Optional
private void receiveEvent(@UIEventTopic(MyEventConstants.SOME_EVENT) Object payload)
Now the questions are:
IEventBroker IEclipseContext. , , e4, , , ContextInjectionFactory.inject(myEventSendingObject, context);
, , , . E4?
JUnit , ( , )? , , . , , . , IEventBroker?
IEclipseContext DI . , , JUnit Plug-in, , PDE unit test. , .
" IEventBroker". , ! , , .
, - , ? , ? / ?