140 likes | 365 Views
DISTRIBUTED FILE SYSTEM USING RMI. By George Koutsogiannakis. A. B. C. D. DISTRIBUTED SYSTEM. In a distributed system the nodes are connected with each other (complete network). Usually there is no distinction between a client and a server. Services are distributed
E N D
DISTRIBUTED FILE SYSTEM USING RMI By George Koutsogiannakis
A B C D DISTRIBUTED SYSTEM In a distributed system the nodes are connected with each other (complete network). Usually there is no distinction between a client and a server. Services are distributed throughout the nodes and a node can act as a client, at some point in time, asking for services from another node, or as a server at another time offering services to another node.
FILE SYSTEM DISTRIBUTION • OFFERS RELIABILITY (DUPLICATION OF THE SYSTEM • IN VARIOUS NODES) • ALLOWS ANOTHER NODE TO CONCENTRATE • ITS RESOURCES TO OTHER TASKS (POSSIBLY • COMPUTATIONAL TASKS) • ALLOWS THE MIGRATION OF DATA FROM NODE TO • NODE AS NEEDED (SHARING OF DATA BETWEEN • NODES). • ALLOWS MIGRATION OF PROCESSES FROM NODE • TO NODE (EXAMPLE IS THE TRANSFER OF AN APPLET • PROGRAM FROM A WEB SERVER TO A CLIENT VIA THE • INTERNET).
IMPLEMENTATION • A SERVICE AT A PARTICUALR NODE IS REPRESENTED BY A PROCESS. THEREFORE WE NEED A PROTOCOL FOR EXCHANGING MESSAGES. • THE DISTRIBUTED SERVICES AT A SERVER NODE (AND THE CLIENT NODE) CAN BE IMPLEMENTATED BY USING ONE OF THE FOLLOWING FRAMEWORKS: • JAVA ‘S REMOTE METHOD INVOCATION API • ALL SERVICES MUST BE WRITTEN IN JAVA. • USES THE JRMIP (JAVA REMOTE METHOD INVOCATION PROTOCOL) AS THE TRANSPORT LAYER PROTOCOL. • FREES THE DEVELOPER FROM: • CREATING THE NETWORKING CODE • CREATING THE OBJECT SERIALIZATION CODE • CREATING THE MESSAGING MECHANISM
IMPLEMENTATION • JAVA ‘S RMI OVER IIOP (RMI OVER INTERNET INTER OPERABILITY PROTOCOL) API. • SERVICES CAN COMMUNICATE WITH EACH OTHER EVEN IF THEY ARE NOT WRIITEN IN JAVA (AND THUS THEY ARE NOT USINGJAVA DATA TYPES) • USES IDL (INTERFACE DEFINITION LANGUAGE) AS THE LANGUAGE TO CREATE DATA TYPES THAT ARE UNDERSTOOD BY ALL NODES REGARDLESS OF THE LANGUAGE USED TO REPRESENT A PROCESS AT THE PARTICULAR NODE. • JUST LIKE RMI IT FREES THE DEVELOPER FROM: • CREATING THE NETWORKING CODE • CREATING THE OBJECT SERIALIZATION CODE • CREATING THE MESSAGING MECHANISM • CREATING THE IDL DATA TYPES. THE SYSTEM CONVERTS JAVA DATA TYPE STO IDL AUTOMATICALLY. • USES THE IIOP PROTOCOL AT THE TRANSPORT LAYER.
IMPLEMENTATION • AN IMPLEMENTATION OF THE CORBA (COMMON OBJECT REQUEST BROKER) SPECIFICATION. • THERE ARE MANY VENDORS THAT PRODUCE IMPLEMENTATIONS IN DIFFERENT PROGRAMMING LANGUAGES (INCLUDING JAVA OR C++). • MS OFFERS IT IN ITS .NET FRAMEWORK. SUN MICROSYSTEMS OFFERS IT AS A SEPARATE API IN THE JDK. • HARDER TO USE THAN THE PREVIOUS TWO FRAMEWORKS. • DEVELOPER H AS TO IMPLEMENT NETWORKING • DEVELOPER HA STO IMPLEMENT SERIALIZATION ALGORITHMS • DEVELOPER HAS TO IMPLEMENT IDL DATA TYPES MODULES.
IMPLEMENTATION USING RMI SUPPOSE A SERVER HAS THE FILE SERVICE int openFile(String name). That means that a client requesting the service(invoking the service openFile remotely) has to pass to the server a string representing the name of the file to be opened. The server will execute the service and then return to the client an int representing either success or the code for an error message. The following communications take place:
Registry 1 1 server client 3 4 IMPLEMENTATION USING RMI 2 • Server implements the method and registers an object that can be used by a client to a registry ( a database that • keeps track of all services and their locations). The client is aware of the remote object. It contacts the registry • to obtain information about the location of the server node, the port number where the process resides and the • object id number (Many clients can request the service simultaneously). • The registry responds with information about the server’ s IP address , port number for the service, object • id number etc. • The client sends a request to invoke the service on the server. • The server executes the service and returns the results to the client.
IMPLEMENTATION USING RMI • Most of the communications discussed thus far are created by providing a single line of code in our coding of the corresponding processes. The RMI system and the local O.S. handle the rest. • SERVER CODING: • Create an interface that represents the service: • public interface MyRemoteFileSystem exetnds Remote { public int openFile ( String name) throws RemoteException; } • Create a class that implements the remote service (method). • public class MyRemoteFileSystemImpl extends UnicastRemoteObject implements MyRemoteFileSystem { //constructor that calls super(); . Super is a call to the superclasse’ s constructor. In the case the super class creates network connections. Nothing else is needed on the part of the developer.
IMPLEMENTATION USING RMI // implement the code for the remotely invokable method public int openFile(name) { //code to open the file return int; } //main method for the class that starts the server public static void main ( String [ ] args) { // start the server by instantiating an instance of the class MyRemoteFileSystemImpl rfs = new MyRemoteFileSystemImpl ( ) ; //create a string that represents the location of the registry and the name of a remote object that can be used by a client to invoke the service String serverobjectname = “//localhost/remoteobject; // we assume that the registry resides localhost (or it can be the ip address of another node //proceed to register the remote object with the registry Naming.rebind ( serverobjectname, rfs ); }//end of main }// end of the class THTAT’S ALL IS NEEDED FOR THE SERVER!
IMPLEMENTATION USING RMI • CLIENT CODING • Create a class that represents the client process. public class Client { // global declarations as needed //constructor //other methods as needed 9including a main method for the client // method that needs to open a file from the File Server node public void getRemoteFile ( ) { String serverobjectname = “//localhost/remoteobject; // lookup remote object on the registry. Notice that the name of the interface is used below MyRemoteFileSystem myfile = mew (MyRemoteFileSystem) Naming.lookup ( serverobjectname) ; //proceed with remote invocation int c = myfile. openFile(filename) ; // where filename is a string representing the name of the file. It is passed to the server. The server returns the result which is capured by the int c. } //end of the method }//end of the client class
IMPLEMENTATION USING RMI • As you can see the implementation is simple. Most of the work is handled by the system under the hood. • COMPILING • Compile the server interface class first by using javac. • Compile the server class that implemets the interface next by using the javac compiler • Compile the server class that implements the interface one more time by using the rmic compiler (it comes with the jdk). This produces an extra class called the stub > rmic –v1.2 MyRemoteFileSystemImpl //notice that no extension is used after the file name The file MyRemoteFile SystemImpl_stub.class is produced • Compile the client class by using javac compilker
IMPLEMENTATION USING RMI • MAKING IT WORK • Place the compiled interface file ( MyRemoteInterface.class) in the client node (in addition to the server node) • Place the stub (MyRemoteFileSystemImpl_stub.class) in the client node also (in addition to the server node). • Place the server MyRemoteFielSystem.class on the server node • Place the client code on the client node. • Start the registry. RMI provides registry automatically > start rmiregistry • Start the server >java MyRemoteFileSystemImpl • Start the client >java Client • Note: In windows open a DOS window for each process.