Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Problem with IEventBroker(Problem with IEventBroker)
Problem with IEventBroker [message #734956] Mon, 10 October 2011 14:18 Go to next message
Beat Schaller is currently offline Beat SchallerFriend
Messages: 42
Registered: July 2009
Member
I am trying to use the EventBroker in my sample application.

I implemented a simple OSGI service. An initialization of the EventBroker over injection doesn't work. So I assume I have to initialize it the standard way in the constructor of my service. Correct?

Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx = EclipseContextFactory.getServiceContext(bundleContext);
eventBroker = (IEventBroker) eclipseCtx.get(IEventBroker.class.getName());

I get the following Exception:
org.eclipse.e4.core.di.InjectionException: Unable to process "EventBroker.logger": no actual value was found for the argument "Logger"

what's the problem??
Thx for any hints
Beat
Re: Problem with IEventBroker [message #735149 is a reply to message #734956] Tue, 11 October 2011 05:52 Go to previous messageGo to next message
Beat Schaller is currently offline Beat SchallerFriend
Messages: 42
Registered: July 2009
Member
I have now initialized the osgi service over the xml settings:

</service>
<reference bind="setEventAdmin" cardinality="1..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" policy="static"/>
</scr:component>

but the question is still interesting - why can't I initialize the EventBroker? Is this a problem of the new IEventBroker, a sequence of instantiating?
Re: Problem with IEventBroker [message #735243 is a reply to message #735149] Tue, 11 October 2011 10:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
The IEventBroker is *not* an OSGi-Service (OSGi has no idea about it)
but is created through an IContextFunction which *is* an OSGi-Service
and because the OSGi-Registry has no idea from e4 DI it can't resolve
IEventBroker!

Tom

Am 11.10.11 07:52, schrieb Beat:
> I have now initialized the osgi service over the xml settings:
>
> </service>
> <reference bind="setEventAdmin" cardinality="1..1"
> interface="org.osgi.service.event.EventAdmin" name="EventAdmin"
> policy="static"/>
> </scr:component>
>
> but the question is still interesting - why can't I initialize the
> EventBroker? Is this a problem of the new IEventBroker, a sequence of
> instantiating?
>
Re: Problem with IEventBroker [message #735250 is a reply to message #734956] Tue, 11 October 2011 10:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
The IEclipseContext created by the E4Application sets in the
root-context an Logger-Instance. If you are bootstraping your own
IEclipseContext you also have to set an Logger.

The problem you are facing generally here is that you are trying to use
DI-Stuff in a pure OSGi-Service Env where you don't have the default
IEclipseContext available which was created for the E4Application.

Tom

Am 10.10.11 16:18, schrieb Beat:
> I am trying to use the EventBroker in my sample application.
>
> I implemented a simple OSGI service. An initialization of the
> EventBroker over injection doesn't work. So I assume I have to
> initialize it the standard way in the constructor of my service. Correct?
>
> Bundle bundle = FrameworkUtil.getBundle(getClass());
> BundleContext bundleContext = bundle.getBundleContext();
> IEclipseContext eclipseCtx =
> EclipseContextFactory.getServiceContext(bundleContext);
> eventBroker = (IEventBroker) eclipseCtx.get(IEventBroker.class.getName());
>
> I get the following Exception:
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "EventBroker.logger": no actual value was found for the argument "Logger"
>
> what's the problem?? Thx for any hints
> Beat
Re: Problem with IEventBroker [message #735270 is a reply to message #735250] Tue, 11 October 2011 11:39 Go to previous messageGo to next message
Beat Schaller is currently offline Beat SchallerFriend
Messages: 42
Registered: July 2009
Member
Txh Tom to clarify...
Beat
Re: Problem with IEventBroker [message #739461 is a reply to message #735270] Mon, 17 October 2011 13:59 Go to previous messageGo to next message
Christian Hanster is currently offline Christian HansterFriend
Messages: 22
Registered: March 2011
Junior Member
I haven't understood the problem exactly.
I get the same error in a bundle-Activator of a e4-fragment-bundle.
When I now inject the IEventBroker in a part of the fragment it works. What I don't understand is why I can not inject the IEventBroker in the Activator.

Christian
Re: Problem with IEventBroker [message #739539 is a reply to message #739461] Mon, 17 October 2011 15:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You can only use Injection if stuff is created through the DI-Framework
which is not the case for the Activator whose instance is created by the
OSGi-Framework itself.

Tom

Am 17.10.11 15:59, schrieb christian-hanster:
> I haven't understood the problem exactly. I get the same error in a
> bundle-Activator of a e4-fragment-bundle. When I now inject the
> IEventBroker in a part of the fragment it works. What I don't understand
> is why I can not inject the IEventBroker in the Activator.
>
> Christian
Re: Problem with IEventBroker [message #739722 is a reply to message #739539] Mon, 17 October 2011 19:42 Go to previous messageGo to next message
Christian Hanster is currently offline Christian HansterFriend
Messages: 22
Registered: March 2011
Junior Member
Ok,
but also when I add the class to the DI it does not work:
Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx =   EclipseContextFactory.getServiceContext(bundleContext);
ContextInjectionFactory.make(helpers.BundleInit.class,eclipseCtx);


The BundleInit Class:
@Inject
public void hookEvents(IEventBroker events)
{
  //My Code
}

Probably I make an error in my logic but I cannot guess it yet.
Re: Problem with IEventBroker [message #740142 is a reply to message #739722] Tue, 18 October 2011 07:46 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So you say you don't get a IEventBroker injected? Do have Equinox-DS
running?

Tom

Am 17.10.11 21:42, schrieb christian-hanster:
> Ok,
> but also when I add the class to the DI it does not work:
>
> Bundle bundle = FrameworkUtil.getBundle(getClass());
> BundleContext bundleContext = bundle.getBundleContext();
> IEclipseContext eclipseCtx =
> EclipseContextFactory.getServiceContext(bundleContext);
> ContextInjectionFactory.make(helpers.BundleInit.class,eclipseCtx);
>
> The BundleInit Class:
>
> @Inject
> public void hookEvents(IEventBroker events)
> {
> //My Code
> }
>
> Probably I make an error in my logic but I cannot guess it yet.
Re: Problem with IEventBroker [message #740580 is a reply to message #740142] Tue, 18 October 2011 17:11 Go to previous messageGo to next message
Christian Hanster is currently offline Christian HansterFriend
Messages: 22
Registered: March 2011
Junior Member
Yes the plugin org.eclipse.equinox.ds is running. My Code in the BundleActivor-Start is:
public void start(BundleContext context) throws Exception {
	Bundle bundle = FrameworkUtil.getBundle(getClass());
	BundleContext bundleContext = bundle.getBundleContext();
	IEclipseContext eclipseCtx =   
	EclipseContextFactory.getServiceContext(bundleContext);
	ContextInjectionFactory.make(helpers.BundleInit.class,eclipseCtx);
	System.out.println("activate");		
}


The BundleInit.class is the class where the IEventBroker should be injected with the method I have written in the previous post.

Christian
Re: Problem with IEventBroker [message #749058 is a reply to message #740580] Tue, 25 October 2011 02:35 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 242
Registered: July 2009
Senior Member
As Tom alluded to earlier, you need to configure a Logger instance.

Basically, the implementor of IEventBroker is org.eclipse.e4.ui.services.internal.events.EventBroker, configured using DS through an IContextFunction. If you look at its definition, you'll see that it requires a org.eclipse.e4.core.services.log.Logger instance to be injected. But Logger is neither provided through DS using an IContextFunction, nor is it an OSGi service. Rather, it is defined by E4Application as it sets up the application's default context (see E4Application#createDefaultContext()).

Because a Logger instance cannot be found, and Logger is abstract (and hence can't be instantiated by the injection framework), the injection of EventBroker fails, and so the injection of your BundleInit fails too.

If you changed your code to something like the following

Bundle bundle = FrameworkUtil.getBundle(getClass());
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx =   
	EclipseContextFactory.getServiceContext(bundleContext);
// configure the logger
eclipseCtx.set(Logger.class, null);
ContextInjectionFactory.make(helpers.BundleInit.class,eclipseCtx);
System.out.println("activate");		


It would likely work (though you'll probably end up with an NPE from the null logger).
Re: Problem with IEventBroker [message #753812 is a reply to message #749058] Fri, 28 October 2011 21:22 Go to previous messageGo to next message
Christian Hanster is currently offline Christian HansterFriend
Messages: 22
Registered: March 2011
Junior Member
Thank you for the solution. It works quite good for my purpose.
Re: Problem with IEventBroker [message #1691071 is a reply to message #753812] Thu, 02 April 2015 07:02 Go to previous messageGo to next message
Piero Campalani is currently offline Piero CampalaniFriend
Messages: 114
Registered: January 2015
Senior Member

...not working here however.
Same identical task: I want to enable DI on a Java class instance I specify.
Same problem: Logger.

Curiously I could do this in plugin A but not on my new plugin B.
Plugin dependencies are just the same, what could be missing?

Caused by: org.eclipse.e4.core.di.InjectionException: Unable to process "EventBroker.logger": no actual value was found for the argument "Logger".
	at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:416)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:407)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:109)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:337)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at org.eclipse.e4.ui.services.events.EventBrokerFactory.compute(EventBrokerFactory.java:29)
	at org.eclipse.e4.core.internal.contexts.ValueComputation.get(ValueComputation.java:61)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.internalGet(EclipseContext.java:246)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.get(EclipseContext.java:213)
	at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:68)
	at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.runAndTrack(EclipseContext.java:319)
	at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier.get(ContextObjectSupplier.java:167)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:469)
	at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:397)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:109)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:337)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at com.ebotlution.c4ids.drivers.xbee.lifecycle.Activator.start(Activator.java:52)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)


thanks as always,
-Piero
Re: Problem with IEventBroker [message #1691078 is a reply to message #1691071] Thu, 02 April 2015 07:49 Go to previous message
Piero Campalani is currently offline Piero CampalaniFriend
Messages: 114
Registered: January 2015
Senior Member

Ok, problem is: it breaks only when the IEventBroker is injected.
Still this does not work for me:
eclipseCtx.set(Logger.class, null);
Previous Topic:Usage EMF models in E4 RCP
Next Topic:Logger-Layout?
Goto Forum:
  


Current Time: Thu Apr 18 09:04:27 GMT 2024

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

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

Back to the top