Professional Documents
Culture Documents
Technologies
Mettu University, Department of Information
Technology
4th Year
Chapter 2 – Inter system Communication
Prepared by: Sridhar.U
RMI
(Remote Method Invocation)
Introduction
In the traditional client/server model, the client
translates the request to an intermediary transmission
format and sends the request to the server. The server
parses the request format, computes the response and
formats the response for transmission to the client. The
client then parses the response and displays it to the
user.
Skeleton
Stub Server
“Fred”
“Fred”
Skeleton
Stub Server
3 4
“Fred”
“Fred”
or java.rmi.UnicastRemoteObject
Remote Interface Example
import java.rmi.*;
public interface Adder extends Remote
{
public int add(int x, int y)
throws RemoteException;
}
Remote Class Example
import java.rmi.*;
import java.rmi.server.*;
public class AdderImpl extends UnicastRemoteObject
implements Adder
{
public AdderImpl() throws RemoteException
{
}
public int add(int x, int y)
throws RemoteException
{
return x + y;
}
}
Compiling Remote Classes (Diagram)
AdderImpl_Stub.class
(stub classfile)
Create the server
Creates a new instance of the remote object
That’s it
RMI Server Example
try {
AdderImpl adder = new AdderImpl();
Naming.rebind("adder", adder);
System.out.println("Adder bound");
}
catch (RemoteException re) {
re.printStackTrace();
}
catch (MalformedURLException me) {
me.printStackTrace();
}
Creating an RMI Client
Find a registry
use java.rmi.Naming
rmi://host[:port]/name
default port is 1099
name only
System.setSecurityManager(
new RMISecurityManager());
Adder a
=(Adder)Naming.lookup("adder");
Very similar
remote interfaces ~ type libraries
COM is Win32-only (for now)
What Is RMI in Simple?
Access to Remote Objects
Java-to-Java only
Client-Server Protocol
High-level API
Transparent
Lightweight
Introduction
What is CORBA?
– CORBA, or Common Object Request Broker Architecture,
is a standard architecture for distributed object
systems. It allows a distributed, heterogeneous
collection of objects to interoperate.
The OMG ?
– The Object Management Group (OMG) is responsible for
defining CORBA. The OMG comprises over 800 companies
and organizations, including almost all the major
vendors and developers of distributed object
technology, including platform, database, and
application vendors as well as software tool and
corporate developers.
Introduction Cont..
– OMG operates as a non-profit organization aiming at
the standardization of “whatever it takes” to
achieve interoperability on all levels of an open
market for “objects”.
– Initially OMG concentrated in solving one
fundamental problem
1. C++ C++
Windows Windows
2. C++ C++
Windows Linux
3. C++ Java
Windows Linux
Introduction Cont..
– CORBA products can’t interoperate on an efficient
binary levels.
Invocation
ORB Interface ORB Interface Object Adapter
Interface
CORBA ARCHITECTURE
Set of Invocation Interface
It enables various degrees of late biding. They also
marshals an invocation arguments.
ORB
Can locate the receiver object and the invoked
method and transport the arguments.
Object Adapter
Unmarshalls the arguments and invokes the requested
method on the receiver object.
CORBA ARCHITECTURE
OMG IDL
For invocation interface and object adapters for
work, two essential requirements need to be met
1. All object interface need to be described in a
common language.
It enables construction of marshals and
un marshals
IDL Source
Application Server
IDL Compiler
Programs Programs
Dynamic Dynamic
ORB IDL Skeletons Skeleton Object
Invocation IDL Stubs interface Adapter
Interface Interface
Object Request Broker (ORB)
CREATING CORBA IDL FILES
Contents
The CORBA Interface Definition Language (IDL)
Declaring data members, methods, and parameters
The interface compiler
Separating client and server on different machines
CORBA IDL
module Calc{
interface Calculator {
float calculate(in float val1, in
float val2, in char operator);
}
}
This is an interface for a Calculator with one method – calculate.
A module can have many interfaces.
Mapping IDL to Java, C++
IDL Java C++
module Calc{
interface Calculator{
//User-defined exception
exception MyException{};
//synchronous method
float calculate(in float val1, in float val2, in char
operator) raises (MyException);
//asynchronous method
oneway void set_value(in long val);
};
};
More on Exceptions
Every ORB comes with one or more IDL compilers, one for
each language that it supports.
Many vendors supply their IDL compilers. Because the
compilers implement mapping standards, every vendor's
IDL compiler produces language code with the same
mappings, making the code vendor independent.
Sun’s JDK provides the idlj compiler.
VisiBroker provides idl2cpp and idl2java compilers.
Need for Interface Compiler
The interface compiler converts the language independent
IDL to language specific code that C++, Java or other
language clients and servers can understand.
For example, the idlj compiler compiles the IDL to Java
code.
IDL allows an object implementer to choose the
appropriate programming language for the object. Client
and server can be developed in parallel.
Clients depend only on the interface and not the
implementation of the server code.
The idlj compiler
To compile the IDL to java using idlj,
idlj -fall <idl_file_name>
The –fall option creates both server and client files.
-fclient generates client files only (default).
–fserver generates server files only.
Files created by idlj
The following classes are created when Calc.idl is compiled using
idlj
Calc.Calculator - The IDL interface represented as a Java
interface
Calc.CalculatorHelper - Implements the type operations for the
interface
Calc.CalculatorHolder - Used for out and inout parameters
Calc.CalculatorOperations – The interface that defines the
exposed remote methods.
Calc._CalculatorStub - The client stub. Implements a local
object representing the remote CORBA object. This object
forwards all requests to the remote object. The client does not
use this class directly.
Calc._CalculatorImplBase - An abstract class that implements
the Calculator interface. It is the server skeleton.
Separating client and server
Client Server
_CalculatorStub _CalculatorImplBase
Calculator Calculator
CalculatorHelper CalculatorOperations
CalculatorHolder
CalculatorOperations
THANK YOU