Remote Procedure Calls RPC Motivation Development of NFS


















- Slides: 18
Remote Procedure Calls (RPC) • Motivation: Development of NFS (SUN) • A client can call a function in an application running on a server just like if it is locally implemented. • Sends the parameters and receives the results in a correct format(Integer, String, float. . . ) • e. Xternal Data Representation • Serialization.
Remote Procedure Calls • The client stops the execution until the results are received. RPC Client RPC Server Call(parameters) Receive results Server framework: provided by the middleware
The Interface file • Specifies the protocol of the remote function: name, required parameters (how many, and what type), result (type) • It is called “interface” file because server and the client get the needed information. RPC Client Interface definition file The client uses the interface to compile RPC Server The server implements it
Remote Objects • As the object orientation paradigm developed the “remote object” approach replaced the previous paradigm. • An Application call a method of an object located on another JVM. • The interface file is the key concept of the implementation. Invokes the method Gets the result Remote. Object. Server
Necessary files interface Defines the methods (just the header) that could be remotely invoked. Use for compilation • • • Gets a reference to the remote object. Use the method and, Receives the results as if it is locally located. Client program Implements • • • Defines a particular class to implement the methods specified in the interface Creates the remote object from this class. It is published in some registry service, to be located by the clients. Server program
Example: Remote Date Server • The only method of the object will be get. Date(), this method will return as a result the date of the computer where it is located. Remote Server get. Date() Tue Jun 12 17: 20: 24
The interface file import java. rmi. *; import java. util. Date; public interface Remote. Date extends Remote { public Date get. Date() throws Remote. Exception; } • Must import java. rmi. * • Must extend the Remote class • Each declared method must throw a Remote. Exception
Defining a class to implement remote objects. Remote Extends Remote. Object Remote Interface Implements Extends Definition of the class for the remote object Date. Server. java
The client program import java. rmi. *; import java. rmi. server. *; import java. util. Date; public class Date. Client { public static void main( String args[] ) { try { Remote. Date dateobj = (Remote. Date)Naming. lookup( "rmi: //"+args[0]+"/Date. Server" ); Date datum = dateobj. get. Date(); System. out. println( “Server Date : " + datum ); } catch ( Exception e ){ System. out. println(e); } } }
The Stub and Skel files • The communications are implemented by the stub and skel files. • With the 1. 5 version of java they are generated automatically. Client Stub Remote Object Server Skel
The name registry server • It is a server for registring and making public the remote objects. • The server of the remote object registers the object in it and the clients obtain a reference to the object from it. • Must run in the host server, and have access to the stub and skel files. • Must be reinitialized before the server registers the object. rmiregistry 2 Client 3 1 4 Remote Object Server
¿ What file and where? • The client need the interface and stub file. • The server need the Stub and Skel file. Client Date. Client. class Remote. Date. class Remote Object Server Date. Server. class Remote. Date. class
Initiating the rmiregistry from the application. • It is possible to initiate the rmiregistry from an application calling a java method. • The following example will also demostrate concurrent problems. Remote Number Server get. Number() 1 get. Number() Client 3 2 get. Number() Client
The RMI based chat • The client must receive the messages of the server. • The client implements a remote object wich is passed to the server as a parameter!!! • The server does not need to locate the client Remote Object Client add. Client(this) send. Message(text) new. Message(text) Remote Object Server
A remote file server Access to files -open file read/write -close file -Read line -Write line Client What happends if: - It is asked to open a nonexisting file. - It is asked to read a nonopened file. - More errors are generated.
Automatic activation of the remote server • Sometimes it is not convienient to have many servers running at the same time, just when it is necessary. • RMI provides a schema to activate objects. • Only one server is always running (the rmideamon), that will wakeup the objects when it is necesary. (Call from a client ) • It is necessary to write and run a “set-up” program to registry the sleeping server with the rmid that will wake it up. • For the client there is no difference.
Steps to write an activable server • Rewrite the Server to extend an “activable” class instead of the Remote. Unicast. Object. import java. rmi. activation. *; public class My. Remote. Class extends Activable implement My. Interface • Replace the constructor to one that has 2 parameters. public My. Remote. Class(Activation. ID id, Marshalled. Object data) throws Remote. Exception { super(id, 0); } • Compile it with javac and rmic. • Write and compile the Setup program
Steps to run it • Run the Class. File. Server and rmiregistry • Run the rmid –J-Djava. security. policy=policy. txt • Run the Setup program Java -Djava. security. policy=policy. txt – Djava. rmi. server. codebase=http: //hostname: port/ Setup • Run the client. Java -Djava. security. policy=policy. txt – Djava. rmi. server. codebase=http: //hostname: port/ client