1 / 22

W. H. CARLISLE AUBURN UNIVERSITY COMPUTER SCIENCE AND ENGINEERING

W. H. CARLISLE AUBURN UNIVERSITY COMPUTER SCIENCE AND ENGINEERING. Remote Method Invocation (RMI). RMI is a powerful technology for developing distributed applications without worrying about the networking details A server defines the objects that clients can use

bob
Download Presentation

W. H. CARLISLE AUBURN UNIVERSITY COMPUTER SCIENCE AND ENGINEERING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. W. H. CARLISLE AUBURN UNIVERSITY COMPUTER SCIENCE AND ENGINEERING

  2. Remote Method Invocation (RMI) RMI is a powerful technology for developing distributed applications without worrying about the networking details A server defines the objects that clients can use Client invoke methods of a remote object exactly as if they were a part of the client program.

  3. Client/Server model • Client/Server Architecture is a two tier model • presentation (client) • processing/storage (server) • insufficient to support RMI

  4. Three Tier Model • Three software tiers support RMI • presentation (client) • processing/storage (server) • object resource broker (middle tier)

  5. Sun success built on RPC • Three software tiers support RPC • presentation (client) - makes procedure calls • processing/storage (server) - implements the call • broker (middle tier) - understands which procedures • are served by which servers.

  6. Migrate RPC intoObject World Remote objects already existed for C++ with the CORBA consortium (Common Object Resource Broker Architecture) Natural to include an RMI capability in Java. PROBLEM: politics - Sun was member of CORBA consortium and RMI was not CORBA compliant usefulness - with a CORBA design, C++ clients could use Java Objects

  7. Migrate RPC intoObject World PROBLEMS Continued: performance - Early studies showed CORBA outperformed RMI.

  8. Is RMI Dead? With Java 1.2 Sun Microsystems introduced a CORBA compliant Object Resource Broker (ORB) into the toolkit. However Sun lags behind Visigenic (Borland) and other third party companies in the CORBA Java/C++ distributed platform. (I mention Visigenic only because Netscape makes their ORB a part of their package).

  9. Is CORBA Dead? Once upon a time there was a giant who sat at a table and after eating would regurgitate some food for others around the table. “This is not good food”, most said, but others pointed out that “the regurgitated food was not poisoned because it did not kill the giant”. Occasionally there would be food at the far end of the table that the giant was not eating. Some would try it, find it good, and this would begin a rush to eat this food. Unfortunately the giant would notice, reach over and begin consuming this food. This would again leave nothing very good for those crowding the table.

  10. BUT Languages or tool-sets aside: Total agreement that distributed object computing is the next wave to ride.

  11. Distributed Object Computing • uses objects on different machines • allows callbacks from servers to applets • makes writing of reliable distributed applications simple • above are transparent to the client.

  12. Important With RMI the client/server terminology applies only to a single message to an object. The computer running the Java code that sends a message to a remote object may be the server to a Java program on another machine.

  13. Developing an RMI application A local surrogate (stub) object manages invocation of a remote object. Whereas CORBA presumes a heterogeneous multi-language environment and has a language neutral object model, RMI can assume the homogeneous environment of the JVM on client and server. Thus a single Java interface class can serve as a definition of the object to be exported and can be used to generate the stub for the remote object.

  14. Step 1: Create the Interface • Create an interface class that extends java.rmi.Remote • import java.rmi.*; • public interface Intf extends Remote { • public String hello() throws RemoteException; • } • Compile the interface

  15. Step 2: Implement the Interface • Programmer writes a class that extends java.rmi.servr.UnicastRemoteObject and implements the interface. • import java.rmi.*; • import java.rmi.server.UnicastRemoteObject; • public class Server extends UnicastRemoteObject implements Intf { • public Server() throws RemoteException { super() }; //constructor • synchronized public String hello() throws RemoteException { return “Hello”; } //implements interface

  16. Step 2: continued • The main creates an instance and records it with the middleware naming service. • public static void main(String args[]) { try { Server v = new Server(); //create the object; Naming.rebind( ”//church.eng.auburn.edu/HelloServer",v); } catch(Exception e) { System.out.println("Server: "+ e.getMessage()); e.printStackTrace(); } } }

  17. Step 3: Generate client stub • The utility rmic is used to generate a stub for the client and the skeleton code used by the remote object. • When the client sends a message to an object, it is a method of the stub that is called. The stub does the necessary networking to pass the call to the skeleton on the client side. • The skeleton translates the request to a method invocation on the servers object, gets the result and passes it back to the stub on the skeleton side. • The stub returns this information to the client.

  18. Step 3: Continued • rmic Servercreates and compiles two new classes with suffixes _Stub and _Skel • Currently, the server machine must run a program that listens to a port and knows about the services offered. • Start this registry server with the rmiregistry command. • Now you can run the Server program and your machine is offering the object for clients to use.

  19. Step 4: Writing a Client. • The client program defines a variable of the interface and then uses the naming service to get an instance of the object from the server. (Really an instance of the stub) • public class Client { static public void main(String arg[]) { try { Intf object = (Intf)Naming.lookup( “//church.eng.auburn.edu/HelloServer”); • System.out.println(object.hello()); • } catch (Exception e) { System.out.println(e.message()); e.printStackTrace();} }}

  20. Intf.java import java.rmi.*; public interface Intf extends Remote { public String hello() throws RemoteException; }

  21. Server.java import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class Server extends UnicastRemoteObject implements Intf { public Server() throws RemoteException { super();} synchronized public String hello() throws RemoteException {return "Hello"; } public static void main(String args[]) { try { Server v = new Server(); //create the object; Naming.rebind( "//church.eng.auburn.edu/HelloServer",v); } catch(Exception e) { System.out.println("Server: "+ e.getMessage()); e.printStackTrace(); }}}

  22. Client.java import java.rmi.*; public class Client { static public void main(String arg[]) { try { Intf s = (Intf)Naming.lookup( "//church.eng.auburn.edu/HelloServer"); System.out.println( s.hello()); } catch(Exception e){ System.out.println(e.getMessage()); e.printStackTrace();} }}

More Related