Java Reference
In-Depth Information
The Fragment-Host header is somewhat confusingly named, because it seems to be
declaring the bundle as a host; it should be read as “require fragment host.” Although
this header value follows the common OSG i syntax, you can't specify multiple symbolic
names. A fragment is limited to belonging to one host bundle, although it may be
applicable to a range of host versions. Note that you don't need to do anything special
to define a bundle as a host; any bundle without a Fragment-Host header is a poten-
tial host bundle. Likewise, any bundle with a Fragment-Host header is a fragment.
You now understand the relationship between a host and its fragments, but how do
they work together? When the framework resolves a bundle, it searches the installed
bundles to see if there are any fragments for the bundle being resolved. If so, it merges
the fragments into the host bundle. This merging happens in two different ways:
Physically— The content and metadata from the fragments are conceptually
merged with the host's content and metadata.
Logically —Rather than giving each fragment its own class loader, the framework
attaches the fragment content to the host's class loader.
The first form of merging recombines the split physical pieces of the logical bundle,
and the second form creates a single logical bundle because OSG i uses a single class
loader per logical bundle to achieve encapsulation.
Fragments and package-private access
As a technical side note, Java only allows package-private access to classes loaded
by the same class loader. Two classes in the same package, but loaded by two dif-
ferent class loaders, can't access each others' package-private members. By loading
fragment classes with the host's class loader, the fragment classes are properly
recombined to avoid this issue. This isn't true for split packages accessed through
Require-Bundle . This isn't always important, but the distinction between these two
forms of support for split packages is worth understanding.
Returning to the discussion about resolving a bundle, if the bundle being resolved has
fragments, the framework merges their metadata with the host's and resolves the bundle
as normal. Figure 5.11 illustrates the before- and after effects of the merging process.
Host
Fragment
a)
Figure 5.11 a) The host and fragment
bundles are deployed as independent
bundles in the framework. b) When the
framework resolves the host, it effectively
merges the fragment's content and
metadata into the host bundle.
Fragment
b)
Fragment
Host
 
Search WWH ::




Custom Search