Systems Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Systems Programming

Description:

Systems Programming & Scripting Lecture 11: The Distributed Object Model – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 21
Provided by: Yus49
Category:

less

Transcript and Presenter's Notes

Title: Systems Programming


1
Systems Programming Scripting
  • Lecture 11 The Distributed Object Model

2
Introduction
  • The distributed object model is one of executing
    object-oriented code across a network of
    machines.
  • It uses the object-based programming model in
    which objects in different processes communicate
    through remote method invocation.
  • Central to the distributed object model
    applications is a middleware component.
  • Middleware is a software component that is based
    on processes and message passing protocols in a
    distributed system.
  • The middleware layer uses message exchange
    protocols such request-reply protocols to provide
    abstractions on e.g. remote invocations.

3
Introduction (cont'd)
  • The middleware layer abstracts over
  • Execution site (location transparency),
  • the communication protocol,
  • the operating system and
  • the hardware.
  • See figure in next slide for an illustration of
    the position of the middleware layer and its
    relation to other components of a distributed
    system.

4
(No Transcript)
5
Distributed Objects
  • In an object-based system, its state is logically
    divided into parts with each part associated with
    a specific object.
  • The distributed object model borrows the basic
    object-oriented concepts such as
  • Object references.
  • Interfaces (e.g. classes).
  • Actions, method invocations on objects.
  • Exceptions.
  • Garbage collection.

6
Distributed Objects (cont'd)
  • A distributed objects system can use a
    client-server architecture where in this case
  • Objects are created and managed by servers.
  • Clients issue remote method invocations on the
    servers objects to use their services.

7
(No Transcript)
8
Concepts of the Distributed Objects Model
  • Remote Object References
  • Extended from the concept of object reference in
    the object-orientation model where
  • Any object that can receive a remote method
    invocation must have a remote object reference.
  • Remote object references can be passed as
    arguments and results to remote method
    invocations.

9
Concepts of the Distributed Objects Model
  • Remote Interfaces (see figure in next slide)
  • The class of a remote object implements the
    methods of its remote interface.
  • Objects in other processes can only invoke the
    methods specified in the remote interface.
  • Remote interfaces do not have constructors, i.e.
    cannot construct objects directly through
    interfaces.

10
Concepts of the Distributed Objects Model
  • Coulouris G., Dollimore J. and Kindberg T.,
    Distributed Systems Concepts and Design, Pearson
    Addison and Wesly, 2001

remote
object
Data
remote
interface
m4
m1

implementation
m5
m2
m6
of methods
m3
11
Concepts of the Distributed Objects Model
  • Garbage Collection
  • A typical garbage collector ensures that if there
    are no references still held to an object, such
    object is removed and memory is recovered.
  • A distributed garbage collector not only checks
    local references to an object but also remote
    object references from other parts of a
    distributed system, in order to decide whether to
    remove an object or not.

12
Concepts of the Distributed Objects Model
  • Exceptions
  • Remote method invocations can fail due to
    distribution problem or failure in the execution
    of the method itself.
  • Thus, remote method invocations should be able to
    raise exception on each of the above type of
    problems occur.

13
Implementing RMI
  • A number of objects and modules are required to
    achieve remote method invocation as shown in the
    figure on the next slide.
  • This diagram illustrates the operations and
    components involved when an application-level
    object A invokes a method in a remote
    application-level object B.
  • Object A holds a remote object reference for
    object B.
  • Several modules are required in a remote method
    invocation including
  • Communication modules.
  • Remote reference modules.
  • The RMI software including a proxy, a dispatcher
    and skeleton.
  • The two cooperating communication modules at the
    client and server implement the request-reply
    protocol which forms the basis of communication.

14
(No Transcript)
15
Example Remote Calculator
  • First we define an interface of the functions
    that should be provided by the server

public interface ICalc double Add (double
x, double y) double Sub (double x, double
y) double Mul (double x, double y)
double Div (double x, double y)
Example from Programming C 3.0, Jesse Liberty,
O'Reilly. Chapter 19.
16
Example Remote Calculator
  • The server uses remoting libraries

using System using System.Runtime.Remoting using
System.Runtime.Remoting.Channels using
System.Runtime.Remoting.Channels.Http
17
Example Remote Calculator
  • The main server class

public class Calculator MarshalByRefObject,
ICalc public Calculator ()
Console.WriteLine("Calculator constructor")
// the four interface functions public
double Add (double x, double y)
Console.WriteLine("Add 0 1", x, y)
return xy
18
Example Remote Calculator
  • Initialising the server

public class ServerTest public static void
Main() // create a channel an register
HttpChannel chan new HttpChannel(65102)
ChannelServices.RegisterChannel(chan)
Type calcType Type.GetType("CalcServer.Calculato
r") // register our well-known type and
tell the server // to connect the type to
the endpoint "theEndPoint"
RemotingConfiguration.RegisterWellKnownServiceType
( calcType, "theEndPoint",
WellKnownObjectMode.Singleton )
19
Example Remote Calculator
  • The main client class

public class CalcClient public static void
Main() // create an http channel
HttpChannel chan new HttpChannel(0)
ChannelServices.RegisterChannel(chan) //
get my remote object MarshalByRefObject obj
(MarshalByRefObject) RemotingServices.Conn
ect ( typeof(CalcServer.ICalc) // what
to get "http//localhost65102/theEndPoin
t" // where ) try // cast object
to interface CalcServer.ICalc calc obj as
CalcServer.ICalc // use the interface to
call methods double sum calc.Add(3.0,4.0)
Console.WriteLine("34 0", sum)
20
Example Remote Calculator
  • Compile the components individually
  • gmcs -targetlibrary ICalc.cs
  • gmcs -pkgdotnet -referenceICalc CalcServer.cs
  • gmcs -pkgdotnet -referenceICalc CalcClient.cs
  • Run Server and Client as separate programs
  • mono CalcServer.exe
  • mono CalcClient.exe
  • This will print
  • 34 7
Write a Comment
User Comments (0)
About PowerShow.com