Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.

Similar presentations


Presentation on theme: "CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday."— Presentation transcript:

1 CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday

2 Java RMI

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

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

5 Interface Definition l Interface must be public l Extends java.rmi.Remote l 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 l Specifies the remote interface l Defines the constructor l Implements methods l Creates and Installs a security manager l Creates instances of the remote object l 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 l Obtain a reference to the "HelloServer" from the server's registry l Invoke the method on the remote object l 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 l Compile the source files using javac l Generate Stub and Skeleton files » client side and server side proxies » generated using rmic on class files

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

17 Execution l Start the registry on the server » start rmiregistry l Start the server using the java interpreter l Run the applet

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


Download ppt "CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday."

Similar presentations


Ads by Google