Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remote Method Invocation Internet Computing Workshop Lecture 17.

Similar presentations


Presentation on theme: "Remote Method Invocation Internet Computing Workshop Lecture 17."— Presentation transcript:

1 Remote Method Invocation Internet Computing Workshop Lecture 17

2 Remote Method Invocation ● So far we have look at sending messages across a network. ● Remote Method Invocation (RMI) gives you access to objects that are implemented at a remote location. ● It's distributed programming in a fully object- oriented Java style.

3 Advantages of RMI ● You can program in a purely object-orientated style. ● Once it's set up you don't need to worry about handling remote access. ● No need to design a protocol for your system. ●

4 Disadvantages of RMI ● Needs additional configurations: ● Object registry ● Complied with rmic ● Hard to tell which objects are local and which are remote.

5 Remote Objects ● In RMI the client has access to an object that is implemented remotely. ● Fields of the object are stored remotely ● Remote data storage. ● Methods of the object are executed remotely ● Remote processing.

6 Communication Model ● With sockets: client and server communicate directly, exchanging messages. ● With RMI, a Registry lists all objects offered by the server. ● The server binds objects that the client can use. Server Client Registry Bind Object X X X?

7 Communication Model ● The client asks the registry for the object. ● This connects the object X to a stub. ● The client use the stub as if it was the object. Server Client Registry Bind Object X Give me X X Stub for X X?

8 Communication Model ● The client treats the stub like the real object. ● All methods called on the stub are forward to the server. ● The result is then returned to the client. Server Client Registry X Stub Method call Resul t

9 The Registry ● You must start the a registry running. ● e.g. type “ rmiregistry ” from the command line ● ● Usually runs on port 1099, but can run on any port and even on the same machine as the server. ● Interact with registry using the java.rmi.Naming class

10 Interface for the Object ● Both the client and the server must have access to an interface for the remote object. ● This interface must extend the java.rmi.Remote class. ● The methods may throw java.rmi.RemoteException

11 java.rmi.Naming bind(String name, Remote obj) – Adds the object “obj” to the registry under the name “name”. lookup (String name) – Returns a stub for the object called “name” unbind(String name) – Removes the object “name” from the registry list(String name) – Returns a list of all objects in the registry rebind (String name, Remote obj) – = unbind(name);bind(name,obj)

12 Registry URLs ● Services in registries can be addressed directly using a URL of the form: ● rmi:// [: ]/ rmi://localhost/printObject or rmi://68.45.12.7:30099/process These are used with the Naming.lookup method: Naming.lookup(rmi://68.45.12.7:30099/process) which returns the remote object called “process”

13 java.rmi.registry.LocateRegistry ● You can also refer to a Registry my creating a Registry object using the LocateRegistry package. ● LocateRegistry.getRegistry(h,p) return an reference to the registry runing on host h and on port p ● Registry registry = LocateRegistry.getRegistry(host); Ro o = (Ro)registry.lookup("service"); ● Is the same as: ● Ro o = (Ro)Naming.lookup("rmi://host/serv");

14 Communication Model Registry Implement s Client Gets Objec t Generate using rmic Calc Interface Calc Inpl Calc stub Calc Client Calc Server Bind s Client uses Stub Stub forwards Calls to remote stub

15 Running Code Example See handout

16 Distributing the Code ● Both the client and the server need the interface class. ● Client does not need the implementation ● Client does need the stub, but can fetch this dynamically, using the java.rmi.server.codebase ● java Calc -Djava.rmi.server.codebase=URLofStub

17 Communication Model Registry Stub and impl communicate Calc Interface Calc Impl Calc stub Calc Client Calc Server binds object Calc Interface Clien t Public Host Calc stub Server places stub on public host Client gets object

18 Method Arguments and RMI ● To keep things easy you should sending primitive data types as arguments and return values. ● You can send Objects that are “serializable” ● Make your own object serializable by extending the java.io.serializable class. ● The remote object is a new object: a copy of the one you sent.

19 CORBA vs RMI ● Common Object Request Broker Architecture (CORBA) is like RMI but not just in Java. ● Only primitive data types can be passed in CORBA. ● CORBA is very useful when new Java code is combined with legacy systems.

20 CORBA vs RMI ● CORBA uses a “Object Request Broker” (ORB), rather than a rmi registory. ● Interfaces in CORBA are written in Interface Definition Language (IDL). ● You then generate the Java Interface using “ildj”.

21 CORBA vs RMI ● “ildj” generates all the files you need. ● Use the “org.omg.CORBA.*” to distribution and access the object. ● Use CORBA for inter-language working. ● Or for legacy Systems ● Otherwise use RMI.

22 Summary ● RMI gives you access to objects that are implemented at a remote location. ● It's distributed programming in a fully object- oriented Java style. ● It needs addition configurations (registry,rmic) ● Hard to tell which objects are local and which remote.

23 For More Information ● For more on RMI see: http://java.sun.com/docs/books/tutorial/rmi/ ● For more on CORBA see: http://java.sun.com/developer/onlineTraining/corba

24 Next Week: ● Guest Lecture by Andrew Watson from the Object Management Group (OMG). ● The API and standards you have learn in this module are developed and maintained by computer professionals and academics. ● It's quite possible that you will be involved in developing some future standards. ● Andrew Watson will tell you how this is done.


Download ppt "Remote Method Invocation Internet Computing Workshop Lecture 17."

Similar presentations


Ads by Google