Description
Assignment 3:To develop any distributed application using CORBA using JAVA IDL. Problem statement: Develop a simple calculator.
Objectives:Students will be able to implement any distributed application based on CORBA. Tools:Java 8 with IDLJ Compiler
Theory:
CORBA:
● Stands for Common Object Request Broker Architecture.
● It is a specification for creating distributed objects and NOT a programming language.
● It promotes design of applications as a set of cooperating objects.
● Clients are isolated from servers by interface.
● CORBA objects run on any platform, can be located anywhere on the network and can be written in any language that has IDL mapping.
● Working:
● A CORBA (Common Object Request Broker Architecture) application is developed using IDL (Interface Definition Language).
● IDL is used to define interfaces and the Java IDL compiler generates skeleton code.
● CORBA technology is an integral part of the Java platform. It consists of an Object Request Broker (ORB), APIs for the RMI programming model, and APIs for the IDL programming model.
● The Java CORBA ORB supports both the RMI and IDL programming models.
● I will be using the IDL Programming Model for this assignment.
● Object Request Broker is an Object Manager in CORBA.
● It is present on the client side as well as server side (allows agents to act as both clients and servers of remote objects).
● On client side the ORB is responsible for
○ accepting requests for a remote object
○ finding implementation of the object
○ accepting client-side reference to the remote object(converted to a language specific form, e.g., a Java stub object)
○ routing client method calls through the object reference to the object implementation.
● On server side the ORB
○ lets object servers register new objects
○ receives requests from the client ORB
○ uses object’s skeleton interface to invoke object’s activation method
○ creates a reference for a new object and sends it back to the client.
○ Between the ORBs, Internet Inter-ORB Protocol is used for communication.
What is IDL?
● IDL is Interface Definition Language which defines protocol to access objects.
● Stub lives on the client, and pretends to be a remote object.
● Similarly, Skeleton lives on the server, receives requests from stub, talks to the true remote object and delivers the response to stub.
How to use CORBA with JAVA?
● Java-idl is a technology for distributed objects, i.e objects interacting on different platforms across a network.
● Translates IDL concepts to Java Language Constructs.
● It enables objects to interact regardless of whether they’re written in the Java programming language or another language such as C, C++.
● This is possible because Java IDL is based on the Common Object Request Brokerage
Architecture (CORBA), an industry-standard distributed object model.
● Each language that supports CORBA has its own IDL mapping, and as its name implies,
Java IDL supports the mapping for Java.
● To support interaction between objects in separate programs, Java IDL provides an
Object Request Broker, or ORB.
● The ORB is a class library that enables low-level communication between Java IDL applications and other CORBA-compliant applications.
● On the client side, the application includes a reference for the remote object. The object reference has a stub method, which is a stand-in for the method being called remotely.
● The stub is actually wired into the ORB, so that calling it invokes the ORB’s connection capabilities, which forwards the invocation to the server.
How to write a CORBA Program in Java??
1. Writing the IDL file
a. Create the directory for project and inside the directory, create a file with name
calc.idl
b. There are 3 steps of writing an IDL file
i. Declare the CORBA IDL module – module calc_val (Translates to the
module in java)
ii. Declaring the interface – this will generate a Java interface (Java code)
iii. Declaring the operations – define the functions which we want to implement (Translates to the methods in the said interface).
iv. In the end it will look like this
module calc_val
{
interface calc
{
double addfn(in double a,in double b); double subfn(in double a,in double b); double mulfn(in double a,in double b); double divfn(in double a,in double b);
}; };
c. Compile the idl file
idlj -fall calc.idl
2. Write the server
a. Once we compile the IDL file, we get skeleton files which can be then used to create the server and client applications.
b. Server typically consists of two classes, one is called the Servant and other is called the Server.
c. The Servant (calcImplementation) is the implementation of the calc IDL
interface.
d. The Servant implements the actual functions defined in IDL. It is a subclass of
_serverImpl, which is generated by the idlj compiler.
e. Servant methods are ordinary Java methods, meant to provide actual implementation by overriding the interface methods. They marshal the
arguments and results, and so on, which is provided by the server and the stubs.
f. The server class has the server’s main() method, which:
i. Creates an ORB instance.
ii. Creates a servant instances and tells the ORB about it.
iii. Gets a CORBA object reference for a naming context in which to register
the new CORBA object.
iv. Registers the new object in the naming context under the name “Hello“.
v. Waits for invocations of the new object.
3. Implement the Client
a. Performing Basic Setup: The structure of a CORBA client program is the same as
most Java applications: You import required library packages, declare the
application class, define a main() method, and handle exceptions.
b. Create main method
c. Handle the exceptions
d. Create an ORB object
e. Find the Server using COS Naming service.
f. Finding a Service in Naming: CORBA name servers handle complex names by way
of NameComponent objects.
g. An array of NameComponent objects can hold a fully specified path to an object
on any computer file or disk system.
h. We pass path to the naming service’s resolve() method to get an object reference to the calc Server and narrow is to a object.
i. The resolve method returns a generic CORBA object, calcHelper immediately narrows it to a calc object.
4. Run the application:
a. Start the ORDB service.
orbd -ORBInitialPort 1051 -ORBInitialHost localhost&
b. Compile server and client code
Javac calcServer.java -Xlint:unchecked
javac calcClient.java -Xlint:unchecked
c. Run the server and client code
java Server.calc Server -ORBInitialPort 1050 -ORBInitialHost localhost& java client.calc Client -ORBInitialPort 1050 -ORBInitialHost localhost
Output:
Server Output:-
Client Output:-
Conclusion:
Thus, in this assignment, I learned how to use CORBA in Java using IDL and IDLJ for distributed computing systems.
Reviews
There are no reviews yet.