Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How do you inject the IEventBroker in an OSGi service ?
How do you inject the IEventBroker in an OSGi service ? [message #1005889] Tue, 29 January 2013 03:45 Go to next message
Erik Vande Velde is currently offline Erik Vande Velde
Messages: 62
Registered: September 2012
Member
In an MVC world you want to send events from a controller/service, not from a view object. In our project that controller is an OSGi service, as we create it with spring dynamic modules (to use spring based remoting). How can we send events thru the IEventBroker from this non E4 service?
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005902 is a reply to message #1005889] Tue, 29 January 2013 04:19 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
There are multiple threads on this topic already, IEventBroker lives
above the OSGi-Level.

The reason is that we want to support multiple workbench instances in
future versions so you'll have multiple IEventBroker instances bound to
different application instances (see e.g. the Vaadin Renderers who use
this already today). I leave out the fact the EventBroker instances are
created when needed on the requesting context through a ContextFunction
(freeing you to clean up when context goes away!)

There is a feature request to publish application instances as
OSGi-Services so one could get rid of the running applications and get
access to the IEclipseContext and get the IEventBroker.

The bug is: https://bugs.eclipse.org/bugs/show_bug.cgi?id=398297

A current implementation detail of the IEventBroker is that is use the
EventAdmin-Service from OSGi which you can get access already today but
you rely on an implementation detail.

Tom

Am 29.01.13 09:45, schrieb Erik Vande Velde:
> In an MVC world you want to send events from a controller/service, not
> from a view object. In our project that controller is an OSGi service,
> as we create it with spring dynamic modules (to use spring based
> remoting). How can we send events thru the IEventBroker from this non E4
> service?
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005913 is a reply to message #1005902] Tue, 29 January 2013 04:52 Go to previous messageGo to next message
Erik Vande Velde is currently offline Erik Vande Velde
Messages: 62
Registered: September 2012
Member
Thanks for the fast reaction! Another suggestion we found on the web is to create a declarative service, and put it in a/the context thru an AddOn.
Sample code fragment:
---
public class ControllerAddon {
@PostConstruct
void hookListeners(IEclipseContext context) {
Controller controller = ContextInjectionFactory.make(Controller.class, context);
context.set(Controller.class, controller);
}
---
Here we can inject
1) the IEventBroker into that Controller class
2) our OSGi service into the same Controller, and delegate from the Controller to the OSGi service.
The injection indeed works. If we set a breakpoint on the context.set above we see both injected fields. But when we inject our controller in a List Part we see another instance, with null IEventBroker and OSGi service. Do you have an idea why E4 creates a new controller for the List Part, instead of using the one we created in the AddOn?
We put a @Singleton annotation on the controller, but that didn't help ...
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005916 is a reply to message #1005913] Tue, 29 January 2013 04:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
You are putting it in the wrong context, you need to put it into the one
of your MApplication.

public class ControllerAddon {
@PostConstruct
void hookListeners(..., MApplication app) {
Controller ...
app.getContext(Controller.class, controller);
}
}

Tom

Am 29.01.13 10:52, schrieb Erik Vande Velde:
> Thanks for the fast reaction! Another suggestion we found on the web is
> to create a declarative service, and put it in a/the context thru an AddOn.
> Sample code fragment:
> ---
> public class ControllerAddon {
> @PostConstruct
> void hookListeners(IEclipseContext context) {
> Controller controller = ContextInjectionFactory.make(Controller.class,
> context);
> context.set(Controller.class, controller);
> }
> ---
> Here we can inject 1) the IEventBroker into that Controller class
> 2) our OSGi service into the same Controller, and delegate from the
> Controller to the OSGi service.
> The injection indeed works. If we set a breakpoint on the context.set
> above we see both injected fields. But when we inject our controller in
> a List Part we see another instance, with null IEventBroker and OSGi
> service. Do you have an idea why E4 creates a new controller for the
> List Part, instead of using the one we created in the AddOn?
> We put a @Singleton annotation on the controller, but that didn't help ...
Re: How do you inject the IEventBroker in an OSGi service ? [message #1005941 is a reply to message #1005916] Tue, 29 January 2013 06:18 Go to previous message
Erik Vande Velde is currently offline Erik Vande Velde
Messages: 62
Registered: September 2012
Member
OK Tom, now it's working. Of course this is only a temporary solution, because the delegation from the E4 declarative service to the spring-created OSGi service isn't ideal, but at least we can proceed with other things. It's clear there are many people looking forward to the implementation of https://bugs.eclipse.org/bugs/show_bug.cgi?id=398297 !!!
Previous Topic:Some questions about logging
Next Topic:How to inject a service, which has the IEventBroker injected in it, in an Eclipse part
Goto Forum:
  


Current Time: Mon Apr 21 05:48:25 EDT 2014

Powered by FUDForum. Page generated in 0.03407 seconds