Title: Systems Programming
1Systems Programming Scripting
- Lecture 11 The Distributed Object Model
2Introduction
- 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.
3Introduction (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)
5Distributed 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.
6Distributed 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)
8Concepts 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.
9Concepts 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.
10Concepts 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
11Concepts 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.
12Concepts 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.
13Implementing 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)
15Example 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.
16Example Remote Calculator
- The server uses remoting libraries
using System using System.Runtime.Remoting using
System.Runtime.Remoting.Channels using
System.Runtime.Remoting.Channels.Http
17Example Remote Calculator
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
18Example Remote Calculator
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 )
19Example Remote Calculator
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)
20Example 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