Java Reference
In-Depth Information
Despite these dire-sounding warnings, OSG i provides another way of dealing with
split packages, called bundle fragments . We'll talk about those shortly, but first we'll dis-
cuss some of the issues surrounding bundle dependencies and split packages.
5.3.3
Issues with bundle dependencies
Using Import-Package and Export-Package is the preferred way to share code
because they couple the importer and exporter to a lesser degree. Using Require-
Bundle entails much higher coupling and lower cohesion between the importer and
the exporter and suffers from other issues, such as the following:
Mutable exports —Requiring bundles are impacted by changes to the exports of
the required bundle, which introduce another form of breaking change to con-
sider. Such changes aren't always easily apparent because the use of reexport
visibility can result in chains of required bundles where removal of an export in
upstream required bundles breaks all downstream requiring bundles.
Shadowing —Because class searching continues across all required bundles and
the requiring bundle's class path, it's possible for content in some required
bundles to shadow other required bundle content and the content of the
requiring bundle itself. The implications of this aren't always obvious, especially
if some bundles are optionally required.
Ordering —If a package is split across multiple bundles, but they contain overlap-
ping classes, the declared order of the Require-Bundle header is significant. All
bundles requiring the bundles with overlapping content must declare them in
the same order, or their view of the package will be different. This is similar to
traditional class path ordering issues.
Completeness —Even though it's possible to aggregate split packages using a
facade bundle, the framework has no way to verify whether an aggregated pack-
age is complete. This becomes the responsibility of the bundle developer.
Restricted access —An aggregated split package isn't completely equivalent to the
unsplit package. Each portion of the split package is loaded by its containing
bundle's class loader. In Java, classes loaded by different class loaders can't
access package-private members and types, even if they're in the same package.
This is by no means an exhaustive list of issues, but it gives you some ideas of what to
look out for when using Require-Bundle and (we hope) dissuades you from using it
too much.
Enough of the scare tactics. So far, we've introduced you to some of the more
advanced features of managing OSG i dependencies, including importing exports,
implicit export attributes, mandatory export attributes, export filtering, duplicate
exports, optional and dynamic imports, and requiring bundles. These tools allow you
to solve some of the more complex edge cases found when migrating a classic Java
application to an OSG i environment. That must be it—we must have covered every
possible mechanism of specifying dependencies, right? Not quite. There's one more
Search WWH ::




Custom Search