Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA
Cli/Serv.: rmiCORBA/ RMI Overview 1.1What is RMI? 1.2A Typical RMI Application 1.3.Server-side Features 1.4. Client-side Features 1.5.Advantages 1.6.Disadvantages 1.7.More Details on RMI
Cli/Serv.: rmiCORBA/133 v RMI == Remote Method Invocation –allows a Java object to call a method of a Java object running on another machine –RMI is a modern version of RPC for communication between Java objects 1.1. What is RMI ?
Cli/Serv.: rmiCORBA/ A Typical RMI Application rmiregistry client server remote objects lookup remote reference 2 store (rebind) remote references 1 invoke method via the remote stub 4 remote stub
Cli/Serv.: rmiCORBA/ Server-side Features v The server: –creates remote objects (objects that will be accessible by clients) u the server is sometimes called a server factory –places remote references (names) for the objects in the –places remote references (names) for the objects in the rmiregistry u they can then be accessed by clients continued
Cli/Serv.: rmiCORBA/136 v A remote object is made from a remote interface and a separate implementation class. v A remote interface is a set of method prototypes –a method prototype is the name of the method and the types of its input arguments and return type continued remote interface impl.
Cli/Serv.: rmiCORBA/137 Example Remote Interface import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { String sayHello() throws RemoteException; } The remote object will have this interface
Cli/Serv.: rmiCORBA/ Client-side Features The client gets a reference to a server's remote object by querying the rmiregistry. v At the programming level, this reference appears to be the remote object –in fact it refers to a remote stub which is downloaded invisibly from the rmiregistry
Cli/Serv.: rmiCORBA/139 v The remote stub is an ordinary Java class –its purpose is to handle the low-level communication between the client and the remote object on the server-side. v Object data is passed between the client and server using a standard feature of Java called object serialization.
Cli/Serv.: rmiCORBA/1310 Diagram of Communication client remote object hi.sayHello() is really... remote stub 1. serialize the call 2. stream of bytes server 3. call 4. result 5. stream of bytes 6. result
Cli/Serv.: rmiCORBA/ Advantages v Dynamic code loading –a client does not need to contain any communication code when written -- that is downloaded when the remote stub is retrieved –a client can dynamically download other classes u e.g. those used by the remote stub –the server can also download code from the client continued
Cli/Serv.: rmiCORBA/1312 v The programmer doesn't write any communication code –the remote stub is generated automatically by passing the remote interface to the RMI compiler ( rmic )
Cli/Serv.: rmiCORBA/ Disadvantages v Not easy to integrate RMI Java code with legacy applications in other languages (e.g. C, C++).
Cli/Serv.: rmiCORBA/ More Details on RMI v The Java RMI tutorial v A starting point for RMI information:
Cli/Serv.: rmiCORBA/ CORBA Overview 2.1. What is CORBA? 2.2. Important CORBA Features 2.3. Why use CORBA? 2.4. CORBA/Java Advantages 2.5. A CORBA Application 2.6. Other CORBA Coding Styles 2.7. Comparisons with Other Approaches 2.8. More Details on CORBA
Cli/Serv.: rmiCORBA/ What is CORBA? v The Common Object Request Broker Architecture (CORBA) –a specification, not an implementation v The Object Management Group’s (OMG) aim: –specify a distributed computing environment within an object-oriented framework u i.e. using objects, methods, message passing, etc.
Cli/Serv.: rmiCORBA/1317 Using CORBA (simple view) Client object ORB call a method in an object managed by the server by using an object reference network Server ORB method call & result objects managed by the server
Cli/Serv.: rmiCORBA/1318 ORBs v An Object Request Broker (ORB) implements the features specified by CORBA. v An ORB can be coded in any language –so long as it supports CORBA’s functionality v ORBs communicate using the Internet Inter- ORB Protocol (IIOP) –an extension of TCP
Cli/Serv.: rmiCORBA/1319 Major ORB Components Dynamic Invocation IDL Stubs ORB Interface IDL Skeleton Object Adapter ORB Core ClientObject Implementation
Cli/Serv.: rmiCORBA/1320 Using CORBA (more detail) Client IDL client stub ORB interface ORB internals ORB interface ORB internals Server IDL server skeleton Network
Cli/Serv.: rmiCORBA/1321 v IDL: Interface Definition Language –for defining OO data and methods The J2SE idltojava compiler generates client stubs and server skeletons for work with any CORBA ORB. v J2SE includes a simple (free) ORB. (Java) IDL
Cli/Serv.: rmiCORBA/1322 IDL Examples module HelloApp { interface Hello { string sayHello(); }; }; continued
Cli/Serv.: rmiCORBA/1323 module Appliance { interface TV { readonly attribute string SerialNo; attribute short Vol; attribute short Channel; void operate(); }; interface WebTV : TV { void surfTo(in URL url); }; };
Cli/Serv.: rmiCORBA/ Important CORBA Features v An object’s interface (service) is completely separated from its implementation. v An object’s location is completely hidden. Consequently, CORBA provides: –a naming service(white pages) –a trading service(yellow pages) –an interface Repository (IR) continued
Cli/Serv.: rmiCORBA/1325 v Object communication is greatly simplified: –messages, written in IDL v An object can find other objects at run-time by using the Dynamic Invocation Interface (DII): –but the usual approach is to already know the location of the other object continued
Cli/Serv.: rmiCORBA/1326 v Objects can be built more easily by using pre-existing CORBA services for: –message encoding, object locating, security, etc. v Advanced services: –persistent objects, transactions, concurrency control, etc. continued
Cli/Serv.: rmiCORBA/1327 v CORBA facilities: –horizontal and vertical application frameworks –e.g. printing, mobile agents v Convert legacy code in Basic, C, etc. into objects –uses CORBA object adaptors
Cli/Serv.: rmiCORBA/ Why Use CORBA? v It provides a powerful OO mechanism for defining the interfaces between distributed objects. v It offers many services and facilities. v Platform/language independent. v An open standard: –ensures its continued innovation and evolution
Cli/Serv.: rmiCORBA/ CORBA/Java Advantages v CORBA’s advantages for Java: –CORBA supports object method calling from anywhere –CORBA allows Java to work with objects coded in other (non-OO) languages –CORBA augments Java’s networking features u e.g. it encourages multi-host applications continued
Cli/Serv.: rmiCORBA/1330 v Java’s advantages for CORBA –Java’s OO features match those in CORBA u e.g. separation of interface (service) and impl. –Java has many useful features for implementing CORBA services and facilities: u multi-threading, exceptions, GUI, packages, automatic garbage collection
Cli/Serv.: rmiCORBA/ A CORBA Application v 1. Write an IDL interface for the remote objects managed by the server. v 2.Compile the IDL interface –it generates a Java version of the interface –it generates stub and skeleton code for the client and server continued
Cli/Serv.: rmiCORBA/1332 v 3. Write the server, which has two parts –the server (factory) u it creates remote objects –the remote object implementation (of the IDL interface) v 4. Implement the client –it contacts and uses a remote object
Cli/Serv.: rmiCORBA/1333 Running the Application tnameserv client server factory remote objects lookup remote reference to an object 2 store (rebind) remote references for objects 1 invoke method via the remote reference and stub 4 ORBORB O R B network 3 remote stub
Cli/Serv.: rmiCORBA/1334 Using a Remote Object Client (object) object ref server object method invocation continued Client object ref server object execution 4
Cli/Serv.: rmiCORBA/1335 Client object ref server object return method result Client object ref server object garbage collect
Cli/Serv.: rmiCORBA/1336 Client Callback Client object ref B method invocation object A Server object B object ref A continued 4
Cli/Serv.: rmiCORBA/1337 Client object ref B method invocation (callback) object A Server object B object ref A
Cli/Serv.: rmiCORBA/ Other CORBA Coding Styles Single-threaded server Multi-threaded server Being a client and a server Blocking vs. one-way Pass by reference vs. pass by value
Cli/Serv.: rmiCORBA/ Single-threaded Server client 1 server client 2 method call result suspended busy method call call proceeds busy suspended result wait
Cli/Serv.: rmiCORBA/ Multi-threaded Server client 1 server client 2 method call result suspended method call suspended result thread exits thread exits
Cli/Serv.: rmiCORBA/1341 Object Factory Pattern client 1 server client 2 request object result return ref object method call object method call request object return ref
Cli/Serv.: rmiCORBA/ Being a Client and a Server Client B Client/ Server C Server D Server E Client A continued
Cli/Serv.: rmiCORBA/1343 v Usually, a client can be single-threaded, and a server should be multi-threaded. v In mixed-mode, the client may need to be multi-threaded to handle its server role.
Cli/Serv.: rmiCORBA/1344 A Mixed-mode single-threaded Problem client/ server 1 method call client/ server 2 suspended X deadlock waits forever
Cli/Serv.: rmiCORBA/1345 Multi-threaded Solution method call suspended result thread exits client/ server 1 client/ server 2 method call result thread exits
Cli/Serv.: rmiCORBA/ Blocking vs. One-way client server method call result suspended busy Blocking processing resumes
Cli/Serv.: rmiCORBA/1347 client server oneway method call busy one-way processing continues method call finishes v Problem: the client has no way of knowing if the method call has succeeded.
Cli/Serv.: rmiCORBA/ Pass by Reference vs. Value client server request object result return ref object method call Pass an object by reference.
Cli/Serv.: rmiCORBA/1349 client server request object return copy of object Pass an object by value. create object continued
Cli/Serv.: rmiCORBA/1350 v If a client invokes many methods in an object, it may be better, in terms of efficiency, to copy it to the client.
Cli/Serv.: rmiCORBA/ More Details on CORBA v Beginners Java and CORBA tutorial: onlineTraining/corba/corba.html v More technical Java & CORBA tutorial: guide/idl/ v OMG Site: continued
Cli/Serv.: rmiCORBA/1352 v Java Programming with CORBA Gerald Brose and others John Wiley, 2001, 3rd ed. Books.html#Network