distributed file system using rmi

13
1 DISTRIBUTED FILE SYSTEM USING RMI By George Koutsogiannakis

Upload: yates

Post on 05-Jan-2016

55 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: DISTRIBUTED FILE SYSTEM USING RMI

1

DISTRIBUTED FILE SYSTEM USING RMI

By George Koutsogiannakis

Page 2: DISTRIBUTED FILE SYSTEM USING RMI

2

DISTRIBUTED SYSTEM

A B

DC

In a distributed system the nodes are connected with each other (complete network). Usually there is no distinctionbetween a client and a server. Services are distributedthroughout the nodes and a node can act as a client, at some point in time, asking for services from another node, or as a serverat another time offering services to another node.

Page 3: DISTRIBUTED FILE SYSTEM USING RMI

3

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).

Page 4: DISTRIBUTED FILE SYSTEM USING RMI

4

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

Page 5: DISTRIBUTED FILE SYSTEM USING RMI

5

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.

Page 6: DISTRIBUTED FILE SYSTEM USING RMI

6

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.

Page 7: DISTRIBUTED FILE SYSTEM USING RMI

7

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:

Page 8: DISTRIBUTED FILE SYSTEM USING RMI

8

IMPLEMENTATION USING RMI

client

Registry

server

1

1

3

41. 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).

2. The registry responds with information about the server’ s IP address , port number for the service, object id number etc.

3. The client sends a request to invoke the service on the server. 4. The server executes the service and returns the results to the client.

2

Page 9: DISTRIBUTED FILE SYSTEM USING RMI

9

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.

Page 10: DISTRIBUTED FILE SYSTEM USING RMI

10

IMPLEMENTATION USING RMI

// implement the code for the remotely invokable methodpublic int openFile(name) {

//code to open the file return int;

}//main method for the class that starts the serverpublic static void main ( String [ ] args) { // start the server by instantiating an instance of the classMyRemoteFileSystemImpl 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 classTHTAT’S ALL IS NEEDED FOR THE SERVER!

Page 11: DISTRIBUTED FILE SYSTEM USING RMI

11

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

Page 12: DISTRIBUTED FILE SYSTEM USING RMI

12

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

Page 13: DISTRIBUTED FILE SYSTEM USING RMI

13

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.