A simple CORBA implementation using Java
The IDL file defines the interface that will be used by the client and server for communicating and passing objects.
When the IDL file gets compiled, it will produce a number of files, known as the stub and skeleton:
- The stub is used by the client to communicate with the server
- The skeleton is used by the server to communicate with the client
- The stub and skeleton communicate with the ORB server to facilitate the remote procedure call
The module in the IDL file will correspond to the package and directory in which the Java code will be generated
Echo.idl
module EchoApp {
interface Echo {
string echoString();
};
};
There is an idlj program that comes with the JDK for generating the stub and skeleton code in Java
idlj –fall sum.idl
The following files are generated by the idlj program:
- _EchoStub.java
- Echo.java
- EchoHelper.java
- EchoHolder.java
- EchoOperations.java
- EchoPOA.java
The server program will inherit from the EchoPOA class that was generated as part of the idlj program.
The EchoPOA class implements the EchoOperations interface
- This interface contains the methods we defined in the Echo.idl file, but standardized to Java.
We create an EchoServer.java class that extends the abstract EchoPoa class and then implement the methods contained in it
We create a main method in Server.java to communicate with the object request broker (ORB), registering the server with the ORB so clients are able to find it.
The client program Client.java needs to get a reference to the ORB then resolve the name of the server object it would like to invoke.
- This is ECHO-SERVER in this case
After getting an instance of a Server object from the server, it can invoke methods on it just like a method within its own JVM.
-
Compile the stub and skeleton from the directory that contains the IDL file.
Windows
javac EchoApp\*.java
Linux
javac EchoApp/*.java
-
Generate a JAR file from the compiled stub and skeleton.
Windows
jar cvf echoapp.jar EchoApp\*.class
Linux
jar cvf echoapp.jar EchoApp/*.class
-
Compile the server and client classes
Windows
javac -classpath .;echoapp.jar Server.java EchoServer.java Client.java
Linux
javac -classpath .:echoapp.jar Server.java EchoServer.java Client.java
-
Start the ORB server
orbd -ORBInitialPort 1050 -ORBInitialHost localhost
-
Start the server application
java Server -ORBInitialPort 1050 -ORBInitialHost localhost
-
Start the client application
java Client -ORBInitialPort 1050 -ORBInitialHost localhost
If everything was compiled correctly the output should be:
Hello World!!!!!!!