2
votes

Suppose I have the following bundles in my OSGi container:

Bundle-Name: Bundle A
Import-Package: org.foo;version="[1.0.0,2)"

Bundle-Name: Bundle B1
Export-Package: org.foo;version="1.0.0"

then a little while later, I add B2

Bundle-Name: Bundle B2
Export-Package: org.foo;version="1.1.0"

At what point does A start using the classes in B2's 1.1.0? Is that an inherent part of adding a bundle that exports a new incremented version or must something be done manually to tell OSGi to look for "upgrades"?

1

1 Answers

3
votes

You must call refresh on bundle A to re-wire the packages after B2 is resolved. E.g.:

Bundle systemBundle = bundleContext.getBundle(0);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
frameworkWiring.refreshBundles(Arrays.asList(bundleA.getBundleId()));

Until bundle A is not refreshed, it will be wired to bundle B1. Even if you uninstall bundle B1, bundle A will keep being wired to it. Bundle B1 will get the _pending_removal_ state until anything wires to it (until all bundles are refreshed that wires to it).

For more information, see the javadoc of FrameworkWiring functions.