diff options
Diffstat (limited to '')
-rw-r--r-- | site/trunk/site-publish/documentation-2x/classloading.html | 351 |
1 files changed, 351 insertions, 0 deletions
diff --git a/site/trunk/site-publish/documentation-2x/classloading.html b/site/trunk/site-publish/documentation-2x/classloading.html new file mode 100644 index 0000000000..aa51c96265 --- /dev/null +++ b/site/trunk/site-publish/documentation-2x/classloading.html @@ -0,0 +1,351 @@ + + + + + + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<HTML> + <HEAD> + <META name="description" content="Apache Tuscany"> + <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource"> + + <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css"> + <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/$images/favicon.ico"> + <TITLE>Classloading : Apache Tuscany</TITLE> + <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD> + + <STYLE> + .spacetree * ul { + padding-left:0px; + margin-left: 0px; + } + .spacetree * li { + margin-left: 5px; + padding-left:5px; + } + </STYLE> + + <BODY onload="init()"> + <!-- topNav --> + <TABLE border="0" cellpadding="2" cellspacing="0" width="100%"> + <TR class="topBar"> + <TD align="left" valign="middle" class="topBarDiv" align="left" nowrap=""> + <A href="https://cwiki.apache.org/geronimo"> Home</A> > <A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="development-guides.html" title="Development Guides">Development Guides</A> > <A href="sca-java-runtime-overview.html" title="SCA Java Runtime Overview">SCA Java Runtime Overview</A> > <A href="" title="Classloading">Classloading</A> + </TD> + <TD align="right" valign="middle" nowrap=""> + <FORM name="search" action="http://www.google.com/search" method="get"> + <INPUT type="hidden" name="ie" value="UTF-8"> + <INPUT type="hidden" name="oe" value="UTF-8"> + <INPUT type="hidden" name="domains" value=""> + <INPUT type="hidden" name="sitesearch" value=""> + <INPUT type="text" name="q" maxlength="255" value=""> + <INPUT type="submit" name="btnG" value="Google Search"> + </FORM> + </TD> + </TR> + </TABLE> + + + <TABLE border="0" cellpadding="2" cellspacing="0" width="100%"> + <TR class="topBar"> + <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%"> + <A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A> > <A href="index.html" title="Index">Index</A> > <A href="development-guides.html" title="Development Guides">Development Guides</A> > <A href="sca-java-runtime-overview.html" title="SCA Java Runtime Overview">SCA Java Runtime Overview</A> > <A href="" title="Classloading">Classloading</A> + </TD> + + <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true"> + <A href="http://tuscany.apache.org/">Tuscany Home</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A> + </TD> + </TR> + </TABLE> + + <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF"> + <TR> + <TD valign="top" align="left" width="22%" bgcolor="#F9F9F9" class="noprint"> + <DIV class="tabletitle">Table of Contents</DIV> + <DIV class="spacetree"> + + + </DIV> + </TD> + <TD align="left" valign="top" width="78%"> + <!-- pageContent --> + <DIV id="PageContent"> + <DIV class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="http://geronimo.apache.org/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany Docs 2.x</DIV> + <DIV style="margin: 0px 10px 8px 10px" class="pagetitle">Classloading</DIV> + + <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> +<!-- --> + <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644728"> + <IMG src="http://geronimo.apache.org/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A> + <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=20644728">Edit Page</A> + + <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x"> + <IMG src="http://geronimo.apache.org/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A> + <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">Browse Space</A> + + <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644728"> + <IMG src="http://geronimo.apache.org/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A> + <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644728">Add Page</A> + + <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644728"> + <IMG src="http://geronimo.apache.org/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A> + <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=20644728">Add News</A> +<!-- --> + </DIV> + </DIV> + + <DIV class="pagecontent"> + <DIV class="wiki-content"> + <P>Need to detail the various ways the Tuscany runtime loads classes and the issues involved. Here are some notes to kick of this document</P> + +<H1><A name="Classloading-ClassloadingObjectives"></A>Classloading Objectives</H1> + +<P>The runtime must work in both OSGi and non-OSGI environments. I.e. we can't rely on the OSGi service registry for extensibility<BR> +The runtime must not be generally environment specific. I.e. no buddy classloading<BR> +...</P> + +<H1><A name="Classloading-GeneralPatterns"></A>General Patterns</H1> + +<H2><A name="Classloading-ExtensionloadingJSE"></A>Extension loading - JSE</H2> + +<P>tuscany-extensibility<BR> +Tuscany finds extensions by looking for META-INF/services files on the classpath.</P> + +<H2><A name="Classloading-ExtensionloadingOSGi"></A>Extension loading - OSGi</H2> + +<P>tuscany-extensibility-equinox<BR> +It's a bit more complicated here. The extensibility-equinox bundle is given the entire OSGi context at start up and from there is looks in all of the loaded bundles looking for META-INF/services files. It caches them against the bundle in which they are found.</P> + +<P>The tuscany-extensibility-equinox bundle also has a dynamic import</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +DynamicImport-Package: org.apache.tuscany.sca.extensibility.equinox, + javax.transaction;version=<SPAN class="code-quote">"1.1"</SPAN>, + javax.transaction.xa;version=<SPAN class="code-quote">"1.1"</SPAN>, +</PRE> +</DIV></DIV> + +<P>Which allows it to generally load any classes in the runtime</P> + +<H2><A name="Classloading-SplitPackagesJSE"></A>Split Packages - JSE</H2> + +<P>We don't take any special account of this in JSE <IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/help_16.gif" height="16" width="16" align="absmiddle" alt="" border="0"><BR> +We avoid split packages across the JARs we create as it messes OSGi up.</P> + +<H2><A name="Classloading-SplitPackagesOSGI"></A>Split Packages - OSGI</H2> + +<P>We avoid split packages across the bundles we create<BR> +They may exist in third party bundles (or jars that we turn into bundles) so we need a way round it</P> + +<P>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 <IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/help_16.gif" height="16" width="16" align="absmiddle" alt="" border="0"> and the resulting bundle it in the distribution modules directory in the following form</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +bundle-name + META-INF + MANIFEST.MF + bundle-name.jar +</PRE> +</DIV></DIV> + +<P>The MANIFEST.MF is generated and will have a bundle classpath pointing to the jar (which doesn't itself have a manifest</P> + +<P>The runtime (node-launcher-equinox) has code to load these directories as bundles.</P> + +<P>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</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +distribution/all/manifests +</PRE> +</DIV></DIV> + +<P>Update distribution/pom.xml to configure the Tuscany version of the maven bundle plugin to apply this manifest</P> + +<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent"> +<PRE> <plugin> + <groupId>org.apache.tuscany.maven.plugins</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>1.0.6</version> + <executions> + <execution> + <id>distribution-modules</id> + <phase>generate-resources</phase> + <goals> + <goal>generate-modules</goal> + </goals> + <configuration> + <targetDirectory>target/modules</targetDirectory> + <useDistributionName>${useDistributionName}</useDistributionName> + <generateAggregatedBundle>${generateAggregatedBundle}</generateAggregatedBundle> + <generateManifestJar>true</generateManifestJar> + <artifactManifests> + <artifactManifest> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <version>1.2.8</version> + <manifestFile>${basedir}/manifests/axiom-api-1.2.8.MF</manifestFile> + </artifactManifest> + <artifactManifest> + <groupId>org.apache.woden</groupId> + <artifactId>woden-impl-dom</artifactId> + <version>1.0M8</version> + <manifestFile>${basedir}/manifests/woden-impl-dom-1.0M8.MF</manifestFile> + </artifactManifest> + <!--artifactManifest> + <groupId>org.apache.tuscany.sdo</groupId> + <artifactId>tuscany-sdo-api-r2.1</artifactId> + <version>1.1.1</version> + <manifestFile>${basedir}/manifests/tuscany-sdo-api-r2.1-1.1.1.MF</manifestFile> + </artifactManifest--> + <!-- artifactAggregations (below) is the right approach to solving the split + package between axis-kernel and axis2-transport-http however the Tuscany + runtime doesn't take any notice of it so using a fragment at the moment --> + <artifactManifest> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-kernel</artifactId> + <version>1.5.1</version> + <manifestFile>${basedir}/manifests/axis2-kernel-1.5.1.MF</manifestFile> + </artifactManifest> + <artifactManifest> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-transport-http</artifactId> + <version>1.5.1</version> + <manifestFile>${basedir}/manifests/axis2-transport-http-1.5.1.MF</manifestFile> + </artifactManifest> + <artifactManifest> + <groupId>org.apache.axis2</groupId> + <artifactId>*</artifactId> + <version>*</version> + </artifactManifest> + </artifactManifests> + <!--artifactAggregations> + <artifactAggregation> + <symbolicName>org.apache.tuscany.sca.axis2-kernel</symbolicName> + <version>1.5.1</version> + <artifactMembers> + <artifactMember> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-kernel</artifactId> + <version>1.5.1</version> + </artifactMember> + <artifactMember> + <groupId>org.apache.axis2</groupId> + <artifactId>axis2-transport-http</artifactId> + <version>1.5.1</version> + </artifactMember> + </artifactMembers> + </artifactAggregation> + </artifactAggregations--> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.eclipse</groupId> + <artifactId>osgi</artifactId> + <version>3.3.0-v20070530</version> + </dependency> + </dependencies> + </plugin> +</PRE> +</DIV></DIV> + +<P>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.</P> + +<P>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!)</P> + +<H2><A name="Classloading-ThirdpartylibrariesJSE"></A>Third-party libraries - JSE</H2> + +<P>TBD</P> + +<H2><A name="Classloading-ThirdpartylibrariesOSGI"></A>Third-party libraries - OSGI</H2> + +<P>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.</P> + +<P>See ClassLoaderContext which help us to set up a multi-classloader configurations.</P> + +<P>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.</P> + + +<H2><A name="Classloading-TuscanyNodeAPIJSE"></A>Tuscany Node API - JSE</H2> + +<P>TBD</P> + +<H2><A name="Classloading-TuscanyNodeAPIOSGi"></A>Tuscany Node API - OSGi</H2> + +<P>There are a small number of Tuscany Jars you need to use in the app launcher in the OSGi environment</P> + +<P>tuscany-sca-api<BR> +tuscany-node-api<BR> +tuscany-node-launcher-equinox</P> + +<P>The node API has to load the node implementation and has a dynamic import in its manifest</P> + +<P>DynamicImport-Package: org.apache.tuscany.sca.node.impl,org.apache.tuscany.sca.extensibility</P> + + + +<H2><A name="Classloading-SCAClientAPIJSE"></A>SCA Client API - JSE</H2> + +<P>Factory finder impl is injected into the API class by the implementation</P> + +<H2><A name="Classloading-SCAClientAPIOSGi"></A>SCA Client API - OSGi</H2> + +<P>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.</P> + +<H2><A name="Classloading-%23ContributionClassLoading"></A><A href="#Classloading-Contribution">Contribution</A> Class Loading </H2> + +<P>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 [2]</P> + +<P>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.</P> + +<P>The itest project <EM>import-export-tests</EM> 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 [1] code which traverses all contributions, identifying cross contribution dependencies (see buildDependencies at [1]) and using the set of remaining contributions to resolve the import, potentially more than once.</P> + +<P>[<A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&title=1&linkCreation=true&fromPageId=20644728" class="createlink">1</A>] <A href="http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java?view=markup&pathrev=948564" class="external-link" rel="nofollow">http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java?view=markup&pathrev=948564</A>|http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/deployment/src/main/java/org/apache/tuscany/sca/deployment/impl/DeployerImpl.java?view=markup&pathrev=948564]</P> + +<P>[2] <A href="http://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver</A></P> + + </DIV> + + </DIV> + </DIV> + </TD> + </TR> + </TABLE> + + <!-- footer --> + <TABLE border="0" cellpadding="2" cellspacing="0" width="100%"> + <TR> + <TD align="left" valign="middle" class="footer"> + + <IMG src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious"> + <A href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'delicious','toolbar=no,width=550,height=550'); return false;">Bookmark this on Delicious</A> + + <IMG src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!"> + <A href="" onclick="window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&topic=programming');">Digg this</A> + <!-- Slicker, but no text + <script type="text/javascript"> + digg_skin = 'icon'; + digg_window = 'new'; + digg_title = 'Apache Geronimo v2.2 Documentation : Classloading'; + digg_topic = 'programming'; + </script> + <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script> + --> + + </TD> + <TD align="right" valign="middle" class="footer"> + <A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A> - + Copyright © 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A> + </TD> + </TR> + </TABLE> + + </BODY> +</HTML>
\ No newline at end of file |