Presentation is loading. Please wait.

Presentation is loading. Please wait.

10. Distributed object-based systems

Similar presentations


Presentation on theme: "10. Distributed object-based systems"— Presentation transcript:

1 10. Distributed object-based systems
P493

2 广州 北京 employee dept personnel hire() obj server Corp server 南京

3 Features Commercial systems
P152, P496 Offer services and resources in the form of objects object server ~ concurrent server (FTP, Web) hide distributed aspect behind an object’s interface Commercial systems CORBA: an industry-defined standard for distributed system DCOM: a middleware layer on top of Windows OS Java: distributed object

4 Common Object Request Broker Architecture
P494 10.1 CORBA Common Object Request Broker Architecture

5 10.1 Introduction 1. Two kinds of applications for distributed system
Resource sharing build up distributed application system, C/S, XML Parallel distributed computing use several computers to solve a large problem 2. Two kinds of tools

6 Distributed programming language ---
is used to write distributed parallel program Linda PVM (Parallel Virtual Machine) MPI (Message Passing Interface) Communication middleware --- build up distributed application system CORBA, DCOM Object-oriented Web services

7 Goals of CORBA different platform different OS different language
different protocol prog obj OS1,Lang1 OS2,Lang2 OS3,Lang3 Internet?

8 目标 在异构, 开放环境中,各机间实现互操作。 独立于厂商的软件工业规范 CORBA提供公共服务和开发工具,以支持分布式应用程序开发
OMG(Object Management Group)制定CORBA规范

9 3. Why CORBA? 一个单位有不同的应用系统: 人事处:教师的人事资料,Windows 教务处:学生成绩和档案,上课教师, Unix
校医院:教师和学生的健康状况 如何共享数据,如何系统集成? CORBA能解决应用系统集成,包括传统应用程序,也能为动态变化的企业环境提供适应性

10 4. What is CORBA? 一种面向对象的分布式应用程序体系规范,是分布式计算和面向对象技术的结合。
一应用程序能共享和访问其他应用程序的对象。这样可连接图形应用程序, 数据库应用程序, GI S 应用程序等。所有分布式对象都有统一的接口,遵守统一通信方法。CORBA可称为通信中间件. 用OO方法构造可重用的, 可共享的软件组件.

11 Distributed object --- component`
self-contained entity provide standard interface is independent of programming language interoperability reuse It is easy to assemble distributed application system

12 10.2 建立CORBA应用程序的大致步骤 假设已建立要解决问题的对象模型. 把 实体 对象 实体的活动 对象的操作 data data
实体 对象 实体的活动 对象的操作 data op1( ) {…. } op2( ) data op3( ) {….. } 要做工作 的描述 …... object i object1

13 实例:公司雇员人事数据的分布式应用程序 实体 属性 操作 Department DeptID manager Employee personal-data promote( ) department dismiss( ) transfer( ) Manager approve-transfer( ) Personnel hire( ) PersonnelManager arbitrate( )

14 1. 建立CORBA应用程序的大致步骤 ~RPC
用IDL语言写各对象接口定义。建立 .IDL文件或接口仓库 Fileserver.IDL IR Corp.IDL

15 Employee Personnel Manger hire( ) promote( ) dismiss( ) transfer( )
personal-data department approve-transfer( ) hire( ) promote( ) dismiss( ) transfer( ) Department DeptID manager Corp.IDL GO

16 编译 .IDL生成 IDL_stub和IDL_skeletons
例如 Corp_cstub.c Corp_sskel.c 用某种语言写客户方程序 例如 Client_main.c 用某种语言写server各对象接口的实现代码 例如 Personnel_Impl { hire(…) {实现代码……………} } 连接,部署上述应用程序的两部分

17 初始化Server, 创建客户所需要的对象实例等 (可用CORBA产品提供的wizard生成) 例如 Server_main.cpp
Client Server Corp_cstub.c Corp_sskel.c Client_main.c Server_main.c 初始化Server, 创建客户所需要的对象实例等 (可用CORBA产品提供的wizard生成) 例如 Server_main.cpp pers_cs 运行上述应用程序 obj

18 基于CORBA的分布式应用开发过程 应 用 开 发 者 return 客户应用 C++, Java编译器 客户程序 IDL Stub
Skeleton C++, Java编译器 服务程序 对象实现 return

19 2. CORBA concepts 对象:由标识,接口,实现组成 对象实例
接口:描述对象上哪些操作可用 请求:是C与S之间传送的消息 激发:发送消息的过程

20 …… …… Personnel object hire(emp_data,dept,...) { … implementation ……}
pers_cs object instance object reference …… hire(emp_data,dept,...) interface Personnel interface

21 Why object reference? Department Personnel …… hire(emp,dept,.. ) { ……
DeptID manager Personnel …… hire(emp,dept,.. ) { …… } pers_cs = resolve(“personnel_cs”) hire(emp,dept,.. ) { …… } pers_cs pers_cshire( , , ); Data Client in 南京 Server in 北京

22 对象引用应含内容? network address of the machine server id or endpoint
object id pointer = object reference

23 The organization of an IOR with specific information for IIOP.
interoperable

24 3. 请求的基本形式: C : hire(对象引用, *ev, 参数) C++ : 对象引用 hire(参数, *ev) OO:
对象.方法名(参数) hire(emp,dept,.. ) { …… } pers_cs

25 10.3 General organization of CORBA
两种角度: 开发应用系统角度 怎么设计、建立、实现CORBA应用程序 CORBA系统实现角度 怎么样的体系结构、怎么实现CORBA系统 1. General organization of a CORBA system

26 Client IR Object implementation DII IDL stub Client ORB ORB intf. OA
DSI IDL skel ORB intf. Server ORB IR Interface-specific stubs and skeletons Same for all ORBs There may be multiple OA P496 return

27 The general organization of a CORBA system.
P496 The general organization of a CORBA system.

28 DII --- Dynamic Invocation Interface
DSI --- Dynamic Skeleton Interface IR Interface Repository OA --- Object Adapter ORB --- Object Request Broker adapter (e-dap’ter`) adaptor noun A printed circuit board that enables a personal computer to use a peripheral device, such as a CD-ROM drive, modem, or joystick, for which it does not already have the necessary connections, ports, or circuit boards. Commonly, a single adapter card can have more than one adapter on it.

29 Stubs:静态调用的客户方桩。由IDL编译程序 产生,将被link到Client程序
Skeletons:静态调用的服务方框架,提供客户 请求到某对象上各操作(方法)的连接 ORB:用客户请求中的信息来发现特定的实现 把客户请求传送到server的对象实现,并 返回结果。ORB是通信中间件,处理对象引用 OA:ORB---OA---对象实现。ORB传来的请求 通过OA选择特定的实现(bind),中间经由 Skeleton来调用有关方法。它的职责:

30 对象注册:把具体程序语言实体注册为 CORBA 对象
激活server:若必要,OA启动server进程, 以便 在其中能激活对象 激活对象:OA激活对象,若这些对象在请求到 达时还未活动 请求分路:OA必须与ORB合作以保证能在多个 连接上接收请求, 分路给不同服务器 调用对象:OA分派请求给注册的对象

31 DII:动态客户请求调用。应用程序在运行时访 问IR,以发现对象的接口定义,建立对对 象的请求
DSI:动态地把客户请求分派到所希望的对象 IR:包含用IDL写的接口,为动态调用提供信息, 如请求操作的参数,及其类型等

32 employee ORB promote() {…} dismiss() {… } Corp server pers_cs
hire() {… } ORB Corp server corp_pers_cs _hire corp_pers_cs_hire OA sale_salesman_bonus salesman bonus() {… } Sale server advertise cost() {… }

33 employee ORB promote() {…} dismiss() {… } Corp server pers_cs
hire() {… } corp_pers_cs_hire corp_pers_cs _hire ORB OA salesman bonus() {… } Sale server advertise cost() {… } skeleton

34 2. CORBA加入代理器 C/S: CORBA: C S C S C 代理器 S ORB C S

35 CORBA的C,S无需直接了解对方。代理知道双方的位置和能力 (from object reference)
S同时也能作为C

36 10.4 OMG IDL ILD是一种中性语言,是说明语言,不是编程语言。用来定义对象的接口,这些接口说明该对象所支持的操作和类型
P496 ILD是一种中性语言,是说明语言,不是编程语言。用来定义对象的接口,这些接口说明该对象所支持的操作和类型 IDL可以映射到多种语言 IDL compiler for C .idl IDL_stub.c IDL_skeleton.c .h return

37 类型 类似于许多程序设计语言中的类型 IDL C++ long (32), short (16) long, short
float (32), double (64) float, double char … char octet (8) unsigned char any string, struct, array, … char*, … object reference pointer or object interface class

38 Example of CORBA CDR message
(Common data representation) Person struct with value: {‘Smith’, ‘London’, 1934} index in sequence of bytes 4 bytes 0-3 5 4-7 “Smit” 8-11 “h___” 12-15 6 16-19 “Lond” 20-23 “on__” 24-27 1934 string string unsigned long don’t include type information

39 IDL例子 Module CORP typedef long BadgeNum; typedef long DeptNum;
enum DismissalCode {Dismiss_Fired, Dismiss_Quit} enum DenyApprovalReason {Reason, Codes}; struct PersonalData { } struct EmpData { } struct DeptInfo { } name phone site id personal_info job_class wage id name return

40 GO interface Employee; //forward declaration for interface interface Department { attribute DeptInfo DeptID readonly attribute Employee manager_obj; }; interface Employee { attribute EmpData personal_data; readonly attribute Department department_obj; void promote(in char new_job_class); void dismiss(in DismissalCode reason, in string description); void transfer(in Department new_dept_obj) }; return return

41 interface Manager : Employee
{ void approve-transfer(in Employee employee-obj, in Department current-department, in Department new-department ) raise(DENY_APPROVAL) context(“division”); }; interface Personnel : Employee { Employee hire(in EmpData employee_data, in Department department_obj, out BadgeNum new_employee_id); return

42 方向属性 in 参数 参数 out 参数 *参数 inout 参数 *参数
interface PersonnelManager : Personnel, Manager { void arbitrate( ); }; }; 方向属性 in 参数 参数 out 参数 *参数 inout 参数 *参数 Inherit: promote( ), transfer( ), dismiss( ); approve-transfer( ); hire( )

43 10.5 调用类型和通信方式 客户程序通常包括: 界面显示,接收输入 调用已定义对象上的操作 需选择 处理结果,显示结果等
P502 客户程序通常包括: 界面显示,接收输入 调用已定义对象上的操作 需选择 处理结果,显示结果等 两类调用和三种通信方式 桩类型调用 动态调用 同步 synchronous 单向 one-way 异步 deferred synchronous

44 10.5.1 桩类型调用 1. 调用形式 同步通信的调用形式 与RPC的不同 C++ :
对象引用 操作名(参数, *ev, 上下文对象引用) OO: 对象.方法名(参数) 与RPC的不同 Server must create a instance first. Client must get the object reference of the object pers_cs hire(tom_data, dept_cs, tom_id, &ev)

45 2. 桩类型调用步骤 3. 如何获取对象引用 编写获取调用所需的对象引用, 参数填写等 调用 处理结果, 包括异常情况处理代码 释放存区
go Server Personnel { … hire(参数) } 如何获得 pers_cs; …... pers_cs hire(tom_data, CS,… ); … … 客户方程序 pers_cs

46 tom_obj = pers_cs hire(tom_data, dept_cs, tom_id, &ev, )
通过调用某操作产生一对象引用。如, tom_obj = pers_cs hire(tom_data, dept_cs, tom_id, &ev, ) tom_obj promote(参数, &ev, ) CORBA应提供一种机制,使客户方能获得所需对象引用, 如第一个调用所需的对象引用。 类似于:域名 ——> IP地址 新对象引用 已有对象引用

47 10.5.2 对象获得 1. 抽象模型 对象目录:存储对象引用和一些可选择的描述 性数据。例如, 对象目录 查找 公布 客户机 服务器 使用
对象获得 1. 抽象模型 对象目录:存储对象引用和一些可选择的描述 性数据。例如, 对象目录 查找 公布 客户机 服务器 使用 对象引用 对象名

48 2. CORBA提供的服务 CORBA命名服务 <名字, 对象引用> CORBA交易对象服务
P500 CORBA命名服务 <名字, 对象引用> CORBA交易对象服务 <一系列属性, 对象引用 > 配置文件 对象引用 ---> 字符串 ---> 放入配置文件

49 4. CORBA naming service P517 Naming service client server ORB
object name object name & reference object reference client server ORB

50 使用命名服务 服务器调用对象目录中“命名上下文对象”中的bind(name, object)方法来公布对象
P517 服务器调用对象目录中“命名上下文对象”中的bind(name, object)方法来公布对象 客户机通过调用对象目录中“命名上下文对象”中的resolve(name)方法来查找对象 Interface NamingContext { void bind(in Name n, in Object obj); Object resolve(in Name n); } 通用对象

51 10.6 POA 1. Two key issues in CORBA
How do clients get object references? Naming service, configuration file, trading service How map implementations in various languages into CORBA object? Server - creates a object instance in a particular language, such as C++ (dynamic object, pointer) - registers the instance as a CORBA object via POA (object id)

52 2. Jobs for client and server
use an existing language (C, C++, Java,…) to implement objects and their methods (servant), create necessary instances. use POA’ operation to register the instance as a CORBA object, and return an CORBA identifier use naming service’ bind(name, object) to publish object name (and its object reference) Servant: is implementation of object, dependent of language

53 pers_cs = new Personnel; oid = poa ->activate_object (pers_cs);
// Create a new C++ object oid = poa ->activate_object (pers_cs); // Register C++ object as CORBA object NamingContext.bind(“personnel_cs”, oid) // Public object name and object reference Naming service Object reference Object name (IP address, port no.) oid personnel_cs

54 Servant Map pers_Math pers_CS var x, y = servant = C++ object C
function1( ) { … } function2( ) { … } C pers_Math C++ object pers_CS = servant = POA oid Naming service object name object reference

55 Client use naming service’ resolve(name) to get the required object reference do RMI Example: per_cs = NamingContext.resolve (“personnel_cs”) per_cs hire( . . .)

56 3. Functions of OA P153 adapt (register,包装) a program (server-side code) as a CORBA object generate object reference call a method of an object implement a specific activation policy for a group of objects: thread-per-object

57 GIOP (General Inter-ORB Protocol) IIOP (Internet Inter-ORB Protocol)
server client Corp server sale server per-cs per-cs hire(..) li ORB OA OA ORB GIOP (General Inter-ORB Protocol) IIOP (Internet Inter-ORB Protocol)

58 10.2 Distributed object in Java Java RMI
Distributed Systems Concepts and Design P208

59 1. Distributed object caller callee
invoke method on * define remote interface, remote object each method must throw handle remote remote exception exceptions * implement remote interface Features: a single language system need not use IDL no mapping IDL to implementation language

60 2. Example: shared whiteboard
C S C * maintain the current state of a drawing * keep a record of all shapes it has received inform(latest shape) get version number retrieve(latest shapes) ? CSCW = Computer Supported Cooperative Work

61 Define Remote interfaces Shape and ShapeList
import java.rmi.*; import java.util.Vector; public interface Shape extends Remote { int getVersion( ) throws RemoteException; GraphicalObject getAllState( ) throws RemoteException; } public interface ShapeList extends Remote { Shape newShape(GraphicalObject g) throws RemoteException; Vector allShape( ) throws RemoteException; int getVersion( ) throws RemoteException;

62 3. Parameter and result passing
Parameter is a remote object (i.e. interface) pass remote object reference Parameter is non-remote object object is copied and passed by value If the recipient doesn't’t possess the class of an object, its code is downloaded automatically (object is created)

63 4. RMI registry naming service client server client server object name
& reference object reference client server client server naming service

64 bind(“URL name”, remote obj.)
4. RMI registry remote object bind(“URL name”, remote obj.) lookup(URL name) remote obj. ref. RMIregistry client name remote object server bind(“//domain name:port/objName”, remote object) This service is not system-wide binding service. Clients must direct their lookup to particular hosts

65 Naming class of Java RMIregistry
P211 void rebind(String name, Remote obj) this method is used by a server to register the identifier of a remote object by name. void bind(String name, Remote obj) this is alternative way to rebind, but if the name is already bound to a remote object an exception is thrown void unbind(String name, Remote obj) Remote lookup(String name) String [ ] list( ) return an array of strings containing the names bound in the registry.

66 5. Server program server= main( ) + implement each of its remote interface main( ) create an instance of ShapeListServant object as remote one bind it to a name “Shape List” in RMIregistry ShapeListServant – implementation of ShapeList interface. implement newSpape which is used by clients to create a remote object (Shape); add it to its vector …… ShapeServant – implementation of Shape interface

67 class ShapeListServer with main method
public class ShapeListServer { public static void main(String args[ ]) { System.setSecurityManager(new RMISecurityManager()); try { ShapeList aShapeList = new ShapeListServant( ); Naming.rebind(“Shape List”, aShapeList); System.out.println(“server is ready”); } catch(Exception e) { System.out.println(“server main” + e.getMessage()); } Default security manager

68 class ShapeListServant implements interface ShapeList
public class ShapeListServant extends UnicastRemoteObject implements ShapeList { private Vector theList; private int version; public ShapeListServant( ) throws RemoteException {……} public Shape newShape(GraphicalObject g) throws RemoteException { version++; Shape s= new ShapeServant(g, version); theList.addElement(s); return s; } public Vector allShapes( ) throws RemoteException {……} public int getVersion ( ) throws RemoteException {……} }

69 class ShapeServant implements interface Shape
public class ShapeServant extends UnicastRemoteObject implements Shape { private int version; public ShapeServant(…) throws RemoteException {……} public getAllState( ) throws RemoteException {……} public int getVersion ( ) throws RemoteException {……} }

70 6. Client program import … public class ShapeListClient
{ public static void main(String args[ ]) { System.setSecurityManager(new RMISecurityManager()); ShapeList aShapeList = null; try { aShapeList = (ShapeList) Naming.lookup(“//bruno/Shape List”); Vector sList = aShapeList.allShapes( ); …} catch(RemoteException e) { System.out.println(e.getMessage());} catch(Exception e) { System.out.println(“Client:”+e.getMessage());} }

71 Summary 1. Goals interoperable in heterogeneous environment
2. How build up a distributed application 3. General organization of CORBA 4. Functions of OA 5. Object reference and naming service 6. Distributed object in Java and Java RMI 7. Difference between CORBA and Java

72 Project 3 Use Java or CORBA or DCOM to build up a distributed application, such as whiteboard, database application, … Requirement: the application must access database

73 IDL Implement RPC: CORBA: Java: (no IDL) }
func1(in int i, string s) func1(in int i, string s) {implement … } CORBA: interface name1 class name1Impl extends …name1POA { method1(in int i, …); { method1(in int i, …) method2(in param, …); {implement … } ……} method2( ……) …… Java: (no IDL) } interface name2 extends Remote class name2Servant extends … name2 { method1(int i, …) throw …; { method1(int i, …) throw … method2(param, …) throw …; {implement … } ……} method2(……) …… }

74 Stub and message RPC: CORBA: Java: C_stub S_stub func1(16,’abc,…)
IDL_stub Skeleton objRef.method1(…) Java: Serialization Deserialization int 16 string “abc” func1 16 3 a b c _ obj. ref. method1 P23 3 a b c obj. ref. method1 16 2, int i, sting s


Download ppt "10. Distributed object-based systems"

Similar presentations


Ads by Google