How is the OSGi bundle start level defined?
I am using Apache felix and would like to persist the start level across framework executions. I do not anticipate a need to change the start level of a bundle very frequently at all an an entry in Manifest.MF seems the most sensible. I've to org.osgi.framework.startlevel but have not seen a practical example.
I am also using maven with the maven-bundle-plugin, if there is an elegant way to incorporate the start level in the POM that would be brilliant.
How does OSGi work? OSGi is a set of specifications that define a dynamic component system for Java. These specifications allow for a development model in which an application is composed of several components, and then packed into bundles. These components communicate locally and through the network via services.
A BundleContext object is generally for the private use of its associated bundle and is not meant to be shared with other bundles in the OSGi environment. The Bundle object associated with a BundleContext object is called the context bundle.
An OSGi bundle is a Java™ archive file that contains Java code, resources, and a manifest that describes the bundle and its dependencies. The bundle is the unit of deployment for an application. This article is meant for developers wanting to create OSGi service or a servlet using AEM Forms 6.4 or 6.5.
Bundles don't define their own start level at build-time; the administrator or agent that installs the bundle into the framework defines it.
The core framework defines a Start Level interface in section 8. Quoting:
The Start Level API provides the following functions:
Controls the beginning start level of the OSGi Framework.
Is used to modify the active start level of the Framework.
Can be used to assign a specific start level to a bundle.
Can set the initial start level for newly installed bundles.
The last two are relevant to your inquiry here. Section 8.3.4—Changing a Bundle's Start Level—indicates that the framework will store an assigned start level persistently.
If you're using Apache Felix, there are several ways you can install bundles and assign their start level, whether explicitly or by allowing them to inherit a default start level for installed bundles:
felix.fileinstall.start.level
property, though it's not per-bundle)felix.auto.install.<n>
property)bundlelevel
command)Also, see the felix.startlevel.bundle
property, which controls bundles installed through means other than those above.
As for setting a manifest property (such as with Maven at build time), there used to be a way to do this in Equinox—now deprecated—but there is no standard means for a bundle to indicate to the framework what its proper start level should be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With