No events received when I listen outside the class who sends [message #1619227] |
Mon, 16 February 2015 12:27 |
|
Dear experts,
I am sending my event through the bus but event listeners are seemingly not waken up by it. Only those listeners within the same class/file where the event is sent, react to it.
It seems to me that only classes directly linked to the application model via classURI are connected to the event bus... I also tried also with Eclipse events like UIEvents.UILifeCycle.APP_STARTUP_COMPLETE and still only the UI handlers receives the signal.
Is this an expected behaviour, and in this case: how would I be able to include all my classes in the happy yellow Event submarine system?
For instance:
public class WhateverWherever {
@Inject
@Optional
private void postAppComplete(
@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) {
// Start listening socket;
System.out.println("No way to get here.");
// do stuff
// [...]
}
}
thanks for your support,
-Piero
|
|
|
|
Re: No events received when I listen outside the class who sends [message #1620618 is a reply to message #1619588] |
Tue, 17 February 2015 10:03 |
|
Thank you Dirk.
Do you mean if I ContextInjectionFactory.inject() my WhateverWherever class in the example somewhere in the plugin? No, I didn't and I am sorry if I missed that somewhere in the docs.
In practice... does this mean that the scope of the events' bus is delimited by those classes in the application context?
Which means, without further programmer intervention, command or part handlers or anyway any class referred to in the application model (via classURI) ?
As Lars (thank you Lars for all the material you provide, God bless you) or one of his slaves writes in [1], the event bus is not aware of the context hierarchy (so no events' hierarchy neither) but I interpreted this as "events bus and context are completely separate things." I'd like to fully understand the logic here
[1] http://www.vogella.com/tutorials/Eclipse4EventSystem/article.html#eventsystem_summary
Meanwhile, my working workaround is now to implement a pure-OSGi "event handler" as org.osgi.service.event.EventHandler, and by registering it in the plugin activator:
public class Activator implements BundleActivator {
public static final String MY_EVENT = "myEvent";
[...]
@Override
public void start(BundleContext bundleContext) throws Exception {
[...]
/*** REGISTER MY_EVENT HANDLER ***/
String topic = MY_EVENT;
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, topic);
ServiceRegistration eventRegistration = context
.registerService(EventHandler.class.getName(),
new WhateverWherever(),
properties);
eventRegistration.getReference();
}
}
public class WhateverWherever implements EventHandler {
/*** HANDLE MY_EVENT EVENT ***/
@Override
public void handleEvent(Event event) {
System.out.println("Event received : https://sometimesigetangry.files.wordpress.com/2011/06/fuck_yea_in_hd_by_crusierpl_re_sharenator_is_growing-s900x773-1208112.png.");
// do stuff
// [...]
}
}
Still in this case I am not able to obtain a complete integration of my WhateverWherever class in the Eclipse event's bus, so I won't be able to register to events like APP_STARTUP_COMPLETE or other {@link org.eclipse.e4.ui.workbench.UIEvents}.
Thanks again for your patience, to all.
-Piero
|
|
|
|
Powered by
FUDForum. Page generated in 0.02150 seconds