Code Segregation
Code segregation is a mechanism that determines how dependencies between bundles can be satisfied. When code segregation is enforced, dependencies can only be satisfied when the bundles are contained in features and the features containing the bundles have the same dependencies.
When code segregation is not enforced, a bundle dependency can be satisfied by any matching bundle installed on the same node even if there is no dependency relationship between the features containing the bundles.
For example, consider a feature A containing a bundle BA, which is dependent on bundle BB. When code segregation is enforced:
- Bundle BB must be contained in a feature B
- Feature A must depend on feature B
- Features A and B must be installed on the same node
Code segregation eliminates the unpredictable results that can occur when a bundle inadvertently uses a third-party bundle. In particular, code segregation enables version coexistence because it prevents a bundle from using a bundle with a different version than it requires. Version Coexistence illustrates how code segregation allows two versions of the Spring framework bundle to coexist on a node without interfering with each other. If your bundle requires a version of the Spring bundle that is newer than the one used by the TIBCO ActiveMatrix platform, code segregation enforces the dependency on that version and prevents your bundle from using the Spring bundle in the TIBCO ActiveMatrix platform. Similarly, code segregation prevents a TIBCO ActiveMatrix bundle from using the newer version of the Spring bundle.
Advanced Uses
Even if you enable code segregation, the use of DynamicImport-Package headers in the bundle manifest is supported. That is, bundles declaring DynamicImport-Package headers can load classes outside of their dependency tree, which is required for packages such as Hibernate and Log4J.
The implementation of code segregation is based on the ResolverHook specification described in chapter 53 of OSGi core specification R4.3 and also supports the Bundle Hook Service described in chapter 54, which includes the following features:
- FindHook - A bundle can call BundleContext.getBundles() to return a list of all bundles installed in the TIBCO ActiveMatrix runtime. The FindHook service allows a bundle to limit the returned bundles to only those bundles contained in a feature in the feature dependency tree.
- EventHook - A bundle can create a BundleTracker or register a BundleListener to be notified about a BundleEvent. Code segregation ensures that bundles are only notified about a BundleEvent for bundles that are in their feature dependency tree.