|Home > Apache Tuscany Docs 2.x > Index > Development Guides > SCA Java Runtime Overview > Classloading|
|Apache Tuscany Docs 2.x > Index > Development Guides > SCA Java Runtime Overview > Classloading||Tuscany Home | User List | Dev List | Issue Tracker|
Apache Tuscany Docs 2.x
Need to detail the various ways the Tuscany runtime loads classes and the issues involved. Here are some notes to kick of this document
The runtime must work in both OSGi and non-OSGI environments. I.e. we can't rely on the OSGi service registry for extensibility
The tuscany-extensibility-equinox bundle also has a dynamic import
Which allows it to generally load any classes in the runtime
We don't take any special account of this in JSE
We avoid split packages across the bundles we create
The Tuscany eclipse plugin is used to generate bundles manifest for jars which don't have them. This is done automatically with all packages exported and the resulting bundle it in the distribution modules directory in the following form
The MANIFEST.MF is generated and will have a bundle classpath pointing to the jar (which doesn't itself have a manifest
The runtime (node-launcher-equinox) has code to load these directories as bundles.
There is a way of overriding these automatically generated bundles so that split packages (or any other manifest problems) can be worked round. Generate the manifest manually and put it in
Update distribution/pom.xml to configure the Tuscany version of the maven bundle plugin to apply this manifest
You'll note that there is an artifact aggregation element that doesn't work at the moment. This should aggregate the two bundles together so that a split package isn't an issue. As this doesn't work at the moment another way to achieve the same result is to make one package a fragement of the other by configuring separate manifests manually.
NOTE!!!!! you also need to put the manually generated manifest in node-launcher-equinox\src\main\resources\org\apache\tuscany\sca\node\equinox\launcher otherwise you'll spend a lot of time trying to get this to work. (we need to fix this!)
Third-party libraries often rely on TCCL to load implementation classes in an extensible way. For example, the SDO API loads the HelperContext implementation in this way. In an OSGi environment there will not be a static dependency between the api bundle and the impl bundle so we need to fake it. Typically we do this by setting up the TCCL appropriately before the library us called.
See ClassLoaderContext which help us to set up a multi-classloader configurations.
Typically in OSGi one of the classloaders we pass in here will be the extensibiliy-equinox bundle classloader (the ServiceDiscoverer) as this bundles has a dynamic import which allows it to load any class in the runtime.
There are a small number of Tuscany Jars you need to use in the app launcher in the OSGi environment
The node API has to load the node implementation and has a dynamic import in its manifest
Factory finder impl is injected into the API class by the implementation
NodeFactory maintains a NodeProxy inner class that supports cross-classloader calls. The calling client api will have been loaded by the app classloader but the underlying node will have been loaded by a bundle classloader. We need to bridge that gap.
Contribution Class Loading
When a contribution is read, containing an implementation.java element, a ClassReference is instantiated, which contains the name of the class. ClassReference instances are resolved by a ClassLoaderModelResolver, by virtue of the entry in 
The ClassLoaderModelResolver (CLMR) specializes java.net.URL.URLClassLoader and implements o.a.t.s....ModelResolver. Each contribution is associated with a single CLMR . On construction the CLMR is endowed with a set of URLs that allow it to find all classes in its contribution via the URLClassLoader behaviour.
The itest project import-export-tests has a class TestTestCase with method testOneNode which demonstrates a more complex scenario where a cross contribution import/export of a java package exists between the contributions. In this example a node is created using 2 composite URIs for contributions ... "../exports/target/classes", "../imports/target/classes". An imported class is resolved using the CLMR of the exporting contribution. The exporter's CLMR is made available to the importing CLMR by deployment  code which traverses all contributions, identifying cross contribution dependencies (see buildDependencies at ) and using the set of remaining contributions to resolve the import, potentially more than once.