|
|
|
Re: Using declared osgi services inside an RCP application [message #547615 is a reply to message #547577] |
Mon, 19 July 2010 07:23 |
Daniel Krügler Messages: 853 Registered: July 2009 |
Senior Member |
|
|
On 19.07.2010 03:31, elgabo81@gmail.com wrote:
> Hi Tom,
>
> I think that the osgi runtime must call it automagically, because there
> is plugin that defines a service (service plugin) and another one that
> consumes it (ui plugin).
You did not explain in any word that your Activator class is also
supposed to be an osgi component. Your new description implies this
somehow, but that was not clear from begin with.
> But I think I found something interesting. The Activator.setModel method
> is being called, but not for the correct instance.
It's not clear what you mean with this. Note that an osgi bundle
activator and an osgi component are conceptually different things.
It is true, that some aspects allow to compare the specification
of an bundle activator to behave *similar* to a component, but
the osgi spec does not say that an bundle activator *is* an osgi
component. So you cannot impose requirements on a type that you
use for *both* an activator and a component. In fact, I would
strongly recommend to *never* mix these responsibilities.
> The "Component Resolve Thread" is instancing the ui plugin Activator
class twice:
>
> 1) AbstractBundle.loadBundleActivator() line 151
> 2) ServiceComponent.createInstance line 457
>
> The method start(BundleContext) of the first instance is gets called and
> the method setModel(IModel) of the second instance gets called. So the
> model is not being setted correctilly on the singleton instance. Is
> there a plugin.xml or component.xml configuration that prevents this
> from happening?
>
> I worked around this issue using this code:
>
>
> public void setModelo(IModelo model) {
> Activator.getDefault().model=model;
> }
>
> public void unsetModelo(IModel model) {
> Activator.getDefault().model=null;
> }
>
I would separate concerns. Don't make the bundle activator an osgi
component. Just define a separate osgi component and if user-code
should be able to access the model via the activator as well, it is
easy to solve this as you describe above:
public void setModelo(IModelo model) {
Activator.getDefault().setModel(model);
}
public void unsetModelo(IModel model) {
Activator.getDefault().setModel(null);
}
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03277 seconds