summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/documentation-2x/osgi-enablement-for-tuscany-runtime.html
blob: 38a82c3242e21dd139cbbc4c6a56ac2a1792a2cb (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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!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>OSGi Enablement for Tuscany Runtime : 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> &gt;&nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="development-guides.html" title="Development Guides">Development Guides</A>&nbsp;&gt;&nbsp;<A href="" title="OSGi Enablement for Tuscany Runtime">OSGi Enablement for Tuscany Runtime</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%">
                &nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="development-guides.html" title="Development Guides">Development Guides</A>&nbsp;&gt;&nbsp;<A href="" title="OSGi Enablement for Tuscany Runtime">OSGi Enablement for Tuscany Runtime</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>&nbsp;&nbsp;
            </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">OSGi Enablement for Tuscany Runtime</DIV>

        <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
<!-- -->         
            <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=109741">
            <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=109741">Edit Page</A>
          &nbsp;
          <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>
          &nbsp;
          <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109741">
            <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=109741">Add Page</A>
          &nbsp;
          <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109741">
            <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=109741">Add News</A>
<!-- -->	 
        </DIV>
      </DIV>

      <DIV class="pagecontent">
        <DIV class="wiki-content">
          <H1><A name="OSGiEnablementforTuscanyRuntime-OSGiEnablementforTuscanyRuntime"></A>OSGi Enablement for Tuscany Runtime</H1>

<P><A href="osgi-enablement-for-tuscany-runtime.data/OSGi%20Enablement%20for%20Tuscany.ppt">OSGi Enablement for Tuscany.ppt</A></P>

<H2><A name="OSGiEnablementforTuscanyRuntime-MovtivationstoenableOSGiforTuscany%3A"></A>Movtivations to enable OSGi for Tuscany:</H2>

<UL>
	<LI>Provide modularity for Tuscany to formalize the SPI contracts and enforce the package dependencies across modules</LI>
	<LI>Enable Tuscany to work with OSGi environment such as JEE application servers, Eclipse RCP or Spring DM (see <A href="http://www.infoq.com/news/2008/11/osgi-in-the-enterprise" class="external-link" rel="nofollow">http://www.infoq.com/news/2008/11/osgi-in-the-enterprise</A> )</LI>
	<LI>Provide versioning and isolation so that Tuscany extensions can depend on different versions of the same library</LI>
	<LI>Provide dynamic lifecycle for extensions, install/uninstall/start/stop a module</LI>
</UL>


<H2><A name="OSGiEnablementforTuscanyRuntime-Objectives"></A>Objectives</H2>

<UL>
	<LI>Tuscany runtime will be able to run in both non-OSGi and OSGi environment</LI>
	<LI>A consistent OSGi story across development, build, runtime and testing</LI>
</UL>


<H2><A name="OSGiEnablementforTuscanyRuntime-StepstomakeTuscanyworkwithOSGi%28Basicenablement%29"></A>Steps to make Tuscany work with OSGi (Basic enablement)</H2>

<UL>
	<LI>Add OSGi MANIFEST.MF for each module to make it an OSGi bundle
	<UL>
		<LI>The generated MANIFEST.MF from maven-bundle-plugin is a good starting point. The result may not be accurate and it doesn't help to reduce the coupling</LI>
		<LI>It should be developers' reponsibility to maintain it for the optimal dependencies</LI>
	</UL>
	</LI>
	<LI>Convert each non-OSGi 3rd-party jar into an OSGi bundle
	<UL>
		<LI>Exception: Aggregate a group of 3rd-party jars if they have split packages</LI>
	</UL>
	</LI>
	<LI>Add an OSGi-based service discoverer to discover tuscany extension points and extensions from the installed bundles
	<UL>
		<LI>Use the same JDK service provider pattern (META-INF/services) as JSE</LI>
		<LI>The discoverer is configured based on the running environment (JSE or OSGi)</LI>
	</UL>
	</LI>
	<LI>Change how JDK factories such as XMLInputFactory, XPathFactory, and DocumentBuilderFactory, are discovered and instantiated
	<UL>
		<LI>XMLInputFactory.newInstance() used the JSE service provider pattern which doesn't work with OSGi</LI>
		<LI>We need to use Tuscany's service discovery mechanism to discover and instantiate the factories</LI>
	</UL>
	</LI>
	<LI>Adjust the code that assumes there is a flat thread context classloader that can access all the classes in the Tuscany runtime
	<UL>
		<LI>With OSGi, there is a network of classloaders (one classloader per module) and the class visibility is constrained by the OSGi headers such as Import-Package and Export-Package</LI>
		<LI>The classloader for the current class is a good starting point for Class.forName() with OSGi</LI>
	</UL>
	</LI>
	<LI>Provide a SCA node launcher to start an OSGi runtime and run SCA application with the OSGi-enabled Tuscany runtime</LI>
	<LI>Produce distributions that are compatible with the OSGi bundle structure in an efficient way (in one-two minutes)</LI>
	<LI>Bring samples and itests to use the Tuscany SCA OSGi node launcher or run with the Eclipse Equinox profile</LI>
</UL>


<DIV class="panelMacro"><TABLE class="noteMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>To learn from the excerises we went through, please see the slides: <A href="osgi-enablement-for-tuscany-runtime.data/tuscany-osgi.pdf">tuscany-osgi.pdf</A></TD></TR></TABLE></DIV>

<H2><A name="OSGiEnablementforTuscanyRuntime-UseOSGitohelpTuscanymaintainandenforcegoodmodularitywithcleanSPIsfollowingtheOSGibestpractices"></A>Use OSGi to help Tuscany maintain and enforce good modularity with clean SPIs following the OSGi best practices</H2>

<UL>
	<LI>Identify the absolutely necessary SPI packages that need to be exported
	<UL>
		<LI>Don't try to export everything</LI>
		<LI>For model modules, try to only export the package that contains the interfaces</LI>
		<LI>Try not to export any package from the xxx-runtime moudles</LI>
		<LI>Any classes that can be accessed via the ExtensionPointRegistry using interfaces should not be exported</LI>
	</UL>
	</LI>
	<LI>Only import other packages when it's needed
	<UL>
		<LI>For example, we used to have a lot of modules pull in assembly for just a constant for the SCA namespace</LI>
		<LI>Avoid DynamicImport-Package=&#42;</LI>
	</UL>
	</LI>
	<LI>Do not export &quot;private&quot; packages as a workaround or hack which can fail the &quot;clean SPI&quot;. Refactor things into SPIs if necessary
	<UL>
		<LI>For example, tuscany-core has quite a few packages that are exported. We need to define a SPI layer if these exports are required.</LI>
		<LI>implementation-java: extract out the annotation processing so that they can be reused for introspecting other java-based implementation technologies such as Spring or EJB</LI>
		<LI>implementation-java-runtime: extract out the IoC</LI>
		<LI>add common modules such as common-java and common-xml to host java or XML related utilities</LI>
	</UL>
	</LI>
	<LI>Split modules into model/runtime to promote modularity</LI>
	<LI>Fix some of the unit testcases that pull in too many dependencies and they should be itests</LI>
</UL>


<P>To help developers to develop Tuscany modules as OSGi bundles and receive errors if OSGI constraints are violated, we integrated with a set of tools (help for improvement is welcome):</P>
<UL>
	<LI>A maven plugin to generate .classpath and .project files and target definition file to produce Eclipse PDE plugin projects for Tuscany modules so that we can leverage the nice OSGi development tooling
	<UL>
		<LI>Compile dependencies are now pulled in by the PDE requiredPlugins classpath container</LI>
		<LI>Runtime dependencies are now generated as an explict classpath entry</LI>
		<LI>Test dependencies can be optional Import-Package or an explicit classpath entry</LI>
	</UL>
	</LI>
	<LI>A maven compiler to use Eclipse JDT and OSGi bundle resolver
	<UL>
		<LI>The JDT compiler is much faster that javac</LI>
		<LI>The OSGi resolution reports unsatisfied OSGi constraints</LI>
	</UL>
	</LI>
	<LI>A maven plugin to generate OSGi-compatible distribution structure which hosts 3rd-party jars that can be used a bundle for OSGi as well as a plain jar for JSE classpath
	<UL>
		<LI>Copy OSGi bundles as jars</LI>
		<LI>Create a folder structure to hold the MANIFEST.MF which keep the 3rd-party jar as-is</LI>
	</UL>
	</LI>
</UL>


<DIV class="panelMacro"><TABLE class="noteMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>For more details, please see: <A href="osgi-aware-programming-in-tuscany.html" title="OSGi Aware Programming in Tuscany">OSGi Aware Programming in Tuscany</A>?</TD></TR></TABLE></DIV>

<H2><A name="OSGiEnablementforTuscanyRuntime-DevelopingTuscanymodulesasOSGibundles"></A>Developing Tuscany modules as OSGi bundles</H2>

<H3><A name="OSGiEnablementforTuscanyRuntime-DesignofanOSGibundle"></A>Design of an OSGi bundle</H3>

<UL>
	<LI>Modularity/Granularity
	<UL>
		<LI>Not just a simple packaging scheme such as all jars are consolidated into one big bundle, export/import everything</LI>
	</UL>
	</LI>
	<LI>Maven is designed to manage build dependency
	<UL>
		<LI>Visibility at module level (too high)</LI>
		<LI>Transitive dependency</LI>
		<LI>Classloading is flat</LI>
		<LI>No runtime control</LI>
	</UL>
	</LI>
</UL>


<H3><A name="OSGiEnablementforTuscanyRuntime-CreatinganOSGibundle"></A>Creating an OSGi bundle</H3>

<UL>
	<LI>Converting Tuscany modules into OSGi bundles
	<UL>
		<LI>META-INF/MANIFEST.MF</LI>
	</UL>
	</LI>
	<LI>Converting 3rd-party jars into OSGi bundles
	<UL>
		<LI>Plain Jars</LI>
		<LI>Patching existing bundles</LI>
	</UL>
	</LI>
	<LI>Distribution Structure</LI>
</UL>


<UL>
	<LI>Eclipse PDE integration
	<UL>
		<LI>Target platform</LI>
		<LI>Classpath setting</LI>
		<LI>PDE tools
		<UL>
			<LI>
			<UL>
				<LI>Build path</LI>
				<LI>PDE dependency view</LI>
				<LI>MANIFEST.MF editor</LI>
				<LI>Equinox run/debug profile</LI>
			</UL>
			</LI>
		</UL>
		</LI>
	</UL>
	</LI>
</UL>


<H3><A name="OSGiEnablementforTuscanyRuntime-MavenpluginstohelpOSGidevelopment"></A>Maven plugins to help OSGi development</H3>

<UL>
	<LI>Maven Eclipse Compiler
	<UL>
		<LI>Use Eclipse JDT as the compiler</LI>
		<LI>Validate the MANIFEST.MF</LI>
	</UL>
	</LI>
	<LI>Tuscany Maven Bundle Plugin
	<UL>
		<LI>Generating modules</LI>
		<LI>Generating PDE target</LI>
		<LI>Generating Equinox Configuration</LI>
	</UL>
	</LI>
</UL>


<H3><A name="OSGiEnablementforTuscanyRuntime-Runtimeconcerns"></A>Runtime concerns</H3>

<UL>
	<LI>Equinox OSGi launcher</LI>
	<LI>META-INF/services Service Provider discovery</LI>
	<LI>Avoid XMLInputFactory.newInstance(), DocumentBuilderFactory.newInstance()...</LI>
	<LI>Classloading (TCCL is evil)
	<UL>
		<LI>Equinox ContextFinder</LI>
	</UL>
	</LI>
</UL>


<H3><A name="OSGiEnablementforTuscanyRuntime-TestTuscanycodewithOSGi"></A>Test Tuscany code with OSGi</H3>

<UL>
	<LI>How to run maven surefire plugin with OSGi?</LI>
	<LI>Eclipse run as JUnit plugin test</LI>
</UL>


<H3><A name="OSGiEnablementforTuscanyRuntime-TroubleshoottheOSGiconstraintviolations"></A>Troubleshoot the OSGi constraint violations</H3>

<UL>
	<LI>OSGi console
	<UL>
		<LI>&#45;Dosgi.console=&lt;port #&gt;</LI>
	</UL>
	</LI>
	<LI>Eclipse PDE state view</LI>
	<LI>Traps
	<UL>
		<LI>Split Packages</LI>
		<LI>System packages</LI>
		<LI>Version mismatch</LI>
	</UL>
	</LI>
</UL>



<P><A href="osgi-enablement-for-tuscany-runtime.data/OSGi%20Enablement%20for%20Tuscany.ppt">OSGi Enablement for Tuscany.ppt</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">
            &nbsp;&nbsp;
            <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>
            &nbsp;&nbsp;
            <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 : OSGi Enablement for Tuscany Runtime';
              digg_topic = 'programming';
            </script>
            <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
            -->
            &nbsp;&nbsp;
          </TD>
          <TD align="right" valign="middle" class="footer">
            <A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A>&nbsp;&nbsp;-&nbsp;&nbsp;
            Copyright &copy; 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>&nbsp;&nbsp;
          </TD>
        </TR>
    </TABLE> 

    </BODY>
</HTML>