You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Luc Dewavrin <lu...@gmail.com> on 2009/04/28 22:39:31 UTC
Bundle and components lifecycles.
Hi,
I have a newbie question regarding bundle lifecycle and declarative services
lifecycle : are they linked together ?
I would like the services of my bundle to be singletons and my bundle should
be activated only when services are instantiated. Is it possible to do that
by configuration ?
Can a service by declaration become a singleton in my bundle ( a la Spring
container) ? i mean all the services dependent on that service should be
bound with the same implementation (for a given bundle).
Considering that my service is a singleton. If i instantiate it in the
bundle activator, can i force my bundle to be activated only when the
service is loaded ?
Thanks for your help,
Luc
Re: Bundle and components lifecycles.
Posted by Clement Escoffier <cl...@gmail.com>.
On 28.04.2009, at 22:39, Luc Dewavrin wrote:
> Hi,
>
> I have a newbie question regarding bundle lifecycle and declarative
> services
> lifecycle : are they linked together ?
Your DS components are created and activated only if the bundle
containing them is ACTIVE (i.e. started). As soon as this bundle is
stopped, your components are disposed.
>
> I would like the services of my bundle to be singletons and my
> bundle should
> be activated only when services are instantiated. Is it possible to
> do that
> by configuration ?
>
>
> Can a service by declaration become a singleton in my bundle ( a la
> Spring
> container) ? i mean all the services dependent on that service
> should be
> bound with the same implementation (for a given bundle).
Not sure about DS because it uses the global service registry. But it
should use the "better" available service provider. So, if you use the
"service.ranking" property you can achieve this (every consumer will
se the best provider). However for sure iPOJO supports that thanks to
its composite. A composite is a kind of isolated service registry, so
every component instance living in the composite use only services
from this service registry.
>
>
> Considering that my service is a singleton. If i instantiate it in the
> bundle activator, can i force my bundle to be activated only when the
> service is loaded ?
Maybe it is possible to to that with the lazzy activation. So, the
bundle is activated only when the first class of the bundle is loaded.
Clement
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Bundle and components lifecycles.
Posted by Christopher Armstrong <ca...@fastmail.com.au>.
Hi
Unfortunately everything is the other way around. The services in OSGi
are not really "instantiated", but "registered". Your bundle needs to
be activated, and then it registers the services in the framework.
When another bundle requests the services, they need to be published
into the framework first.
It should be impossible for the scenario where a bundle to requests a
service, and as a result, causes a bundle to be activated. This is
because the services model doesn't tie bundles to services - any
bundle can have code implements and publishes the same service
interface, so it is impossible for the framework to know which bundle
it should activate (especially if there is more than one).
Declarative services is an OSGi spec that covers an extension which
allows your bundle's "components" to be published as services when it
is activated. You can register "delayed" components which are
registered in the framework, but not "configured" (see DS
specification) until they are requested, however your bundle must be
activated of course.
Cheers
Chris
On 29/04/2009, at 6:39 AM, Luc Dewavrin wrote:
> Hi,
>
> I have a newbie question regarding bundle lifecycle and declarative
> services
> lifecycle : are they linked together ?
> I would like the services of my bundle to be singletons and my
> bundle should
> be activated only when services are instantiated. Is it possible to
> do that
> by configuration ?
>
>
> Can a service by declaration become a singleton in my bundle ( a la
> Spring
> container) ? i mean all the services dependent on that service
> should be
> bound with the same implementation (for a given bundle).
>
> Considering that my service is a singleton. If i instantiate it in the
> bundle activator, can i force my bundle to be activated only when the
> service is loaded ?
>
> Thanks for your help,
> Luc
--------
Christopher Armstrong
carmstrong@fastmail.com.au
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org