Distributed Objects and RMI
Distributed Objects and RMI
Middleware Interfaces (IDL) The Distributed Object Model RMI: Remote Method Invocation
An extension to local method invocation that allows remote method invocation also
Middleware
CORBA COM and DCOM
SOAP
Introduction
Sockets API used for sending & receiving calls (simple IO) Remote Procedure Calls (RPC)
Was designed to provide a procedural interface for distributed (i.e., remote) services The aim was to make the distributed nature of service transparent to the programmer However, it is no longer considered particularly good
Middleware
Middleware abstracts much of the detail and heterogeneity in systems Middleware provides, location transparency, independence from the communication protocols, operating systems, hardware etc.
Middleware
What middleware hides / provides
Provides location transparency:
A programmer could make a call to method without knowing where the method is physically located (same host, different host)
Marshalling details hidden and automatic Independence from different OS CORBA allows different programming languages to talk
Using interface definition language (IDL)
Interfaces
What is an interface
Not a GUI Interface in this unit refers to the means of connection for two different systems
return a+b; }
Interfaces
public int sumNumbers(int a, int b){
In software
Units of code are modularized that is organized into modules Modules may use other modules via either calling their methods or through direct access to their data They do this using interfaces
private void myCalc(){ System.out.println(sumNumbers(10,10));
And here we have another method that references and calls the above
System.out.println(sumNumbers(5,7)); }
Interfaces
Interfaces
The calling method does not need to know or care how the code is written So long as the interface remains the same method B may call method A
Interfaces
Interfaces in a DIS
Pass by reference is not appropriate
As a local memory address has no meaning to another computer
However, no change is required in the client code as the INTERFACE remained the same
private void myCalc(){ System.out.println(sumNumbers(10,10)); System.out.println(sumNumbers(5,7)); }
public int sumNumbers(int a, int b){ int result = a+b; return result; }
Interfaces
Interfaces in a DIS
IDL: Interface Definition Language
Provides an agreed convention for describing the interfaces between methods This includes distinguishing between Input and Output arguments
struct Person { string name; string place; long year; }; Interface PersonList{
Interfaces
An example CORBA IDL
Contains marshalling information
readonly attribute string listname; void addPerson(in Person p); void getPerson(in string name, out Person p); long number(); };
Interfaces
An example CORBA IDL
struct Person { string name; string place; long year; }; Interface PersonList{ readonly attribute string listname; void addPerson(in Person p); void getPerson(in string name, out Person p); long number(); };
And what are the key differences between the distributed object model and the object model?
Interfaces
A definition of a method or a set of methods Does not refer to the implementation of the method but Contains types of arguments, return types of the method, etc.
Actions
Actions occur from method invocations Invocations might supply arguments (data) in making an invocation
Exceptions catch errors that occur so that the software does not crash in an uncontrolled manner When an error occurs control jumps to the handler for the error
Example, try{some code}catch (some error){some other code}
Garbage collection
Objects are instantiated and either de-instantiated or cease being referenced anywhere in the program The memory allocated to these objects must be made available Thus, a system for collecting dead objects and data is required This is referred to as garbage collection
Distributed objects also run as separate processes communicating via their interfaces However, in a DIS processes can run at different computers
Perhaps communicating via RMI
In a DIS a program would use a series of local and remote processes during its execution
Distributed Objects
A client server example
client
server LI E RI A B LI F LI C RI D RI G
In order to make a remote request invokers must have a Remote Object Reference
i.e. A must have Remote Object Reference for B, etc.
Remote objects must have a remote interface that specifics methods that can be invoked remotely
i.e. B, D and G
= an object = a message
Interfaces
Similar to the classic Object Model +++ defines methods that can be remotely invocated
Actions
Similar to the classic Object Model +++Actions may require methods from remote objects, these remote objects have to be available Exceptions Similar to the classic Object Model +++There are more reasons to fail and more exceptions, remote process failure, timeouts, etc. Garbage collection +++remote garbage collection requires coordination is required between local garbage collectors Similar to the classic Object Model
Implementation of methods
m5 m6
RMI
RMI design issues
Invocation semantics
Maybe semantics
No guarantees, it may or may not have executed
RMI
How RMI is implemented?
RMI is composed of many objects and modules that together provide the RMI implementation:
Communication module Remote reference module RMI software
Proxy Dispatcher Skeleton
Transparency
Access, location, migration, failure, etc.
RMI
How RMI is implemented
Example: Object A makes a remote method invocation of object B
>>> PICTURE HERE <<<
Proxy For B A
RMI
How RMI is implemented Example: Objects A makes a remote method invocation of object B
Proxy Skeleton, dispatcher for B For B B A
request reply
request reply
Communication module
Client
Contains the proxies for the remote objects The remote reference module Can also have a binder to reference remote objects A communication module
An example of a request
Server
Contains skeletons and dispatchers Communication module
RMI
Communication module
Implements the Request-Reply protocol that is used for communication
RMI
Proxy
Makes remote methods transparent to local processes Remote object references are directed to the proxy which passes them to the remote method Thus, there can be one for each remote object in the Remote Object Table The proxy marshals data and un-marshals results The proxy implements the interfaces of remote methods and send calls to them using the interfaces
RMI
Dispatcher
Receives messages from the communication module, selects and passes on the message to the right skeleton for the remote object
RMI
Servant
provides the implementation for a remote class. Runs in a server process is the recipient of the remote request from the skeleton
Skeleton
Un-marshals the request and calls the relevant remote method Marshals the response into the reply Sends to the requesting proxy (through the communication module)
RMI
Proxies, dispatchers and skeletons
These tend to be generated by middleware software using compilers CORBA IDL is compiled into skeletons and stubs Similarly for Java RMI when the remote interface is used.
RMI
Example: Objects A makes a remote method invocation of object B
Proxy For B A
request reply
An example of a request
RMI
Static invocation
Proxies are generated pre-runtime using the remote interfaces Binder
RMI
A client service that obtains and stores remote object reference
Java RMIregistry, CORBA Naming service
Dynamic invocation
Useful when all remote interfaces are not know at design time Client supplies a remote object reference, name of method and arguments The middleware then determines which remote object is required
It stores mappings from textual names to remote object references Servers need to register the services they are exporting with the client binder
Sever
Can choose to execute a thread for each RMI
RMI
Activation of remote objects
Active and passive objects
An Active object is an instantiated in a running process A Passive object is an object not currently active but can be made Active
i.e. its Implementation, and marshalled state are stored on disk
RMI
Persistent object stores
An object that lives between activations of processes is called a persistent Object Stores the state of an object in a marshalled (serialised) form on disk
Recall in Java the implements serialisable
Location service
Objects can move (Migrate) from one system to another during their lifetime Solution is to maintains mapping between object references and the location of an object May involve broadcasts to track down objects
RMI
Distributed garbage collection
Local hosts have their own garbage collectors Traditionally an object is dead when it is no longer referenced However, in a DIS a remote method might still reference the object Javas solution
Servers keep a list of references When a client proxy is created addReference to server list When a client proxy is deleted removeReference from server list
Distributed event
Similar but needs to account for distribution Change state of a remote object might require a change in state of other remote objects
CORBA
What is it?
CORBA is a middleware that allows application programs to communicate with one another irrespective of their programming languages, their hardware and software platforms, the networks they communicate with and their implementers
[Coulouris et al, 2001]
CORBA: Architecture
Key concepts
ORB core Object adaptor Skeletons Client stub/proxies And some others:
Repositories (implementation & interface) Dynamic invocation interface Dynamic interface
CORBA: Architecture
Object Request Broker (ORB)
The ORB allows clients to invoke operations in remote objects Remote objects are called as CORBA objects but are essentially regular objects wrapped in CORBA IDL Clients make a request of the ORB The ORB is responsible for:
locating objects, activating objects and communicating client requests to objects
CORBA: Architecture
CORBA: Architecture
The ORB provides:
Access transparency
Object methods are invoked in the same manner whether they are local or remote to the requesting object
CORBA: Architecture
Skeletons
RMI messages are sent via skeletons to appropriate server implementations (known in CORBA as servants) Skeletons performs un-marshalling and marshalling duties
Location transparency
The location of an object is not known and does not need to be known when invoking that objects methods
Client stubs/proxies
Stubs for procedural languages Proxies used in OO languages Marshal client arguments of invocations
Implementation transparency
The way an application is implemented (language, Activation Policy, platform, operating system etc.) is hidden
Distribution transparency
The communications network, specific node - server mappings, and relative locations of communicating objects are hidden
CORBA: Architecture
The Object Adaptor
Bridges the gap between CORBA IDL and programming languages Its responsibilities:
Creating remote object references for CORBA objects Dispatching ach RMI via a skeleton Activating the object
CORBA: Architecture
Portable object adaptor (POA)
Separates the creation of CORBA objects from the creation of servants An object adapter that can be used with multiple ORB implementations Allows persistent objects - at least, from the client's perspective
CORBA: Architecture
The CORBA Architecture
CORBA: Architecture
ORB core
CORBA: Architecture
Interface repository
Provides similar facilities to Java reflection Stores information about interfaces for client / server use
CORBA: Architecture
Dynamic implementation interface (DII)
Server interface's) may not have been available at client deployment Clients can make requests without using stubs/proxies Client discover services at run-time (using trading service) ORB plays crucial role supplying interfaces and performing marshalling
Implementation repository
stores information about the object implementations maps them to the names of object adaptors Entries contain:
the object adaptor name the pathname of the object implementation the hostname and port number of the server
CORBA: Architecture
Dynamic Skeleton Implementations (DSI)
The server side equivalent to DII A skeleton might not be present on the server in a development environment This facility allows requests for an object that does not have skeletons on the server A sever has to allow invocations on the interfaces of the CORBA objects Examine the contents of the invocation and discover the target object and method. CORBA IDL
CORBA: IDL
Is used to define the remote methods for use by clients Servers define IDL for the methods that will use the ORB Server implements the IDL Clients program to the IDL specification Provides facilities for defining modules, interface types, attributes and method signatures
Interface Stock{ readonly attribute double stockPrice; readonly attribute string stockCode; void getStockPrice(in string stockCode, out double stockPrice); }
A Server must then implement the method A Client may call the server method using the IDL signature
CORBA: Protocols
CORBA Protocols
CORBA GIOP (General Inter ORB Protocol) handles external data using CDR
This provides hardware/software independence
GIOP also handles R-R protocol for different operating systems IIOP implements R-R protocol of TCP-IP
Protocol & address details IIOP Host domain name Port number
CORBA: Services
CORBA provides a set of services for use by distributed objects These include:
Naming service Security service Trading service Transaction and concurrency service Persistent object service Event service
CORBA: Services
Naming service
The CORBA naming service is essentially it is a binder Each ORB has an initial naming context Objects may bind to the initial naming context Contexts may also exist within the initial naming context Objects may then bind to subcontext also Objects are referenced through their context and names
A Initial naming context
Sub-context A
10
CORBA: Services
Security service
Essentially this service authenticates principals Client sends credentials in requests Upon receipt the server decides whether to process has the right to access the remote object If sufficient rights exists the server execute the remote invocation Also ensures non-repudiation and secure communications
CORBA: Services
Event Services
This service defines a means for implementing the Publisher/Subscriber pattern (suppliers and consumers in CORBA)
Push: suppliers push events to consumers Pull: consumers request events from suppliers
CORBA: Services
Persistent object service
Each CORBA object is responsible for saving its state when it id de-activated The POS (Persistent Object Service) provides a means for CORBA objects to save their state Can use PSDL or persistence transparency technique
CORBA: Services
Trading service Rather than accessing objects by name trading services allow objects to be accessed by attributes In other words, this service allows clients to access remote objects based on the which of the remote objects is best able to meet the request of the client rather than the client specifying a specific object Example
If we want to find a plumber we can either use the name of the company Or some criteria,
Local area=london, service=emergency
COM
Its interfaces are defined in IDL Supports dynamic discovery Uses Unique component ID mechanism Invocation from one component to another occurs using virtual tables, known in COM as vtables
Essentially this is just a list of pointers clients have pointers to the vtable which point to server functions This is all stored in binary so it is language independent
11
COM: interfaces
Interfaces in COM have Globally Unique Identifier (GUID) Its using the GUID that clients can locate required interfaces
vtable look-up Vtable is a fast method!
COM: Objects
In COM objects have states and methods Contain code that implements a service Objects can be in different languages Access to objects occurs through defined interfaces COM supports multiple interfaces for objects
COM: Objects
A COM object must have the IUnknown interface This provides functions
QueryInterface, AddRef and Release
DCOM
Distributed COM (DCOM) extends COM for distributed systems allowing remote calls Based on Distributed Communication Exchange (DCE) Can uses proxies and stubs Can also use the DCOM network protocol
But.. a COM object could have more interfaces but must have IUnknown
DCOM
The DCOM intra-network model
Client Proxy Security
DCE RPC
DCOM
Within process communication
Server Stub
Security
DCE RPC
Inter-process communication
Slower, uses proxies and stubs
LPC
LPC
Inter-network communication
DCOM network protocol
12
SOAP
SOAP (Simple Object Access Protocol) A scheme for using XML as RR messages Services are offered through web standards SOAP is built on XML and uses HTTP
SOAP
Interoperability through wrapping Wrap other technologies in SOAP messages
.NET SOAP Server JAVA LEGACY DCOM
CORBA
SOAP
Why SOAP?
Direct connections between businesses is not allowed for security reasons Businesses use different middleware
Connecting them together using a global middleware is not realistic And, middleware is often not compatible
SOAP
Essentially uses RPC through HTTP
1. Client transforms RPC into an XML document 2. Server transforms the XML into a procedure call 3. Sever transforms the procedures response into an XML document 4. Client transforms the XML document into the response to the RPC
Publishing systems that require integration as web services using SOAP is a solution
13
SOAP
SOAP is only a protocol it is not like CORBA or COM SOAP
Single function or method invocations Stateless clients make single method or function calls, one per HTTP request. SOAP gets the data from a Web server in a method call, which uses the data offline locally, it then sends the updated data back to the server in another stateless remote call
SOAP
SOAP is based on message exchanges Everything exists within an SOAP envelope Envelope contains Header and Body elements divided into blocks Body contains an XML document for a webservice Header used for coordination information, identifiers, security information
DCOM or CORBA
create a persistent connection Multiple property accesses and method calls DCOM and CORBA both support stateful remote connections
SOAP
SOAP message SOAP header Security context Signatures
SOAP
env:envelope xmlns:env = namespace URI for SOAP envelopes env:body m:exchange
m:arg1 Simon
m:arg2 1976
m:arg3 London
SOAP
env is the top element and is of type envelope
Envelope definition is defined using XML schemas and referenced through the xmlns (xml namespace)
SOAP
SOAP binds to a transport protocol Typically HTTP using GET or POST
GET does not use a SOAP message but the response is a SOAP message POST uses SOAP message for request and response
body
The body of the message Again defined through an XML schema
14
SOAP: request
POST /StockQuote HTTP/1.1 Host: www.stockquoteserver.com Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "GetLastTradePrice" <SOAP-ENV:Envelopexmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope> From the: Simple Object Access Protocol (SOAP) 1.1. W3C Note 08 May 2000
SOAP: request
POST /StockQuote HTTP/1.1 Host: www.stockquoteserver.com Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI" <SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceDetailed xmlns:m="Some-URI"> <Symbol>DIS</Symbol> <Company>DIS Corp</Company> <Price>34.1</Price> </m:GetLastTradePriceDetailed> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
From the: Simple Object Access Protocol (SOAP) 1.1. W3C Note 08 May 2000
SOAP: request
HTTP/1.1 200 OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Header> <t:Transaction xmlns:t="some-URI" xsi:type="xsd:int" mustUnderstand="1"> 5 </t:Transaction> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> From the: Simple Object Access Protocol (SOAP) 1.1. W3C Note 08 May 2000
Conclusions
Middleware Interfaces (IDL) The Distributed Object Model RMI: Remote Method Invocation
An extension to local method invocation that allows remote method invocation also
Middleware
CORBA COM and DCOM
SOAP
END
15