1 / 18

CS 584 Lecture 18

CS 584 Lecture 18. Assignment Glenda assignment extended to the Java RMI Deadline No Java RMI Assignment Test Friday, Saturday, Monday. Java RMI. RMI Programming Steps. Coding the source files Compilation and Deployment Running. Coding the Source Files.

barbra
Download Presentation

CS 584 Lecture 18

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. CS 584 Lecture 18 • Assignment • Glenda assignment extended to the Java RMI Deadline • No Java RMI Assignment • Test • Friday, Saturday, Monday

  2. Java RMI

  3. RMI Programming Steps • Coding the source files • Compilation and Deployment • Running

  4. Coding the Source Files • There are at least 3 source files • Interface definition • Server Implementation • Client Implementation • HTML file if applet

  5. Interface Definition • Interface must be public • Extends java.rmi.Remote • Must declare java.rmi.RemoteException in throws clause

  6. Interface Definition Example package examples.hello public interface Hello extends java.rmi.Remote { String sayHello() throws java.rmi.RemoteException; }

  7. Server Implementation • Specifies the remote interface • Defines the constructor • Implements methods • Creates and Installs a security manager • Creates instances of the remote object • Registers the remote object with the RMI remote object registry

  8. Server Implementation package examples.hello import java.rmi.*; import java.rmi.server.UnicastRemoteObject public class HelloImpl extends UnicastRemoteObject implements Hello { private String name;

  9. Server Implementation public HelloImpl(String s) throws RemoteException { super(); name = s; } public String sayHello() throws RemoteException { return "Hello World"; }

  10. Server Implementation public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try { HelloImpl obj = new HelloImpl("HelloServer"); Naming.rebind("//myhost/HelloServer", obj); System.out.println("Hello Server bound"); catch(Exception e) { System.out.println("Err: " + e.getMessage); e.printStackTrace(); } }

  11. Client Implementation • Obtain a reference to the "HelloServer" from the server's registry • Invoke the method on the remote object • Use the returned results

  12. Client Implementation package examples.hello import java.awt.*; import java.rmi.*; public class HelloApplet extends java.applet.Applet { String message = " ";

  13. Client Implementation public void init() { try { Hello obj = (Hello)Naming.lookup("//" + getCodeBase().getHost() + "/HelloServer"); message = obj.sayHello(); } catch (Exception e) { System.out.println("Err: " + e.getMessage); e.printStackTrace(); } }

  14. Client Implementation public void paint(Graphics g) { g.drawString(message, 25,50); }

  15. Compilation • Compile the source files using javac • Generate Stub and Skeleton files • client side and server side proxies • generated using rmic on class files

  16. Deployment • RMI is based on packages • RMI objects need to be in a visible place

  17. Execution • Start the registry on the server • start rmiregistry • Start the server using the java interpreter • Run the applet

  18. For More Information • See Sun's website for a tutorial • web3.javasoft.com:80/products/jdk/1.1/docs/guide/rmi/getstart.doc.html • Remember the test!!!!!

More Related