Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remote method invocation. Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are.

Similar presentations


Presentation on theme: "Remote method invocation. Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are."— Presentation transcript:

1 Remote method invocation

2 Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are not distributed programs.

3 Writing RMI services A remote methods are declared explicitly in the interface, RMI interface definition The interface should extend the Remote interface. In order to write a simple RMI application Follow following steps: –Write the Java RMI interface definition for the application with the specified operations. –Implement the interface. – implement the server application, who is responsible for remote object registration. –Design and implement a Client which invokes the server to invoke remote methods, the client should do the following: Locate the remote objects Link to the remote objects

4

5 A simple RMI interface file import java.rmi.*; public interface Interface extends Remote { public int f1(int no) throws java.rmi.RemoteException; public String f2(int sno) throws java.rmi.RemoteException; } //end interface

6 Implementing the interface import java.io.*; import java.util.*; import java.rmi.*; import java.rmi.server.*; import java.lang.*; import java.text.DecimalFormat; public class Implementation extends UnicastRemoteObject implements Interface { private final int recordSize=88; private static byte[] mutex; public Implementation () throws RemoteException { super( ); }

7 Implementing the interface public int f1(int no) throws RemoteException { // do something } public String f2(int no)throws RemoteException { // do something } } // end class

8 Implementing RMI server import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; import java.net.*; import java.io.*; public class Server { public static void main(String args[]) throws Exception { startRegistry(2000); Implementation exportedObj = new Implementation(); String registryURL = "rmi://localhost:2000/App"; Naming.rebind(registryURL, exportedObj); }

9 Writing a RMI client import java.io.*; import java.rmi.*; public class Client { public Client(){ } public static void main(String args[]) { try { String registryURL = "rmi://" + localhost: 2000/App"; // find the remote object and cast it to an interface object Interface h = (Interface)Naming.lookup(registryURL); System.out.println("Lookup completed " ); h.f1(5); // Call remote method }

10 References http://java.sun.com/developer/onlineTraini ng/rmi/RMI.html#IntroRMIhttp://java.sun.com/developer/onlineTraini ng/rmi/RMI.html#IntroRMI http://java.sun.com/docs/books/tutorial/rmi/ overview.htmlhttp://java.sun.com/docs/books/tutorial/rmi/ overview.html http://www.javacoffeebreak.com/articles/ja varmi/javarmi.htmlhttp://www.javacoffeebreak.com/articles/ja varmi/javarmi.html


Download ppt "Remote method invocation. Introduction First introduced in JDK 1.1. Allows distributed Java programs to work with each others by behaving as if they are."

Similar presentations


Ads by Google