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: 5487
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: 5487
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: 5487
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: 5487
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 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.
Previous Topic:messages_de_DE.properties cannot be load
Next Topic:WebDAV and SFS
Goto Forum:
  


Current Time: Mon Dec 22 22:41:59 GMT 2014

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

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