1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
7
<year>1997</year><year>2009</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
24
<title>Orber Examples</title>
27
<date>1997-05-20</date>
29
<file>ch_example.xml</file>
33
<title>A Tutorial on How to Create a Simple Service</title>
36
<title>Interface Design</title>
37
<p>This example uses a very simple stack server. The specification
38
contains two interfaces: the first is the Stack itself and the
39
other is the StackFactory which is used to create new stacks.
40
The specification is in the file <c>stack.idl</c>.</p>
41
<codeinclude file="../../examples/Stack/stack.idl" tag="" type="c"></codeinclude>
45
<title>Generating Erlang Code</title>
46
<p>Run the IDL compiler on this file by calling the <c>ic:gen/1</c> function </p>
48
\0111> ic:gen("stack").
50
<p>This will produce the client stub and server skeleton. Among other files a stack API module named <c>StackModule_Stack.erl</c>
52
This will produce among other files a stack API module called
53
<c>StackModule_Stack.erl</c> which contains the client stub and
54
the server skeleton. </p>
58
<title>Implementation of Interface</title>
59
<p>After generating the API stubs and the server skeletons it is time to
60
implement the servers and if no special options are sent
61
to the IDL compiler the file name should be
62
<c><![CDATA[<global interface name>_impl.erl]]></c>, in our case
63
<c>StackModule_Stack_impl.erl</c>.</p>
64
<codeinclude file="../../examples/Stack/StackModule_Stack_impl.erl" tag="" type="erl"></codeinclude>
65
<p>We also have the factory interface which is used to create new stacks
66
and that implementation is in the file
67
<c>StackModule_StackFactory_impl.erl</c>.</p>
68
<codeinclude file="../../examples/Stack/StackModule_StackFactory_impl.erl" tag="" type="erl"></codeinclude>
69
<p>To start the factory server one executes the function
70
<c>StackModule_StackFactory:oe_create/0</c> which in this
71
example is done in the module <c>stack_factory.erl</c> where
72
the started service is also registered in the name service.</p>
73
<codeinclude file="../../examples/Stack/stack_factory.erl" tag="" type="erl"></codeinclude>
77
<title>Writing a Client in Erlang</title>
78
<p>At last we will write a client to access our service.</p>
79
<codeinclude file="../../examples/Stack/stack_client.erl" tag="" type="erl"></codeinclude>
83
<title>Writing a Client in Java</title>
84
<p>To write a Java client for Orber you must have another
85
ORB that uses IIOP for client-server communication and supports a
86
Java language mapping. It must also have support for
87
<c>IDL:CosNaming/NamingContext</c> or <c>IDL:CosNaming/NamingContextExt</c>.
88
If the client ORB support Interoperable Naming Service the Java Client
90
<codeinclude file="../../examples/Stack/StackClient.java" tag="" type="c"></codeinclude>
92
<p>If an ORB does not support CosNaming at all the <c>cos_naming.idl</c>
93
file must be compiled and imported.</p>
98
<title>Building the Example</title>
99
<p>To build the example for access from a Java client you need a Java
100
enabled ORB (e.g. JavaIDL). The example below is based on JDK-1.4.</p>
103
Erlang (BEAM) emulator version 5.5.4.3 [async-threads:0] [hipe] [kernel-poll:false]
105
Eshell V5.5.4.3 (abort with ^G)
107
Erlang IDL compiler version 4.2.12
110
Recompile: StackModule_EmptyStack
111
Recompile: StackModule_Stack
112
Recompile: StackModule_StackFactory
113
Recompile: StackModule_StackFactory_impl
114
Recompile: StackModule_Stack_impl
116
Recompile: stack_client
117
Recompile: stack_factory
120
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
121
(v)ersion (k)ill (D)b-tables (d)istribution
123
fingolfin 128> idlj stack.idl
124
fingolfin 129> javac StackModule/*.java
125
fingolfin 130> javac *.java
126
fingolfin 131> cp StackClient.class StackModule/
131
<title>How to Run Everything</title>
132
<p>Below is a short transcript on how to run Orber.</p>
136
Erlang (BEAM) emulator version 5.5.4.3 [async-threads:0] [hipe] [kernel-poll:false]
138
Eshell V5.5.4.3 (abort with ^G)
139
1> orber:jump_start([{interceptors, {native, [orber_iiop_tracer_silent]}}]).
141
2> oe_stack:oe_register().
143
3> stack_factory:start().
145
4> stack_client:run().
153
<p>Before testing the Java part of this example generate and compile Java classes for
154
<c>orber/examples/stack.idl</c> as seen in the build example.
155
To run the Java client use the following command:</p>
158
fingolfin 38> java StackModule.StackClient "corbaname::localhost:4001#StackFactory"