summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/osgi-aware-programming-in-tuscany.html
blob: ba033043a3ac840d657bcae4b483c205bf8685dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!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="http://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico">   

        <TITLE>OSGi Aware Programming in Tuscany : Apache Tuscany</TITLE>

    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>

    

    <BODY onload="init()">

        

        
    <TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg">

        <TR>

            <TD valing="top" align="left">

			    <A href="http://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A>

			</TD>

			<TD>

                <A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A>

            </TD>

            

            <TD width="100%">

                &nbsp;

            </TD>

            <!--td align="right">

                <img src="http://incubator.apache.org/tuscany/images/apache- incubator- logo.png" border="0">

            </td-->



            <!-- Adds the edit page link to the top banner-->

            <TD valign="bottom">

                <DIV style="padding: 2px 10px; margin: 0px;">

                    <A href="http://cwiki.apache.org/confluence/pages/editpage.action?pageId=101617">

                    <IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>

                </DIV>

            </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%">

                &nbsp;<A href="home.html" title="Apache Tuscany">Apache Tuscany</A>&nbsp;&gt;&nbsp;<A href="home.html" title="Home">Home</A>&nbsp;&gt;&nbsp;<A href="sca-overview.html" title="SCA Overview">SCA Overview</A>&nbsp;&gt;&nbsp;<A href="sca-java.html" title="SCA Java">SCA Java</A>&nbsp;&gt;&nbsp;<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A>&nbsp;&gt;&nbsp;<A href="" title="OSGi Aware Programming in Tuscany">OSGi Aware Programming in Tuscany</A>

            </TD>

            

            <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">

            <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>&nbsp;&nbsp;

            </TD>

        </TR>

    </TABLE>




        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">

            <TR>

                <TD align="left" valign="top">

                    
    <DIV id="PageContent">

        
        

        <DIV class="pagecontent">

            <DIV class="wiki-content">

                <H2><A name="OSGiAwareProgramminginTuscany-MotivationforOSGi"></A>Motivation for OSGi</H2>

<P>   The Apache Tuscany project has become a large project, with various extensions and component types that brings to the SCA Runtime different levels of dependencies. With its growth, Tuscany also started to have it's SPIs violated by some of these extensions, and some of the boundaries between sub-systems are broken, as there wasn't any enforcement of these boundaries.</P>

<P>   The OSGi model provides a very powerful and flexible framework to develop applications in a modular fashion with a high degree of control over classloading inter-dependencies over modules. An OSGi module (a.k.a bundle) have a manifest file (META-INF\manifest.mf) that contains module information such as &quot;name&quot;, &quot;version&quot; and also a list of what packages are being exported, and what packages are being imported from the given bundle, providing ways to easily enforce module boundaries.</P>

<P>   In summary:</P>
<UL>
	<LI>Better class loading mechanism for our modules</LI>
	<LI>Create clean boundaries between sub-systems</LI>
</UL>


<H2><A name="OSGiAwareProgramminginTuscany-TuscanyandOSGi3rdpartydependencies"></A>Tuscany and OSGi - 3rd party dependencies</H2>

<P>   Currently we are wrapping the 3rd party dependencies as OSGi bundles, but leaving it unpacked (a.k.a folder structure). This allow use to use the same dependency jars in a OSGi environment as well as in a non-OSGI environment and generating no side effect on our distribution footprint.</P>

<P>   <IMG src="osgi-aware-programming-in-tuscany.data/osgi_3rd_party_dependencies.JPG" align="absmiddle" border="0"></P>


<H2><A name="OSGiAwareProgramminginTuscany-TuscanyandOSGiGranularity"></A>Tuscany and OSGi - Granularity</H2>

<P>   The granularity used to define modules should be very familiar to all tuscany developers, </P>

<P>   Tuscany Modules      --&gt; OSGi Bundles<BR>
   3rd Party Libraries  --&gt; OSGi Bundles (using unpacked wrap style bundle)</P>

<H2><A name="OSGiAwareProgramminginTuscany-ProperlydefiningnewTuscanymodulesasanOSGibundle"></A>Properly defining new Tuscany modules as an OSGi bundle</H2>

<P> When adding new modules to the Tuscany project, the developer will need to create the OSGi Manifest to properly describe the new module as an OSGi bundle. These artifacts can be automatically generated using the Felix maven-bundle-plugin and should be available from svn repository once it's stable.</P>

<H4><A name="OSGiAwareProgramminginTuscany-GeneratingOSGimanifestwithFelixmavenbundleplugin"></A>Generating OSGi manifest with Felix maven-bundle-plugin</H4>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>&quot;configuring maven to generate the OSGi manifest&quot;</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
&lt;plugin&gt;
    &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
    &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;instructions&gt;
            &lt;!-- Bundle versioned from Tuscany version --&gt;
            &lt;Bundle-Version&gt;${tuscany.version}&lt;/Bundle-Version&gt;
            &lt;!-- Bundle Symbolic name --&gt;
            &lt;Bundle-SymbolicName&gt;org.apache.tuscany.sca.api&lt;/Bundle-SymbolicName&gt;
            &lt;!-- Bundle description from pom description --&gt;
            &lt;Bundle-Description&gt;${pom.description}&lt;/Bundle-Description&gt;
            &lt;!-- Export org.osoa.sca and all sub-packages --&gt;
            &lt;Export-Package&gt;org.osoa.sca*&lt;/Export-Package&gt;
            &lt;!-- No Import-Package so calculate imports from code dependencies --&gt;
        &lt;/instructions&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</PRE>
</DIV></DIV>

<P>Below is a manifest that was generated for one of the Tuscany modules using the felix maven-bundle-plugin.</P>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>&quot;OSGi Manifest (META-INF\manifest.mf)&quot;</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
Manifest-Version: 1.0
Export-Package: org.apache.tuscany.sca.assembly;uses:=&quot;javax.xml.xpath
 ,org.apache.tuscany.sca.assembly.impl,org.apache.tuscany.sca.policy,o
 rg.apache.tuscany.sca.interfacedef,javax.xml.namespace<SPAN class="code-quote">&quot;;version=&quot;</SPAN>1.4&quot;
 ,org.apache.tuscany.sca.assembly.impl;uses:=&quot;javax.xml.xpath,org.apac
 he.tuscany.sca.assembly,org.apache.tuscany.sca.policy,org.apache.tusc
 any.sca.interfacedef,javax.xml.namespace<SPAN class="code-quote">&quot;;version=&quot;</SPAN>1.4&quot;,org.apache.tu
 scany.sca.assembly.builder;uses:=&quot;org.apache.tuscany.sca.assembly,org
 .apache.tuscany.sca.definitions,org.apache.tuscany.sca.core,org.apach
 e.tuscany.sca.monitor,org.apache.tuscany.sca.interfacedef,org.apache.
 tuscany.sca.extensibility<SPAN class="code-quote">&quot;;version=&quot;</SPAN>1.4&quot;
Private-Package: org.apache.tuscany.sca.assembly.builder.impl;version=
 <SPAN class="code-quote">&quot;1.4&quot;</SPAN>
Tool: Bnd-0.0.255
Bundle-Name: Apache Tuscany SCA Assembly Model
Created-By: 1.6.0_07 (Sun Microsystems Inc.)
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 1.4
Bnd-LastModified: 1225397097203
Bundle-ManifestVersion: 2
Bundle-License: http:<SPAN class="code-comment">//www.apache.org/licenses/LICENSE-2.0.txt
</SPAN>Bundle-Description: Apache Tuscany SCA Assembly Model
Import-Package: javax.xml.namespace,javax.xml.parsers,javax.xml.transf
 orm,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.xpath,o
 rg.apache.tuscany.sca.assembly;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.a
 ssembly.builder;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.assembly.impl;ve
 rsion=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.core;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tusc
 any.sca.definitions;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.extensibilit
 y;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.interfacedef;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org
 .apache.tuscany.sca.monitor;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.poli
 cy;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org.apache.tuscany.sca.policy.util;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>,org
 .w3c.dom,org.xml.sax,junit.framework;resolution:=optional,org.apache.
 tuscany.sca.interfacedef.impl;version=<SPAN class="code-quote">&quot;1.4&quot;</SPAN>;resolution:=optional,org.
 junit;resolution:=optional
Bundle-SymbolicName: org.apache.tuscany.sca.assembly
Bundle-DocURL: http:<SPAN class="code-comment">//www.apache.org/</SPAN>
</PRE>
</DIV></DIV>

<H2><A name="OSGiAwareProgramminginTuscany-TweakingtheOSGimanifest"></A>Tweaking the OSGi manifest</H2>

<P>   Eclipse PDE provides good tooling for editing and maintaining OSGi manifest files. There are various scenarios we might need to tweak the OSGi manifest manualy :</P>

<UL>
	<LI>Updating imported/exported packages</LI>
	<LI>Marking test dependencies optional
	<UL>
		<LI>Avoid issues when tests have references to external packages</LI>
	</UL>
	</LI>
</UL>


<P>   <IMG src="osgi-aware-programming-in-tuscany.data/osgi_manifest_editor.jpg" align="absmiddle" border="0"></P>

<H2><A name="OSGiAwareProgramminginTuscany-PDEintegrationoftuscanymodules"></A>PDE integration of tuscany modules</H2>
<P>1) We generate the .classpath from maven dependencies.</P>

<P>2) For maven compile/provided dependencies, the modules explicit references <BR>
these dependencies via packages. We define corresponding Import-Package <BR>
header in the MANIFEST.MF for OSGi, and these get resolved to other bundles <BR>
that export the matching packages. This magic comes from the <BR>
&quot;org.eclipse.pde.core.requiredPlugins&quot; classpath container which is <BR>
contributed by the Eclipse PDE. The classpath container resolves the OSGi <BR>
dependencies such as Import-Package or Required-Bundle and automatically add <BR>
the required bundles to the classpath as we see in Eclipse project under the <BR>
&quot;Plugin Dependencies&quot;.</P>

<P>3) The exported packages come from three types of sources:</P>
<UL>
	<LI>System packages (exported by the System Bundle, i.e., org.eclipse.osgi).<BR>
Different JDK levels have different list of system packages, for example, <BR>
javax.xml.stream is not in J2SE-1.5 but in JSEJava-1.6. You can find the <BR>
complete list by looking the .profile files within osgi-&lt;version&gt;.jar.</LI>
	<LI>Tuscany modules in the Eclipse workspace. The classpath entry will be<BR>
listed as a project under &quot;Plugin Dependencies&quot;</LI>
	<LI>3rd-party jars (already as OSGi bundles contributed by the target<BR>
platform). The classpath entry will be listed as a jar under &quot;Plugin <BR>
Dependencies&quot;</LI>
</UL>


<P>4) For maven runtime dependencies, there is no corresponding Import-Package <BR>
and the dependencies are used in runtime. Ideally in OSGi, they could be a <BR>
Required-Bundle or a bundle available at runtime. To run the project in JSE <BR>
inside Eclipse, we generate an explicit classpath entry.</P>

<P>5) For maven test dependencies, there are two types: one is for test <BR>
compilation and the other for test runtime. For the first type, we use <BR>
optional Import-Package to pull in the dependencies if the same project has <BR>
the compile dependency for the same artifact. Otherwise, we generate an <BR>
explicit classpath entry for JSE testing.</P>

<P>6) For test cases which require extra dependencies in addition to the <BR>
compile/provided/runtime dependencies for the main code, they probably <BR>
should not be unit tests. We need to consider how to move them into the <BR>
itest bucket.</P>





            </DIV>

        </DIV>

    </DIV>


                </TD>

            </TR>

        </TABLE>



        
    
    <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">

    </SCRIPT>

    <SCRIPT type="text/javascript">

       _uacct = "UA-1174707-5";

       urchinTracker();

    </SCRIPT>

    

    
    <A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A>    



    <DIV class="footer">

        Copyright &copy; 2003-2008, The Apache Software Foundation&nbsp;&nbsp;

    </DIV>




    </BODY>

</HTML>