Java Reference
In-Depth Information
Before version 4 of OSG i, substitutability was guaranteed; a bundle implicitly imported
all the packages it exported. From version 4 onward, substitutability must be explicitly
enabled by importing exported packages. This is an OSG i best practice. The following
manifest exports a substitutable package:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.supermarket.core
Bundle-Version: 1.0.0
Export-Package: com.supermarket.api
Import-Package: com.supermarket.api, some.other.package
A.3.5
Fragments
Fragments are extensions to bundles. They attach to a
host bundle and act in almost every way as if they were
part of the host (see figure A.5). They allow bundles to
be customized depending on their environment. For
example, translated resource files can be packaged up
by themselves into a fragment and only shipped if
needed. Fragments can also be used to add platform-
specific code to a generic host.
Some OSG i developers prefer to avoid bundle frag-
ments. Although they have some useful behaviors,
many of the normal rules for OSG i bundles don't apply
to fragments, which can cause things to go awry in sub-
tle ways. A colleague of ours describes fragments as bun-
dle flakes !
Bundle
classloader
Bundle
Attached
fragments
Figure A.5 A bundle fragment
attaches to its host and shares
a classloader.
A.4
Bundle lifecycles
Unlike normal JAR s, OSG i bundles have a lifecycle. They can be stopped and started
on demand, with their classloaders and classes appearing and disappearing from the
system in response. Figure A.6 shows the complete state machine for OSG i bundles.
A.4.1
Activation policies
A bundle has some control over when it moves between these states. After a bundle
gets started, it may move immediately from the STARTING state to the ACTIVE state
(eager activation), or it may wait until one of its classes is loaded (lazy activation). The
default policy is eager activation; lazy activation may be enabled by adding the follow-
ing to the manifest:
Bundle-ActivationPolicy: lazy
A.4.2
Bundle activators
Before moving into the ACTIVE state, a bundle will have a chance to perform some
initialization. If a bundle declares an activator, its activator will be notified whenever
Search WWH ::




Custom Search