Title: Remote Method Invocation
1Remote Method Invocation
RMI CORBA
RMI supports distributed Java-to-Java
interaction. Unlike the RPC mechanism it allows
the transfer of objects as parameters and return
types across a network - RMI provides
- Serialisation and de-serialisation of
objects when passed as parameters or return
types marshalling/unmarshalling of
data. Handles the interaction with the network
layer. In Java 2 it permits the automatic
activation and deactivation of server
objects. It provides location transparency to
the client. Through RMI/IIOP it supports
integration with CORBA.
P. Martin 2001 - 1
2Components of RMI
RMI CORBA
CLIENT
SERVER STUB
SERVER
DBMS
TCP/IP
Thin client e.g. applet
Proxy for remote object
Remote server
DataBase
REMOTE INTERFACE
Steps involved Specify the Remote Servers
Interface definition. Implement the remote
Server. Compile the remote server and use rmic
to generate stub Run rmiregistry and bind
server to it.
P. Martin 2001 - 2
3RMI Example
RMI CORBA
Defining the remote interface -
Implement the interface in the Server class
P. Martin 2001 - 3
4RMI Example - server
RMI CORBA
public static void main(String args)
throws RemoteException
System.setSecurityManager(new RMISecurityManager()
) try Server obj
new Server(args0)
Naming.rebind(/Server, obj)
System.out.println(Server bound in registry)
//end try catch(Exception
e) System.err.println(ServerImpl
error e.getMessage())
e.printStackTrace() //end catch
//end main //end Server
Compile the server and generate the stub Start
the rmiregistry and start the server
P. Martin 2001 - 4
5RMI Example - applet
RMI CORBA
Example client applet
import java.rmi. import java.applet.
import java.awt. import java.awt.event. p
ublic class DBApplet extends Applet
private Button submit new Button("Submit
Query") private TextField sql new
TextField("",50) private TextArea ans
new TextArea() private DBServer obj
public void init() try obj
(DBServer)Naming.lookup("/Server")
this.add(sql)
this.add(submit)
submit.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
try
String s sql.getText()
ans.append(obj.query(s))
//end try
catch(Exception e1)
) //end
addActionListener
this.add(ans) //end try
catch (Exception e) //end init
//end DBApplet
P. Martin 2001 - 5
6Common Object Broker Architecture
RMI CORBA
Standard developed bu the Object Management Group
(OMG). OMG is a consortium of more than 800
companies worldwide. Founded in 1989 Object
management defined as software development that
models the real-world in terms of
objects. Established the CORBA middleware
standard and other related standards.
P. Martin 2001 - 6
7CORBA components
RMI CORBA
IDL compiler
Interface repository
Implementation repository
in args
CLIENT
OBJECT(servant)
operation()
Obj ref
out args return val
DSI
IDL skeleton
DII
ORB interface
IDL stubs
Object Adapter
ORB CORE
GIOP/IIOP
ORB specific Interface
Standard Interface
Standard language Mapping
Standard Protocol
P. Martin 2001 - 7
8Interface Definition Language
RMI CORBA
- PRIMITIVE
- Integer
- short, long,
- signed unsigned
- Floating point
- float, double, long double, fixed
- char, wchar, boolean, octet
- Any
- CORBA Object Reference
- CONSTRUCTED
- Structs
- Unions
- Enums
- Sequences
- Strings, wstrings
- Arrays
P. Martin 2001 - 8
9IDL (cont)
RMI CORBA
Modules are collections of related interface
definitions (like Java packages). Operations
have return types and in and out
parameters. Attributes can be defined (and
automatically have set and get methods unless
they are designated read only).
P. Martin 2001 - 9
10Object references
RMI CORBA
Object references (which are portable across
systems) can be obtained - As a stringified
reference convertible into a true object
reference. By reference to the CORBA Naming
Service (white pages). Using the Trader Service
(Yellow pages). Once an object reference is
obtained, it can be used to invoke
interface operations either - In the usual way
(static interface - defined at compile time) By
reference to the Interface Repository at run-time
(dynamic interface invocation - DII).
P. Martin 2001 - 10
11Dynamic Interface Invocation
RMI CORBA
Invoking the dynamic interface is done as follows
- Step 1 Obtain method description from the
interface repository lookup_name() describe(
) Step 2 Create argument list and add
arguments create_list() add_arg()
add_arg() add_arg() Step 3 Create
request create_request(object_ref,
method_name, argument_list) Step 4
Invoke remote method in one of three ways
invoke() normal blocking request/response
send() send request and later, getresponse()
get response send() one way send, no
response
P. Martin 2001 - 11
12Method Invocation
RMI CORBA
CORBA provides five different message protocols
- Synchronous Normal request/reply (line
RPC). Deferred synchronous After request,
client continues and can pick up response
later. One-way Request with no reply (like
UDP). Asynchronous Server does not need to be
ready when call is made. Time-independent Se
rver is automatically activated if
not running. CORBA also allows users to
define quality of service - in terms of
message delivery, queuing and priority.
P. Martin 2001 -12
13Communication Protocols
RMI CORBA
GIOP (general inter-orb protocol) - Provides a
set of message formats and a common data
representation language for communication
between ORBs. The Internet Inter-Orb protocol
(IIOP) specifies how GIOP messages are exchanged
over TCP/IP. GIOP provides - Reliable,
connection-oriented communication. Can be
viewed as a byte stream. Notification of
connection loss.
P. Martin 2001 - 13
14Counter example
RMI CORBA
The IDL Interface
The interface count has a single method called
increment which increments by one the value of a
variable sum which is returned to the client. sum
is defined to be a CORBA read/write attribute.
Clients can use built-in set and get CORBA
accesssor functions. A module is the equivalent
of a package in Java and provides a naming
context for a set of related interfaces.
// File Count.idl module Counter
interface Count attribute long sum
long increment()
P. Martin 2001 - 14
15Counter - CountImpl
RMI CORBA
// File CountImpl.java public class
CountImpl extends Counter._CountImplBase
private int sum public CountImpl(String
name) super(name)
System.out.println("Count Object Created")
sum 0 //end CountImpl
This is the implementation of the count IDL
interface. This server implementation class
inherits (extends) _xxxxImplBase class the
skeleton generated by the IDL compiler. Another
way to associate it with the skeleton is by
delegation (the Tie method).
public int sum() return sum
//end sum - gets sum public void
sum(int val) sum val //end
sum - set sum public int increment()
sum return sum //end
increment //end class CounterImpl
The constructor calls is super class which in
this case is the skeleton to create a named
implementation object. This means that each
named instance of CountImpl will have a
persistent name. If super is called without and
argument then a transient object will be created.
P. Martin 2001 - 15
16Counter - messaging
RMI CORBA
ORB
CountImpl
CountServer
BOA
ORB.init
BOA_init
new
Obj_is_ready
impl_is_ready
P. Martin 2001 - 16
17Counter count server
RMI CORBA
// CountServer.java The Count Server main
program public class CountServer static
public void main(String args) try
// Initialize the ORB
org.omg.CORBA.ORB orb org.omg.CORBA.ORB.init(arg
s, null) // Initialize the
BOA ( in future calls will be to the POA )
org.omg.CORBA.BOA boa
orb.BOA_init() // Create
the Count object CountImpl
count new CountImpl("My Count")
// Export to the ORB the newly created
object boa.obj_is_ready(count
) // Ready to service
requests boa.impl_is_ready()
//end try
catch(org.omg.CORBA.SystemException e)
System.err.println(e)
//end catch //end main //end class
CountServer
P. Martin 2001 - 17
18Counter - messaging
RMI CORBA
Client
Count proxy
ORB
CountHelper
CountImpl
Orb.init
bind
Sum(0)
Sum(0)
increment
increment
P. Martin 2001 - 18
19Counter - client
RMI CORBA
// CountClient.java Static Client, VisiBroker
for Java public class CountClient
public static void main(String args)
try // Initialize the ORB
System.out.println("Initializing the
ORB")
org.omg.CORBA.ORB orb org.omg.CORBA.ORB.init(arg
s, null) // Bind to
the Count Object
System.out.println("Binding to Count Object")
Counter.Count counter
Counter.CountHelper.bind(orb, "My Count")
// Set sum to initial value of
0 System.out.println("Se
tting sum to 0")
counter.sum((int)0) //
Time 1000 iterations
long startTime System.currentTimeMillis()
System.out.println("Increment
ing") for (int i 0
i lt 1000 i )
counter.increment()
//end for long
stopTime System.currentTimeMillis()
System.out.println("Avg Ping "
((stopTime - startTime)/1000f) " msecs")
System.out.println("Sum "
counter.sum()) //end try
catch(org.omg.CORBA.SystemException e)
//end main //end CountClient
P. Martin 2001 - 19
20Counter - schematic
RMI CORBA
CountClient
javac -d CountClient.java
CountClient.java
count.idl
idl2java count.idl
CountImpl.java
CountServer
javac -d CountImpl.java javac -d CountServer.java
CountServer.java
P. Martin 2001 - 20
21Counter - components
RMI CORBA
_CountImplBase Class implements server side
skeleton Count - maps Count interface to
corresponding Java Interface -example_Count
an example class for the Count object
implementation _st_Count client stub
class CountHelper class that provides useful
helper functions CountHolder class that handles
OUT INOUT parameters
P. Martin 2001 - 21
22Counter support classes
RMI CORBA
associated ltgtHelper class Narrow method
allows clients to cast object references class
non-standard bind method any insertion/extraction
get repository ID get typecode associated
ltgtHolder class supports stream for portable
stubs skeletons enable out and inout parameters
P. Martin 2001 - 22
23Counter - interface
RMI CORBA
IDL Declaration to show parameter
passing interface example1 long op1 ( in
long arg1, out long arg2, inout long
arg3) produces the following Java public
interface example1 public int op1(int
arg1,IntHolder arg2,IntHolder arg3) //end
interface
P. Martin 2001 - 23
24Counter - parameters
RMI CORBA
The IN parameter is passed from client to server
and it is expected that the server will not
modify it. Pass by value semantics. The OUT
parameter is passed from server to client which
will be available to the client to modify. Pass
by reference semantics. The INOUT parameter is
passed from the client to the server. The server
modifies the parameter which is then available to
the client. Pass by reference semantics. A
request may also return a single return value.
Pass by value semantics. There can be any number
of IN, OUT, INOUT parameters.
P. Martin 2001 - 24