Java Reference
In-Depth Information
3.5
Lifecycle and modularity
A two-way relationship exists between OSG i's lifecycle and module layers. The lifecycle
layer manages which bundles are installed into the framework, which obviously
impacts how the module layer resolves dependencies among bundles. The module
layer uses the metadata in bundles to make sure all their dependencies are satisfied
before they can be used. This symbiotic relationship creates a chicken-and-egg situa-
tion when you want to use your bundles; to use a bundle you have to install it, but to
install a bundle you must have a bundle context, which are only given to bundles. This
close relationship is also obvious in how the framework resolves bundle dependencies,
especially when bundles are dynamically installed and/or removed. Let's explore this
relationship by first looking into bundle dependency resolution.
3.5.1
Resolving bundles
The act of resolving a bundle happens at the discretion of the framework, as long as it
happens before any classes are loaded from the bundle. Often, when resolving a given
bundle, the framework ends up resolving another bundle to satisfy a dependency of the
original bundle. This can lead to cascading dependency resolution, because in order
for the framework to use a bundle to satisfy the requirements of another bundle, the
satisfying bundle too must be resolved, and so on. Because the framework resolves
dependencies when needed, it's possible to mostly ignore transitioning bundles to the
RESOLVED state; you can start a bundle and know the framework will resolve it before
starting it, if possible. This is great compared to the standard Java way, where you can
run into missing dependencies at any point during the lifetime of your application.
But what if you want to make sure a given bundle resolves correctly? For example,
maybe you want to know in advance whether an installed bundle can be started. In
this case, there's a way to ask the framework to resolve the bundle directly, but it's not
a method on Bundle like most other lifecycle operations. Instead, you use the Package
Admin Service. The Package Admin Service is represented as an interface and is
shown here:
public interface PackageAdmin {
static final int BUNDLE_TYPE_FRAGMENT = 0x00000001;
Bundle getBundle(Class clazz);
Bundle[] getBundles(String symbolicName, String versionRange);
int getBundleType(Bundle bundle);
ExportedPackage getExportedPackage(String name);
ExportedPackage[] getExportedPackages(Bundle bundle);
ExportedPackage[] getExportedPackages(String name);
Bundle[] getFragments(Bundle bundle);
RequiredBundle[] getRequiredBundles(String symbolicName);
Bundle[] getHosts(Bundle bundle);
void refreshPackages(Bundle[] bundles);
boolean resolveBundles(Bundle[] bundles);
}
You can explicitly resolve a bundle with the resolveBundles() method, which takes
an array of bundles and returns a Boolean flag indicating whether the bundles could
Search WWH ::




Custom Search