Reputation: 505
I am developing an RCP application based on Eclipse 4 application platform.
My application consists of several own OSGi bundles implemented as declarative services. Now I want to make use of the IEventBroker
service which I can use in my application quite nicely.
But is it possible to use the IEventBroker
service in my separate bundles? Injecting the service as field does not work:
@Inject IEventBroker eventBroker;
And injecting the service in constructor of my class does not work also:
@Inject
public TestUserService(IEventBroker eventBroker) {
..
}
The injected eventBroker
is NULL
every time. Is the usage of IEventBroker
possible in own OSGi bundles in general? Do I have to add any required plugins into my bundle? Is there another way to get such services into own OSGi bundles?
Upvotes: 2
Views: 1834
Reputation: 1153
I know, it's a little late know to answer this question, but I was struggeling with it, too. I was able to solve it with the help of Tom Schindel (e(fx)clipse) and Lars vogel (vogella turials, e.g. the EventAdmin tutorial).
I later suggested an update of this tutorial to Lars, that he could integrate my findings into his tutorial (I don't know if he already did it, though)
In short term, you need to integrate the following additional bundles (see Lars Vogel's tutorial for the others) into your program:
Additionally, I needed to change the Event catching method annotation a bit:
@Inject handleSomething(@Optional @EventTopic("foo") Object bar) {...}
instead of
@Inject @Optional handleSomething(@UIEventTopic("foo") Object bar) {...}
Be aware, that since I didn't want to make use of e4, in preference to JavaFX, so you might still need to use UIEventTopic, while I needed to switch to plain EventTopic - which results in restriction warnings :-(
I hope, that you might still be interessted in it and you can make use of it!
Upvotes: 2
Reputation: 19606
@Inject does not work for pure bundles. You need to use either an Activator or a dependency injection mechanism like Blueprint or DS.
So try to lookup the IEventBorker as an OSGi service using one of the above mechanisms and inject it into you class.
Upvotes: 1