Tutorial One - Greetings, Earthling
From AdaDKWiki - an Ada Programming Wiki
Contents |
Introduction
Welcome to the first of a series of tutorials detailing the construction, configuration and execution of distributed Ada applications. The tutorials are intended to ease a newcomer's entry to building distributed applications with Ada.
More information on DSA can be found here:
- Ada 2005 Reference Manual, Annex E
- Ada 95 Reference Manual, Annex E
- Ada 95 Rationale on Distributes Systems
Design
The 'hello DSA' application is perhaps the simplest possible example of a DSA application.
The main application entities are:
Server:
- exists as a single instance
- provides a single service 'greet', which returns a greeting string to a Client
- implemented as a DSA 'remote call interface' package
Client:
- many instances may exist
- a Client instance will request the Server's 'greet' message and displays it, in an infinite loop.
- implemented as a normal Ada package
Applets:
- Two applets exist to launch the server or a client
- These are implemented as normal Ada main subprograms
The source code is simple enough that it may be presented herein ...
Source Code
Server:
package Server is pragma remote_call_Interface; function Greeting return String; end Server; package body Server is function Greeting return String is begin return "Greetings, Earthling."; end; end Server;
Client:
package Client is procedure Start; end Client; with Server; with ada.Text_IO; use ada.Text_IO; package body Client is procedure Start is begin loop delay 1.0; put_Line ("Server says: '" & Server.Greeting); end loop; end; end Client;
Applets:
with Client; with Server; procedure start_Server is begin loop delay 0.5; end loop; end; with Client; procedure start_Client is begin Client.start; end;
Preparation
Of course, we need an Ada compiler and DSA implementation. A good choice might be the Gnat and Polyorb (GPL09) versions available at Libre.
Polyorb will need to be built from source via:
$ ./configure --enable-debug --with-appli-perso="dsa" --with-proto-perso="giop" $ make $ make install
Now that our tools are installed, we can build the distributed application...
Build
To build a distributed application, po_gnatdist is used, instead of gnatmake.
Instead of producing a single executable (as gnatmake does), po_gnatdist will produce an executable for each partition involved in the distributed application. In our case, an executable for each of the Server partition and Client partition will be produced.
po_gnatdist is fed a build-time configuration file, which tells po_gnatdist which package belongs to which partition executable.
For hello DSA, the following dsa.cfg is our build-time configuration for po_gnatdist and would be invoked with:
$ po_gnatdist dsa.cfg
This should build both the Server and Client executables and place them in the ./bin directory.
configuration DSA is pragma Starter (none); -- Tell 'po_gnatdist' to not create any startup script or launcher (more on this in a lter tute). -- We will launch our Server and Client partitions manually from a console. -- Server server_Partition : partition := (Server); -- Declare the Server partition and assign the 'Server' remote call interface package to this partition. procedure start_Server is in server_Partition; -- Tell po_gnatdist that the 'start_Server' procedure is the the Servers 'main' subprogram or launcher. -- Client client_Partition : partition; -- Declare the Client partition (which has no remote call interface package associated with it, so no 'initialisation' is required). procedure start_Client; -- Declare the Clients 'main' subprogram or launcher. for client_Partition'Main use start_Client; -- Tell po_gnatdist to assign the above declared 'start_Client' procedure as the Clients 'main' subprogram or launcher. for client_Partition'Termination use Local_Termination; -- Tell po_Gnatdist that Clients may terminate locally (more on this later). -- Misc for Partition'Directory use "bin"; -- Ask po_gnatdist to place the built Client and Server partition executables in the './bin' sub-folder. end DSA;
Trial
Now that both client and server partitions have been built, we can test them, first locally within a LAN, and then across a WAN via the internet.
Local Area Net Test
- Run-time configuration: (polyorb.conf)
- start po_cos_naming:
- start Server:
- start Client:
Wide Area Net Test
- adjust /etc/hosts:
- open ports:
- Run-time configuration: (polyorb.conf)
- start po_cos_naming:
- start Server:
- start Client:

