140 likes | 374 Views
CORBA. A CORBA example. From url: http://java.sun.com/developer/technicalArticles/releases/corba/ The transient server example. The IDL file, Add.idl. module ArithApp { interface Add { const unsigned short SIZE=10; typedef long array[SIZE];
E N D
A CORBA example From url: http://java.sun.com/developer/technicalArticles/releases/corba/ The transient server example
The IDL file, Add.idl module ArithApp { interface Add { const unsigned short SIZE=10; typedef long array[SIZE]; void addArrays(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 ArithApp 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.
AddImpl.java implements the idl import ArithApp.*; import org.omg.CORBA.*; class AddImpl extends AddPOA { private ORB orb; public AddImpl(ORB orb) { this.orb = orb; } // implement the addArrays() method public void addArrays(int a[], int b[], ArithApp.AddPackage.arrayHolder result) { result.value = new int[ArithApp.Add.SIZE]; for(int i=0; i<ArithApp.Add.SIZE; i++) { result.value[i] = a[i] + b[i]; } }}
AddServer • AddServer.java in notes section
AddClient • AddClient.java in notes
Compile these files • prompt> javac *.java ArithApp/*.java
To run the application: • Start the orbd, which is a name server: prompt> orbd -ORBInitialPort 2500 • The number 2500 is the port number where you want the orbd to run. Note that the -ORBInitialPort is a require command-line argument. Start the AddServer: prompt> java AddServer -ORBInitialPort 2500 • Start the AddClient: prompt> java AddClient -ORBInitialPort 2500
Persistent serverstart server tool-this 2nd example not completed