changing the the way of designing distributed applications communication design orientation: the...

23
Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development of the system is done based on the protocol. Application design orientation: The development and design of the system is done like if everything is local and then the application is divided into modules that will be running on different machines. This first strategy has a more complicated design but the programming will use less resources.

Post on 20-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Changing the the way ofdesigning distributed applications

• Communication design orientation: The design of the protocol goes first and then the development of the system is done based on the protocol.

• Application design orientation: The development and design of the system is done like if everything is local and then the application is divided into modules that will be running on different machines.

• This first strategy has a more complicated design but the programming will use less resources.

• The second is better when the communications are complicated, at the point to make the application difficult.

Page 2: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Alternative Technologies

• Development of networks => Development of distributed systems

• Development of middleware (libraries,tools,services, etc..) that support the programming of distributed systems

• Based on TCP/IP protocol• The programming language is more high-

level• The problem of the distributed applications

is not a particular case.

Page 3: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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

• eXternal Data Representation• Serialization.

Page 4: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Remote Procedure Calls • The client stops the execution until the results

are received.

Call(parameters)

Receive results

RPC ServerRPC Client

Server framework: provided by the middleware

Page 5: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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.

The client usesthe interface tocompile

The serverimplements it

RPC Server

RPC ClientInterface definition file

Page 6: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Remote Objects• As the object orientation paradigm developed

the “remote object” approach replaced the previous paradigm.

• An Application can call a method of an object located on another JVM.

• The interface file is the key concept of the implementation.

RemoteObjectServerInvokes the method

Gets the result

Page 7: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Necessary files

• Gets a reference to the remote object.

• Use the method and,

• Receives the results as if it is locally located.

Client program Server program

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

Defines the methods (just the header) that could be remotely invoked.

ImplementsUse for compilation

interface

Page 8: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Example: Remote Date Server • The only method of the object will be getDate(),

this method will return as a result the date of the computer where it is located.

Remote Server

getDate()

getDate()

Tue Jun 12 17:20:24

Page 9: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

The interface file

import java.rmi.*;import java.util.Date;

public interface RemoteDate extends Remote { public Date getDate() throws RemoteException;}

• Must import java.rmi.*• Must extend the Remote class• Each declared method must throw a

RemoteException

Page 10: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Defining a class to implement remote objects.

Definition of the class forthe remote object

Remote Interface

RemoteObject

Implements

Remote

Extends

Extends

DateServer.java

Page 11: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

The client program

import java.rmi.*;import java.rmi.server.*;import java.util.Date;

public class DateClient { public static void main( String args[] ) { try { RemoteDate dateobj = (RemoteDate)Naming.lookup( "rmi://"+args[0]+"/DateServer" ); Date datum = dateobj.getDate(); System.out.println( “Server Date : " + datum ); } catch ( Exception e ){ System.out.println(e); } }}

Page 12: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

The Stub and Skel files• The communications are implemented by the stub

and skel files.• They are generated when the sourcecode is

compiled using the rmic command.• With the 1.5 version of java they are generated

automatically

Client

Stub

Remote Object Server

Skel

Page 13: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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.

Client Remote Object Server

rmiregistry

1

2

3

4

Page 14: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

¿ What file and where?

• The client need the interface and stub file.• The server need the Stub and Skel file.

ClientRemote Object Server

DateClient.classRemoteDate.classDateServer_stub.class

DateServer.class RemoteDate.classDateServer_stub.classDateServer_skel.class

Page 15: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Generating stub & skel

• The class file of the implementation must be compiled again with the rmic command.

DateClient.javaRemoteDate.java

DateClient.class

DateServer.class

DateServer_stub.class

DateServer_skel.class

DateServer.java

RemoteDate.classjavac

javacjavac

rmic

Page 16: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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

Client Clie

ntClient

getNumber()

getNumber()getNumber()

1 2 3

Page 17: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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

Remote Object Server

addClient(this)

sendMessage(text)

newMessage(text)

Page 18: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

A remote file server

Access to files

Client

-open file read/write-close file-Read line-Write line

What happends if:- It is asked to open a non-existing file.- It is asked to read a non-opened file.- More errors are generated.

Page 19: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Automatic Distribution (stub)• The stub file can be distributed atomaticly but it is

necessary to add a safety controller.• For this it is necessary to write in a security policy

file.• When the server is initialized it is necessary to

specify an URL to tell the server where the policty file is located.

java –Djava.security.policy=policy.txt -Djava.rmi.server.codebase=http://hostname/filelocation ClientProgram

• Se examples: PideNumero ReparteNumeros (askNumber) (GiveNumber)

Page 20: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Automatic Distribution (stub)• The stub file is obtained using the URL protocol• A “web-server” must be running.• A small class server can be used.• ClassFileServer (extends ClassServer)• Steps :

– Download RFSClient.cass, RFSInterface.class, policy.txt

– Run the class Server with the command ClassFileServer port path.

– Run the remote object server.– The client contacts the server (with the policy and

codebase parameters)

Page 21: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

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.

Page 22: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Steps to write an activable server

• Rewrite the Server to extend an “activable” class instead of the RemoteUnicastObject.

import java.rmi.activation.*; public class MyRemoteClass extends Activable implement

MyInterface

• Replace the constructor to one that has 2 parameters. public MyRemoteClass(ActivationID id, MarshalledObject data) throws RemoteException {

super(id, 0); }

• Compile it with javac and rmic.• Write and compile the Setup program

Page 23: Changing the the way of designing distributed applications Communication design orientation: The design of the protocol goes first and then the development

Steps to run it

• Run the ClassFileServer and rmiregistry• Run the rmid

rmid –J-Djava.security.policy=policy.txt

• Run the Setup programJava -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