JFocus 2009

2009-01-28

OSGi Class Loading

OSGi Class Loading

Bundle Classloader
• An OSGi framework must create one class loader per bundle that is resolved and that is not a fragment bundle • The creation of the class loader may be delayed until it is actually needed

Makewave AB Gunnar Ekolin

2

1

osgi.framework.* Makewave AB Gunnar Ekolin 3 OSGi Class Loading Parent Classloader • The framework must explicitly export packages other than java.com.framework.* to the Parent Classloader • The framework can be instructed to delegate additional classes with the org.*.sun.JFocus 2009 2009-01-28 OSGi Class Loading Parent Delegation • The OSGi framework must always delegate classes that start with java.bootdelegation system property • Examples: • org.framework.osgi.system.* from the System Bundle • The property org.bootdelegation=* • org.osgi.osgi.packages contains those exports in the same format as the ExportPackage manifest header • Framework implementations must take extra care to make sure that classes exported from the boot classpath are loaded from the boot classpath because some classes on the boot class path assumes that they can be loaded by any classloader because of the prevalent hierarchical model Makewave AB Gunnar Ekolin 4 2 .bootdelegation=sun.framework.

0.0.JFocus 2009 2009-01-28 OSGi Class Loading Wires • A bundle that has been resolved is said to have a wire to the class loader of the exporting bundle for each of its imported packages Makewave AB Gunnar Ekolin 5 OSGi Class Loading Fragments «bundle» FragmentHost Bundle-SymbolicName: example.0)” Makewave AB Gunnar Ekolin 6 3 .bundleversion="[1.2.host Bundle-Version: 1.host.0.0.0 +attaches «bundle» Fragment Fragment-Host: example.

n fragments attached. Makewave AB Gunnar Ekolin 7 OSGi Class Loading Extension (framework) «jar» Framework Bundle-SymbolicName: system. • is in the state Resolved when attached. • detached from the host when it becomes unresolved.bundle.bundle +attaches «bundle» Fragment Fragment-Host: system.. will require all bundles that attached fragments requires. will export all packages exported by attached fragments. will import all packages imported by attached fragments. • Fragments are • attached to the host when it becomes resolved. • Attached fragments are search in bundle id order (lowest first). • A fragment host bundle • • • • can have 0.. extension:=framework Makewave AB Gunnar Ekolin 8 4 .JFocus 2009 2009-01-28 OSGi Class Loading Fragments • A fragment • must no have a Bundle-Activator header. • can only attach to one host.

Bundle-Activator.e.bundle. • If an extension bundle is updated the new version must not resolve unless a refresh on it have been made (i. • Extension bundles must be appended to the class path of the class loader of the framework implementation in the order in which the extension bundles are installed: that is. • exports packages via the system bundle. extension:=bootclasspath Makewave AB Gunnar Ekolin 10 5 . Require-Bundle. • An extension bundle • must not specify Import-Package.framework +attaches «bundle» Fragment Fragment-Host: system. the entire framework must be re-launched). • Delivers optional parts of the framework implementation. Makewave AB Gunnar Ekolin 9 OSGi Class Loading Extension (bootclasspath) «jar» Framework Bundle-SymbolicName: example. BundleNativeCode.JFocus 2009 2009-01-28 OSGi Class Loading Extension (framework) • Extension bundles are fragments that attaches to the system bundle. ascending bundle ID order. DynamicImport-Package. • The entire framework must be re-launched if an extension bundle is refreshed..

• Used for JDBC drivers and other legacy code that must be on the boot class path to work properly. Makewave AB Gunnar Ekolin 11 OSGi Class Loading Classloader Search Order 1(2) Start no 1 java? yes Delegate to parent classloader Delegate to parent classloader Delegate to wire's exporter yes found? yes Success Failure 2 boot delegation? yes found? no yes 3 imported? yes found? no yes 4 Search Required bundles found? no Makewave AB Gunnar Ekolin 12 6 .JFocus 2009 2009-01-28 OSGi Class Loading Extension (bootclasspath) • Same rules as for extension bundles with a single exception: • The jar-files of boot class path extension must be added to the boot class path of the JVM executing the framework.

makewave.com Makewave AB Gunnar Ekolin 14 7 .JFocus 2009 2009-01-28 OSGi Class Loading Classloader Search Order 2(2) 5 Search bundle classpath found? no Search fragments bundle classpath yes 9 yes Delegate to wire's exporter found? no yes yes yes Success Failure 6 found? no 7 package exported? no dynamic import? no 8 Makewave AB Gunnar Ekolin 13 OSGi Class Loading Thank You! Gunnar Ekolin www.com ekolin@makewave.

Sign up to vote on this title
UsefulNot useful