CORBA A CORBA example From url http java
CORBA
A CORBA example From url: http: //java. sun. com/developer/technical. Articl es/releases/corba/ The transient server example
The IDL file, Add. idl module Arith. App { interface Add { const unsigned short SIZE=10; typedef long array[SIZE]; void add. Arrays(in array a, in array b, out array result); }; };
Use idl compiler to compile this file • prompt> idlj -fall Add. idl • This command will generate several files. Check the local directory where you run the command from to see the files. You will notice that a new subdirectory with the name Arith. App has been created. This is because an OMG IDL module is mapped to a Java package. For more information on the idlj compiler and the options you can use, please see the IDL-to-Java Compiler.
Add. Impl. java implements the idl import Arith. App. *; import org. omg. CORBA. *; class Add. Impl extends Add. POA { private ORB orb; public Add. Impl(ORB orb) { this. orb = orb; } // implement the add. Arrays() method public void add. Arrays(int a[], int b[], Arith. App. Add. Package. array. Holder result) { result. value = new int[Arith. App. Add. SIZE]; for(int i=0; i<Arith. App. Add. SIZE; i++) { result. value[i] = a[i] + b[i]; } }}
Add. Server • Add. Server. java in notes section
Add. Client • Add. Client. java in notes
Compile these files • prompt> javac *. java Arith. App/*. java
To run the application: • Start the orbd, which is a name server: prompt> orbd -ORBInitial. Port 2500 • The number 2500 is the port number where you want the orbd to run. Note that the -ORBInitial. Port is a require command-line argument. Start the Add. Server: prompt> java Add. Server -ORBInitial. Port 2500 • Start the Add. Client: prompt> java Add. Client -ORBInitial. Port 2500
Run orbd at ORBInitial. Port 2500
Run server
Run client
Persistent server
Persistent server start server tool-this 2 nd example not completed
- Slides: 14