Problem with IEventBroker [message #734956] |
Mon, 10 October 2011 10:18  |
Eclipse User |
|
|
|
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 #749058 is a reply to message #740580] |
Mon, 24 October 2011 22:35   |
Eclipse User |
|
|
|
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).
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06532 seconds