Hi Konrad,
actually the answer is no. There are other ways to tell Equinox to autostart a bundle. Actually there are three ways:
- Set the Bundle-ActivationPolicy: lazy policy
- Configure the autostart setting in the config.ini
- Implement a custom Configurator that does this for you
You already know point 1. The second option is the manual bundle start configuration via config.ini explained here:
https://www.eclipse.org/equinox/documents/quickstart-framework.php
The 3. option is something I did a few years ago when I struggled with the same topic:
https://github.com/fipro78/equinox-autoconfigurator
And actually it is not really a decision of the OSGi implementation in its core. It is a launcher topic. Also Apache Felix does not automatically
start every bundle. You have to configure it. But Felix has a global configuration that makes it easy to simply autostart all bundles. The bndlauncher from Bndtools automatically autostarts all bundles. Equinox made the decision to not autostart all bundles,
to avoid startup delays because of operations done in Activators, which was a quite common pattern in Eclipse plugins at the beginning.
BTW, bringing bundles from RESOLVED to STARTED typically happens if some other bundle requests a class from it. For services this typically
never happens if the interface is located in another bundle, because no one will ever request the service implementation class directly. And the same is true for an immediate component. No one will ever directly request an instance of the immediate component.
Therefore the bundle will never be automatically activated by OSGi if that is the only thing in the bundle. At least if I remember correctly.
😊
Dirk Fauth
ETAS Advance Engineering
T +49 711 3423-2174
Dirk.Fauth@xxxxxxxx
ETAS GmbH, ETAS/ENA
Borsigstraße 24, 70469 Stuttgart, Germany
www.etas.com
ETAS – Empowering Tomorrow’s Automotive Software
Managing Directors: Christoph Hartung, Günter Gromeier, Götz Nigge
Chairman of the Supervisory Board: Dr. Walter Schirm
Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart, HRB: 19033
Von: osgi-users <osgi-users-bounces@xxxxxxxxxxx> Im Auftrag von
Konrad Windszus
Gesendet: Donnerstag, 29. September 2022 19:01
An: This is a community mail list for OSGi technology. Any OSGi technical discussion or questions are acceptable here. <osgi-users@xxxxxxxxxxx>
Betreff: Re: [osgi-users] Framework: Auto-Start of Bundles with Immediate DS Components
Hi Jürgen,
But in fact what I see is the opposite:
Equinox does actually auto-start the bundle once it has the Bundle Header Bundle-ActivationPolicy: lazy being set, which feels wrong to me, as that bundle header should IMHO only defer starting, but in fact without it (i.e. default eager
activation) the bundle won’t be started at all.
So it seems that using Bundle-ActivationPolicy: lazy seems to be the only way (when not relying on explicit start levels) I can make Equinox start my bundle.
So is it a decision of the container implementation when and if transitioning a bundle from RESOLVED to STARTING (when no explicit start method is called on it)?
Hi Konrad,
in my early days, I was under a similar impression and was wondering what the logic behind all this is. The first thing is: it is more of an eclipse then an OSGi thing.
Components:
Components by themself have no influence of on the starting behavior of the bundle it lives in. If a Bundle is Started (or even in state starting, not sure) DS will recognize it and handle its declared components. If a Component is a Service and has immediate=true,
it will activate the service the moment all its references are satisfied. Components without a Service are immediate by default. Thus: DS will not start your Bundles.
Bundle-ActivationPolicy: lazy
After a Bundle is installed, the Framework tries to resolve it. So the Resolve states means, that all its Imports and Requirements are satisfied and it is exacted that all is classes can be properly loaded. At this point other bundles can load the Exported
Classes from the Bundle. This does require a Bundle to be active. Active only means that a Bundle Activator (if present) was called and that Components, Configurations or what ever else lurks in the Bundle has started doing something.
If the Bundle-ActivationPolicy is not lazy, it will be started automatically after the resolve state. If I have read the code correctly, this is done by the launcher who sits outside and not really framework itself.
Equinox has a bit of a special handling. Its Launcher (called EclipseStarter) installs all configured Bundles and then tries to start them if they don't have the Lazy policy. It then goes through the Lazy List and tries to start them according to the configured
start levels. (I hope I've gotten the order right here). So Lazy in the pure OSGi sense means, don't autostart as somebody will do it manually at some point.
So, when you want your Bundle to be started and your Components to be available don't set it to lazy (or in case of Eclipse and RCP you can also set a startlevel for it).
Hope this helps,
Jürgen.
Am 29/09/2022 um 17:56 schrieb Konrad Windszus:
Hi,
I observed an issue in Equinox with Bundles not being automatically started although they do have DS components with an immediate flag in it.
From
https://docs.osgi.org/specification/osgi.core/8.0.0/framework.lifecycle.html#i3270328 it is not quite clear to me under which circumstances the framework can decide to leave a bundle in RESOLVED state.
It seems to depend on its internal autostart setting, which according to chapter 4.4.5 of OSGi Core can have one of three values:
• Stopped - The bundle should not be started.
• Started with eager activation - The bundle must be started once it is ready and it must then be eagerly activated.
• Started with declared activation
Under which particular circumstances is a Framework supposed to start a bundle automatically (given its autostart setting is not set to Stopped)
1. Once a class is requested from it?
2. It defines some DS components (does the immediate flag matter here)?
What I observed is that Equinox does actually auto-start the bundle once it has the Bundle Header Bundle-ActivationPolicy: lazy being set, which feels wrong to me, as that bundle header should IMHO only defer starting, but in fact without it (i.e. default eager
activation) the bundle won’t be started at all.
Thanks in advance for your PoV on this matter
Konrad
_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users
--
Jürgen Albert
CEO
Chair Eclipse OSGi Working Group Steering Committee
Data In Motion Consulting GmbH
Kahlaische Str. 4
07745 Jena
Mobil: +49 157-72521634
E-Mail: j.albert@xxxxxxxxxxxxxxx
Web: www.datainmotion.de
XING: https://www.xing.com/profile/Juergen_Albert5
LinkedIn: https://www.linkedin.com/in/juergen-albert-6a1796/
Rechtliches
Jena HBR 513025
_______________________________________________
osgi-users mailing list
osgi-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/osgi-users