This example is meant to break that barrier, and to show the elementary steps to be taken in writing a CORBA application. To complicate matters a bit, we write a three-language system, consisting of three servers and three clients, written respectively in C++, Java and Prolog.
In the example, it is shown in complete detail how to write clients and servers in the three respective languages, how to write a test program to test all possible combinations and how to manage the configuration of a CORBA application.
The example is based on the original Hello World example
that came with Orbacus 3.1 from
Object-Oriented Concepts
and examples from the experimental
SWI-Prolog CORBA binding
for Orbacus 3.1.
The interface -- IDL
The definition below defines a module universe that contains an interface named world. The world interface provides the method hello and two additional methods ask and tell.
universe.idl
interface world {
void hello();
void ask(in string x);
string tell();
oneway void halt();
};
};
In addition, the world interface supports a method halt,
which was introduced to stop the world on the client's demand.
In actual applications, you do not want to provide
such a method without ensuring that the client has the
right to stop the world.
C++ realization
Client
The implementation of the actual world
server is as simple as its C++ peer.
The implementation of the server object consists of
a collection of predicate definitions (procedures),
that have the interface or class name as a prefix.
Testing CORBA applications is significantly more difficult
than testing stand-alone applications.
This is due on the one hand to the fact that it concerns
a distributed application, involving communication
over a network, and on the other hand to the indirection
that must take place within both the client and the server
to invoke and answer methods over the object request broker
software bus.
As in other areas, in CORBA programming it is good advice
to start small and grow incrementally.
Develop your system in such a way that you can
gradually forget about the wiring, and
concentrate on the application logic instead.
(C) Æliens
04/09/2009
Java -- server implementation
import org.omg.CORBA.*;
public class world_srv extends _worldImplBase
{
public void hello() {
System.out.println("Hello World!");
}
public void ask(String msg) {
System.out.println(msg);
}
public String tell() {
String s = new String("ok");
return s;
}
public void halt() {
System.exit(0);
}
}
Discussion
Prolog realization
Prolog realization
...
corba_initialize_orb([], _),
factory(F). // gives a handle to the server object
broker(server(M:I)) :-
...
corba_initialize_server([server,server(test),
timeout(infinite)],Server),
... // create server object
G =.. [_Create,_Server,Self],
call(G),
corba_object_to_string(Self,IOR),
open(IORFile,write,Fd), // write reference to file
format(Fd,'string',[IOR]),
close(Fd),
corba_main_loop(Server). // enter main loop
Client
:- use_module(universe). // see universe.pl
:- [broker]. // include broker
main :-
broker(client(universe:F)), // initialize the broker
assert(client(factory(F))),
run.
run :-
h,
ask('What is the state of Clinton s affairs?'),
write('Type h to say hallo, x to quit.'),nl.
ask(X) :-
client(factory(F)),
write(client(ask(X))),nl,
world_ask(F,X),
world_tell(F,R),
write(client(ans(R))),nl.
h :- client(factory(F)), world_hello(F).
q :- client(factory(F)), world_halt(F), halt.
x :- halt.
Server
main :-
broker(server(universe:world)).
Prolog -- implementation
world_hello(_Self) :-
write('Hello World'),nl.
world_ask(_Self, X) :-
write(asking(X)), nl.
world_tell(_Self,Y) :-
Y = 'logically, ok',
write(telling(Y)),nl.
world_halt(_Self) :-
halt.
Discussion
Configure, make and test
Configure, make and test
Conclusions
Conclusions