summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/sca-java-bindingerlang.html
blob: 9fa720421ed7b6bc427c246e19a55649a1c19eb9 (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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE- 2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
		<!-- generateKeywords macro -->
	    <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">
		<!-- generateKeywords macro end -->
		
        <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/TUSCANY/$images/favicon.ico">   
        <TITLE>Apache Tuscany : SCA Java binding.erlang</TITLE>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
    
    <BODY onload="init()">
        <!-- topNav macro -->
		<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="https://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>

				<!-- Adds the edit page link to the top banner-->
				<TD valign="bottom">
					<DIV style="padding: 2px 10px; margin: 0px;">
						<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=118627">
						<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>
        <!-- topNav macro end -->

		<!-- breadCrumbs macro -->
		<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="sca-java-user-guide.html" title="SCA Java User Guide">SCA Java User Guide</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java binding.erlang">SCA Java binding.erlang</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>
		<!-- breadCrumbs macro end -->


        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
            <TR>
                <TD align="left" valign="top">

					<!-- pageContent macro -->
					<DIV id="PageContent">
												
						<DIV class="pagecontent">
							<DIV class="wiki-content">
								<TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR>
<TD class="confluenceTd" valign="top" width="15%">
<DIV class="panel" style="background-color: #ECF4D1;border-color: #C3CDA1;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #C3CDA1;background-color: #C3CDA1;"><B>General</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="home.html" title="Home">Home</A><BR>
<A href="http://www.apache.org/licenses/LICENSE-2.0.html" class="external-link" rel="nofollow">License </A><BR>
<A href="sca-java-get-involved.html" title="SCA Java Get Involved">Get Involved</A><BR>
<A href="sca-java-found-a-bug.html" title="SCA Java Found A Bug">Found a Bug?</A></P>
</DIV></DIV>

<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java.html" title="SCA Java">SCA Java Home</A><BR>
<A href="tuscany-dashboard.html" title="Tuscany Dashboard">SCA Dashboard</A><BR>
<A href="java-sca-tools.html" title="Java SCA Tools">Tools </A><BR>
<A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A></P>
</DIV></DIV>

<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 1.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-releases.html" title="SCA Java Releases">Downloads</A><BR>
<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Documentation</A><BR>
<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/" class="external-link" rel="nofollow">1.x Source Code</A><BR>
<A href="http://tinyurl.com/8rlxd3" class="external-link" rel="nofollow">Roadmap</A></P>
</DIV></DIV>

<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 2.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-2x-releases.html" title="SCA Java 2.x Releases">Downloads</A><BR>
<A href="http://tuscany.apache.org/documentation-2x/" class="external-link" rel="nofollow">Documentation</A><BR>
<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/" class="external-link" rel="nofollow">2.x Source Code</A><BR>
<A href="http://tinyurl.com/8rlxd3" class="external-link" rel="nofollow">Roadmap</A></P>
</DIV></DIV>


<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>Documentation</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-user-guide.html" title="SCA Java User Guide">User Guide</A><BR>
<A href="sca-java-architecture-guide.html" title="SCA Java Architecture Guide">Architecture Guide</A><BR>
<A href="sca-java-development-guide.html" title="SCA Java Development Guide">Developer Guide</A><BR>
<A href="sca-java-extension-development-guide.html" title="SCA Java Extension Development Guide">Extension Developer Guide</A></P>
</DIV></DIV>

<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>Resources</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A><BR>
<A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sca" class="external-link" rel="nofollow">Source Code</A></P>
</DIV></DIV>
</TD>
<TD class="confluenceTd" valign="top" width="85%">

<H3><A name="SCAJavabinding.erlang-%3Cbinding.erlang%3E"></A>&lt;binding.erlang&gt;</H3>

<P>The Tuscany Java SCA runtime supports Erlang using the &lt;binding.erlang&gt; SCDL extension. New Erlang based service can be provided using a &lt;binding.erlang&gt; element within a SCA &lt;service&gt;, existing Erlang object can be accessed using a &lt;binding.erlang&gt; element within a SCA &lt;reference&gt;.</P>
<UL>
	<LI><A href="#SCAJavabinding.erlang-using"><B>Using Erlang binding</B></A>
	<UL>
		<LI><A href="#SCAJavabinding.erlang-requirements"><B>Requirements</B></A></LI>
		<LI><A href="#SCAJavabinding.erlang-configuration"><B>Binding configuration</B></A></LI>
		<LI><A href="#SCAJavabinding.erlang-interface"><B>Declaring interface</B></A></LI>
	</UL>
	</LI>
	<LI><A href="#SCAJavabinding.erlang-messaging"><B>Details of message based RPC</B></A></LI>
	<LI><A href="#SCAJavabinding.erlang-Exceptions"><B>Exceptions</B></A></LI>
	<LI><A href="#SCAJavabinding.erlang-Samples"><B>Samples</B></A></LI>
</UL>


<P><A name="SCAJavabinding.erlang-using"></A></P>

<H2><A name="SCAJavabinding.erlang-UsingErlangbinding"></A>Using Erlang binding</H2>

<P>Basically SCA services can be exposed in two ways:</P>
<UL>
	<LI>by Erlang <B>RPC</B> mechanism. In this case SCA component would act as Erlang module containing functions, based on components operations names.</LI>
	<LI>by RPC realised using Erlang <B>messaging</B>. In this case for every operation named Erlang message box would be created - name of the box will correspond to operation name. After receiving message from Erlang node appropriate components operation will be invoked and result would be sent back to sender.</LI>
</UL>


<P>Similarly, SCA references can access Erlang modules in two ways:</P>
<UL>
	<LI>using <B>RPC</B> mechanism. In this case SCA reference would be mapped to remote Erlang functions module, each operation would correspond to different function, basing on its name.</LI>
	<LI>by RPC realised using Erlang <B>messaging</B>. In this case invoking operation on reference would cause sending Erlang message to named Erlang process - name would be the same as operation name. If operation has return value then return message will be expected.</LI>
</UL>


<P><A name="SCAJavabinding.erlang-requirements"></A></P>

<H4><A name="SCAJavabinding.erlang-Requirements"></A>Requirements</H4>

<P>Erlang binding is available since Apache Tuscany SCA Java 1.6, <B>source distribution only</B>. To use Erlang binding module you need to build Apache Tuscany by your own, please follow instructions contained in <B>BUILDING</B> file which can be found in source distribution root directory.</P>

<P>Erlang nodes need to communicate with <B>Erlang Port Mapper Daemon (EPMD)</B> which should be run locally. To run JUnit tests and samples for Tuscany Erlang modules you <B>need to have epmd binary</B> in your system path - epmd comes with Erlang/OTP distribution. See <A href="http://erlang.org/" class="external-link" rel="nofollow">http://erlang.org</A> for downloads.</P>

<P>Erlang samples and JUnit tests inside Tuscany spawns epmd process automatically, but if you are creating your own solution using Erlang binding <B>you need to provide running epmd process</B>.</P>

<P><A name="SCAJavabinding.erlang-configuration"></A></P>

<H4><A name="SCAJavabinding.erlang-Bindingconfiguration"></A>Binding configuration</H4>

<P>Binding configuration can take several attributes:</P>
<UL>
	<LI><B>node</B> &#45; name of the local (service side) or remote (reference side) Erlang node. Tuscany creates separate Erlang node for each service binding, so remember to provide unique node name for every service binding.</LI>
	<LI><B>module</B> &#45; specifies name of the module mapped to SCA component/reference. When using this attribute you can't use mbox=&quot;true&quot; attribute.</LI>
	<LI><B>mbox</B> &#45; specifies whether binding would be realised using messaging based RPC (&quot;true&quot;) or built-in Erlang RPC (&quot;false&quot;). Default (no value specified) is &quot;false&quot;. When using mbox=&quot;true&quot; you can't use module attribute.</LI>
	<LI><B>cookie</B> &#45; (optional) authentication token. Communicating nodes should have the same cookies. You can also provide cookie in .erlang.cookie file in users home directory (it's originally supported by Jinterface).</LI>
	<LI><B>timeout</B> &#45; (optional) specifies timeout (in milliseconds) for inactive connections. Timeouts will be disabled if attribute value is 0 or not provided.</LI>
	<LI><B>serviceThreadPool</B> &#45; (optional) for service side bindings only. Specifies maximum number of threads which will be handling clients. Default value is 20.</LI>
</UL>


<H5><A name="SCAJavabinding.erlang-Serviceconfigurationsamples"></A>Service configuration samples</H5>

<P><B>Sample based on RPC</B></P>

<P>Following sample exposes component as Erlang module named &quot;HelloModule&quot;. Modules functions would be the same as in service interface - helloworld.HelloWorld. Node which will host this module will be named &quot;HelloNodeModule&quot;.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
&lt;service name=<SPAN class="code-quote">&quot;HelloWorldService&quot;</SPAN>&gt;

    &lt;<SPAN class="code-keyword">interface</SPAN>.java <SPAN class="code-keyword">interface</SPAN>=<SPAN class="code-quote">&quot;helloworld.HelloWorld&quot;</SPAN>/&gt;

    &lt;tuscany:binding.erlang node=<SPAN class="code-quote">&quot;HelloNodeModule&quot;</SPAN> module=<SPAN class="code-quote">&quot;HelloModule&quot;</SPAN>/&gt;

&lt;/service&gt;
</PRE>
</DIV></DIV>
<P><B>Sample based on messaging</B></P>

<P>Following sample exposes component as several message boxes - each box will correspond to each component operation. Node which will host those message boxes will be named &quot;HelloNodeMbox&quot;.<BR>
Additional attributes are used:</P>
<UL>
	<LI>cookie for authentication purposes - &quot;secret string&quot;</LI>
	<LI>timeout (1 second) for disconnecting hanging clients</LI>
	<LI>number of threads that handles clients (serviceThreadPool attribute) is set to 10.</LI>
</UL>


<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
&lt;service name=<SPAN class="code-quote">&quot;HelloWorldService&quot;</SPAN>&gt;

    &lt;<SPAN class="code-keyword">interface</SPAN>.java <SPAN class="code-keyword">interface</SPAN>=<SPAN class="code-quote">&quot;helloworld.HelloWorld&quot;</SPAN>/&gt;

    &lt;tuscany:binding.erlang node=<SPAN class="code-quote">&quot;HelloNodeMbox&quot;</SPAN> mbox=<SPAN class="code-quote">&quot;<SPAN class="code-keyword">true</SPAN>&quot;</SPAN> cookie=<SPAN class="code-quote">&quot;secret string&quot;</SPAN> timeout=<SPAN class="code-quote">&quot;1000&quot;</SPAN> serviceThreadPool=<SPAN class="code-quote">&quot;10&quot;</SPAN>/&gt;

&lt;/service&gt;
</PRE>
</DIV></DIV>

<H5><A name="SCAJavabinding.erlang-Referenceconfigurationsamples"></A>Reference configuration samples</H5>

<P><B>Sample based on RPC</B></P>

<P>Following sample uses remote Erlang module as reference. Configuration points to module named &quot;HelloModule&quot;, hosted on &quot;HelloNodeModule&quot;.<BR>
Additional attributes are used:</P>
<UL>
	<LI>cookie for authentication purposes - &quot;secret string&quot;</LI>
	<LI>timeout (1 second) for quitting from hanging server</LI>
</UL>


<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
&lt;reference name=<SPAN class="code-quote">&quot;helloWorldReference&quot;</SPAN>&gt;

    &lt;tuscany:binding.erlang node=<SPAN class="code-quote">&quot;HelloNodeModule&quot;</SPAN> module=<SPAN class="code-quote">&quot;HelloModule&quot;</SPAN> cookie=<SPAN class="code-quote">&quot;secret string&quot;</SPAN> timeout=<SPAN class="code-quote">&quot;1000&quot;</SPAN>/&gt;

&lt;/reference&gt;
</PRE>
</DIV></DIV>
<P><B>Sample based on messaging</B></P>

<P>Following sample uses remote Erlang message boxes in RPC style. Message boxes with names the same as reference operations are available on &quot;HelloNodeMbox&quot;.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
&lt;reference name=<SPAN class="code-quote">&quot;helloWorldReference&quot;</SPAN>&gt;

    &lt;tuscany:binding.erlang node=<SPAN class="code-quote">&quot;HelloNodeMbox&quot;</SPAN> mbox=<SPAN class="code-quote">&quot;<SPAN class="code-keyword">true</SPAN>&quot;</SPAN>/&gt;

&lt;/reference&gt;
</PRE>
</DIV></DIV>
<P><A name="SCAJavabinding.erlang-interface"></A></P>

<H4><A name="SCAJavabinding.erlang-Declaringinterface"></A>Declaring interface</H4>

<P>Following table describes mapping used between Java and Erlang types.</P>
<DIV class="table-wrap">
<TABLE class="confluenceTable"><TBODY>
<TR>
<TH class="confluenceTh"> Java type </TH>
<TH class="confluenceTh"> Erlang type </TH>
</TR>
<TR>
<TD class="confluenceTd"> byte, short, char, int, long </TD>
<TD class="confluenceTd"> number - Erlang does not distinguish numbers size </TD>
</TR>
<TR>
<TD class="confluenceTd"> float, double </TD>
<TD class="confluenceTd"> Double - Erlang does not distinguish floating numbers size </TD>
</TR>
<TR>
<TD class="confluenceTd"> String </TD>
<TD class="confluenceTd"> Array of characters </TD>
</TR>
<TR>
<TD class="confluenceTd"> String annotated with @ErlangAtom (package org.apache.tuscany.sca.binding.erlang.meta) </TD>
<TD class="confluenceTd"> Atom </TD>
</TR>
<TR>
<TD class="confluenceTd"> array </TD>
<TD class="confluenceTd"> List </TD>
</TR>
<TR>
<TD class="confluenceTd"> User defined class with pubic no argument constructor and public fields of type from this table. </TD>
<TD class="confluenceTd"> Tuple </TD>
</TR>
</TBODY></TABLE>
</DIV>


<H5><A name="SCAJavabinding.erlang-Atomssample"></A>Atoms sample</H5>

<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> SomeInterface {

  <SPAN class="code-comment">// Returns user defined class - tuple
</SPAN>  TupleClass operation1();

  <SPAN class="code-comment">// Returns list of characters and takes list of characters as an argument
</SPAN>  <SPAN class="code-object">String</SPAN> operation2(<SPAN class="code-object">String</SPAN> argument);

  <SPAN class="code-comment">// Returns atom and takes atom as an argument
</SPAN>  @ErlangAtom
  <SPAN class="code-object">String</SPAN> operation3(@ErlangAtom <SPAN class="code-object">String</SPAN> argument);

  <SPAN class="code-comment">// Returns list of atoms
</SPAN>  @ErlangAtom
  <SPAN class="code-object">String</SPAN>[] operation4();

}


<SPAN class="code-comment">// Java class represents tuple which contains atom and list of characters.
</SPAN><SPAN class="code-keyword">public</SPAN> class TupleClass {

  @EralngAtom
  <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> atom;

  <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> notAtom;

}
</PRE>
</DIV></DIV>

<H5><A name="SCAJavabinding.erlang-Tuplessample"></A>Tuples sample</H5>

<P>Following interface:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> class TupleClass1 {

  <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">long</SPAN> field1;
  <SPAN class="code-keyword">public</SPAN> TupleClass2 field2;

}

<SPAN class="code-keyword">public</SPAN> class TupleClass2 {

  <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">long</SPAN> field1;
  <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">double</SPAN> field2;

}
</PRE>
</DIV></DIV>
<P>will correspond to live tuple structure (using Erlang notation):</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
{10, {10, 0.9}}
</PRE>
</DIV></DIV>

<P><A name="SCAJavabinding.erlang-messaging"></A></P>

<H2><A name="SCAJavabinding.erlang-DetailsofmessagebasedRPCcommunication"></A>Details of message based RPC communication</H2>

<P>RPC based on messaging uses messages for requests and responses.</P>
<UL>
	<LI>For <B>service bindings</B> incoming messages should contain SCA operation arguments, formed in tuple. Operation result will be send in return message.</LI>
	<LI>For <B>reference bindings</B> Tuscany creates message with content depending on attributes passed to reference operation. If reference operation has return value defined then Tuscany will wait for reply from remote process.</LI>
</UL>


<P>In Erlang messaging it's common technique for sender to provide it's PID at the beginning - it allows recipient to respond. In Tuscany every Erlang message is a tuple which contains operation arguments. This tuple is wrapped with tuple with PID.</P>

<H4><A name="SCAJavabinding.erlang-Overloadingoperations"></A>Overloading operations</H4>

<P>Overloading operations allows user to send message with different structure. Ie., in reference binding we could declare interface:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> SomeInterface {

  void someMbox(<SPAN class="code-object">String</SPAN> argument);

  void someMbox(<SPAN class="code-object">String</SPAN> arg1, <SPAN class="code-object">String</SPAN> arg2);

}
</PRE>
</DIV></DIV>
<P>Invoking first <B>someMbox</B> operation would cause sending message addressed to <B>someMbox</B> message box. This message would contain one string value. Invoking second <B>someMbox</B> operation would cause sending message addressed also to <B>someMbox</B> message box, but message content would differ - now it would contain two string values.</P>

<H4><A name="SCAJavabinding.erlang-Servicesideexample"></A>Service side example</H4>

<P>For service defined by following interface:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> operation(<SPAN class="code-object">long</SPAN> arg1, @ErlangTuple arg2);
</PRE>
</DIV></DIV>
<P>expected Erlang message is (sample using Erlang notation):</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
{SomePid, {10, AtomValue}}
</PRE>
</DIV></DIV>
<P>After receiving such formed message Tuscany is able to process it correctly, invoke SCA operation and send reply to PID provided as first element of outer tuple.</P>

<H4><A name="SCAJavabinding.erlang-Referencesideexample"></A>Reference side example</H4>

<P>For reference interface defined as:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">String</SPAN> operation(<SPAN class="code-object">long</SPAN> arg1, @ErlangTuple <SPAN class="code-object">String</SPAN> arg2);
</PRE>
</DIV></DIV>
<P>executing it with following arguments:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
obj.operation(10, <SPAN class="code-quote">&quot;AtomValue&quot;</SPAN>);
</PRE>
</DIV></DIV>
<P>will make Tuscany to convert input arguments to Erlang tuple (using Erlang notation):</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
{10, AtomValue}
</PRE>
</DIV></DIV>
<P>and wrap with tuple containing PID as follows (using Erlang notation):</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
{SomePid, {10, AtomValue}}
</PRE>
</DIV></DIV>
<P>In this example Erlang message box would receive message and know PID for reply.</P>

<P><A name="SCAJavabinding.erlang-exceptions"></A></P>

<H2><A name="SCAJavabinding.erlang-Exceptions"></A>Exceptions</H2>

<P>While communicating with Erlang nodes (reference bindings) several error can be raised:</P>
<UL>
	<LI>Function on remote Erlang doesn't exist</LI>
	<LI>Connection problems</LI>
	<LI>Others and unexpected errors</LI>
</UL>


<P>In case of error two things can happen:</P>
<UL>
	<LI><B>Exception will be thrown</B>, only for operations which <B>declares exceptions</B></LI>
	<LI><B>Problem will be logged</B>, only for operations with <B>no exception declared</B></LI>
</UL>


<P><A name="SCAJavabinding.erlang-samples"></A></P>

<H2><A name="SCAJavabinding.erlang-Samples"></A>Samples</H2>

<P>Samples can be found under sca/java/samples/:</P>
<UL>
	<LI><B>helloworld-service-erlang</B></LI>
	<LI><B>helloworld-reference-erlang</B></LI>
</UL>


<P>Samples use service and reference Erlang bindings realised via Erlang RPC. If you want to play with Erlang binding it's good place to start. Maybe you would like to experiment by changing communication model to message based?<BR>
For running instructions <B>please read README files</B>. You should also get familiar with <A href="#SCAJavabinding.erlang-requirements"><B>requirements</B></A>.</P></TD></TR></TBODY></TABLE>
							</DIV>
						</DIV>
					</DIV>	
		            <!-- pageContent macro end -->
					
                </TD>
            </TR>
        </TABLE>

		<!-- footer macro -->
				<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 � 2003-2012, The Apache Software Foundation&nbsp;&nbsp;</BR>
                        Apache Tuscany and the Apache Tuscany project logo are trademarks of The Apache Software Foundation.
		</DIV>
		<!-- footer macro end -->

    </BODY>
</HTML>