Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Letting a custom class inject services
icon5.gif  Letting a custom class inject services [message #1691156] Thu, 02 April 2015 15:51 Go to next message
Piero Campalani is currently offline Piero CampalaniFriend
Messages: 110
Registered: January 2015
Senior Member

Dear experts,
I would like to let my class C of plugin P inject its own stuff.

Like explained in [1], I register a service which provides a org.eclipse.e4.core.services.log.Logger (via Activator, but I tried with a DS too: same thing), then inject my class in the bundle context.

I reproduced my scenario in a minimal project, which I hereby attach for volunteers.

It has an activator (Activator.java) and a command handler (FooHandler.java) which handles the Foo Item model button and triggers the instantiation of a Foo object, which is the guy who I want to inject whatever he wants.

The error I get is pasted in [2].
If I remove the injection of the IEventBroker, I get no error but the injected IEclipseContext is null.

[1] https://www.eclipse.org/forums/index.php?t=msg&th=370090&goto=904549&#msg_904549
[2] http://dpaste.com/3TVAZYW

I tried any sort of things, all day long, can't get rid of the Logger error.
Thanks for any help, I am that close to smashing my keyboard inside the screen and runaway screaming!

@see https://www.eclipse.org/forums/index.php?t=msg&th=389240&goto=956075&#msg_956075
@see https://www.eclipse.org/forums/index.php?t=msg&th=389240&goto=928693&#msg_928693
  • Attachment: TestOSGi.zip
    (Size: 10.51KB, Downloaded 45 times)
Re: Letting a custom class inject services [message #1691169 is a reply to message #1691156] Thu, 02 April 2015 18:04 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6363
Registered: July 2009
Senior Member
Hi,

Why are you doing this stuff at the OSGi-Level? Maybe you should start
describing your use case.

Tom

On 02.04.15 17:51, Piero Campalani wrote:
> Dear experts,
> I would like to let my class C of plugin P inject its own stuff.
>
> Like explained in [1], I register a service which provides a org.eclipse.e4.core.services.log.Logger (via Activator, but I tried with a DS too: same thing), then inject my class in the bundle context.
>
> I reproduced my scenario in a minimal project, which I hereby attach for volunteers.
>
> It has an activator (Activator.java) and a command handler (FooHandler.java) which handles the Foo Item model button and triggers the instantiation of a Foo object, which is the guy who I want to inject whatever he wants.
>
> The error I get is pasted in [2].
> If I remove the injection of the IEventBroker, I get no error but the injected IEclipseContext is null.
>
> [1] https://www.eclipse.org/forums/index.php?t=msg&th=370090&goto=904549&#msg_904549
> [2] http://dpaste.com/3TVAZYW
>
> I tried any sort of things, all day long, can't get rid of the Logger error.
> Thanks for any help, I am that close to smashing my keyboard inside the screen and runaway screaming!
>
> @see https://www.eclipse.org/forums/index.php?t=msg&th=389240&goto=956075&#msg_956075
> @see https://www.eclipse.org/forums/index.php?t=msg&th=389240&goto=928693&#msg_928693
>
Re: Letting a custom class inject services [message #1691191 is a reply to message #1691169] Fri, 03 April 2015 04:58 Go to previous messageGo to next message
Piero Campalani is currently offline Piero CampalaniFriend
Messages: 110
Registered: January 2015
Senior Member

Thank you Tom, sure.

Use case is: I have a plugin, a driver for a network card, which asynchronously listens to incoming frames. So I want this asynchronous listener to spread the word about incoming frames on the events bus so that my client plugins can react the way they want.

The first thing that came to my mind was then to give DI powers to my driver listener so that it could require an event broker and send/post stuff with it.

Is there some more convenient alternative?

Thanks Tom and anybody who is supporting and developing this powerful technology the FLOSS way.
Re: Letting a custom class inject services [message #1691197 is a reply to message #1691191] Fri, 03 April 2015 08:09 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6363
Registered: July 2009
Senior Member
Simply use the EventAdmin (which is an OSGi-Service) to post your
information, just take a look how IEventBroker does use it internally
and your are done.

The only other solution is that you fetch the
org.eclipse.e4.ui.workbench.IWorkbench from the OSGi-Registry (note it
might not be there when your bundles activator is running so you need to
use a service-tracker or use a DS-Component who has IWorkbench as a
reference) and from there you grab the IEventBroker.

Tom

On 03.04.15 06:58, Piero Campalani wrote:
> Thank you Tom, sure.
>
> Use case is: I have a plugin, a driver for a network card, which
> asynchronously listens to incoming frames. So I want this asynchronous
> listener to spread the word about incoming frames on the events bus so
> that my client plugins can react the way they want.
>
> The first thing that came to my mind was then to give DI powers to my
> driver listener so that it could require an event broker and send/post
> stuff with it.
>
> Is there some more convenient alternative?
>
> Thanks Tom and anybody who is supporting and developing this powerful
> technology the FLOSS way.
Re: Letting a custom class inject services [message #1691555 is a reply to message #1691197] Wed, 08 April 2015 07:42 Go to previous message
Piero Campalani is currently offline Piero CampalaniFriend
Messages: 110
Registered: January 2015
Senior Member

Thank you Tom, that's a useful advice.

I'll go with OSGi events.

For interested readers, @see org.eclipse.e4.ui.services.internal.events.EventBroker for an implementation of the IEventBroker interface.
Previous Topic:Usage EMF models in E4 RCP
Next Topic:Managing Perspective Lifecycle in Eclipse 4
Goto Forum:
  


Current Time: Wed Oct 18 18:42:31 GMT 2017

Powered by FUDForum. Page generated in 0.01782 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software