Distributed Objects by dffhrtcv3


									Distributed Objects
    背景
          Why, What, How
    一般框架
    CORBA
    Java RMI
    SOA
    小结

2012/5/4                    Institute of Computer Software   2
                                   Nanjing University
    本节ppt 有关CORBA部分内容从下列文献摘
          Bamshad Mobasher
              http://maya.cs.depaul.edu/~mobasher/classes/ds520/
          Douglas C. Schmidt
              http://www.cs.wustl.edu/~schmidt/corba.html

2012/5/4                       Institute of Computer Software       3
                                      Nanjing University
    分布式计算(Distributed computing)
          What:
              the process of running a single computational task on
               more than one distinct computer
                            -- from Wikipedia
              “The network is the computer”
          Why?
          How?
              实践表明,分布式应用系统的开发比集中式应用系统开
2012/5/4                       Institute of Computer Software          4
                                      Nanjing University
    Why?
          “世界是分布的”。
              有时将涉及的用户、应用、数据集中化不合适、不可行。
          资源共享
          并行处理
          冗余容错

2012/5/4              Institute of Computer Software   5
                             Nanjing University
                                 The Business Model
  Every application is part of your business model
         must make them work together!


                           Sales                      Accounting


Distributed Systems Frameworks                                      6
                                 The Problem
  Application Integration and Distributed Processing are the same
        Constructing information-sharing distributed systems from
         diverse sources:
                physically disparate

Distributed Systems Frameworks                                       7
          • Client – Server Computing

                     Client Code                         Server Code
                                 Stub                      Skeleton


                           Client: Thin or Fat?

Distributed Systems Frameworks                                         8
  Multi-Tier Systems

                                     Business Logic

               User Interface                                   Persistent Store

         separates persistence from logic and logic from presentation
         all activity originates in user interface
         arrows represent client-server relation

Distributed Systems Frameworks                                                     9

  Peer-to-Peer Systems


                                                         Persistent Store
  User Interface
 (mixed initiative)                  Monitor

                                                      Enterprise Applications

Distributed Systems Frameworks                                                  10
  Web Applications

               Firewall              HTTP Servers

                                     CGI / Servelets

                                                                   Data Store
         User Interface

         interaction initiated by user
         UI based on HTML, Java, Javascript, etc.
         CGI/Servelet composes HTML, forwards interaction requests to business logic

Distributed Systems Frameworks                                                          11
3 layers of a distributed application:
       network level (TCP/IP, network protocols)
       higher-level services (directory services, security protocols, etc.)
       application level
At the application level:
       processes
       threads
       objects: processes can be made up of one or more objects which can be
        accessed by one or more threads within the process
       agents: an “independent” functional element (e.g., in a banking application
        we may have a customer agent, a transaction agent, an information
        brokerage agent)

Distributed Systems Frameworks                                                  12
Partitioning and Distributing Data and Functions
      data-driven distribution
      functional distribution
      object-based distribution

Flexible, Extendible Communication Protocols
      allocation of tasks to agents has a direct influence on the
       complexity of the communication protocol (type of data,
       amount of data, persistence of connections)
      may also be dictated by legacy systems that need to be

Distributed Systems Frameworks                                       13
Multi-threading Requirements
      server object may need to service multiple remote clients at
      effective way to optimize resources

Security Requirements
      authentication of client identities
      define resource access levels
      data encryption

Distributed Systems Frameworks                                        14
    How?
          理想主义:Distributed Operating System
          现实主义:
              操作系统提供网络通信功能
              (中间件)
              分布应用程序

2012/5/4                Institute of Computer Software   15
                               Nanjing University
    Socket programming in Java
 // listen to port 5000 on the local host for socket
 connection requests
 ServerSocket s = new ServerSocket(5000);
 while (true) {
   // wait for connection request from client
   Socket clientConn = s.accept();
   InputStream in = clientConn.getInputStream();
   OutputStream out = clientConn.getOutputStream();
   // now IO streams are connected to client; do
 something with them...

2012/5/4             Institute of Computer Software    16
                            Nanjing University
// create the socket
InetAddress addr =
Socket s = new Socket(addr, 5000);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
// now we have IO streams to remote process;
do something with them...

 2012/5/4         Institute of Computer Software   17
                         Nanjing University
    Message Passing Libraries
          PVM, MPI
          Send/Recv, Multicast

    Virtual Shared Memory

2012/5/4                  Institute of Computer Software   18
                                 Nanjing University
    远程过程调用(RPC,Remote Procedure Call)
          让应用程序开发者可以
              象调用本地过程一样调用分布在远程节点上的过程
              将结构化方法用于分布环境
          实现上
              Request – response 消息传递模式
              provides a function-oriented interface to socket-level
               communications (sits on top of the TCP/IP transport

2012/5/4                        Institute of Computer Software          19
                                       Nanjing University
      General Pattern for Remote Invocation

                     Client Code                         Server Code
                                 Stub                       Skeleton


        Call:                                   Serve:
                 marshal arguments                   receive data
                 convert to network                  convert & unmarshal
                  format                              invoke method
                 locate server                       marshal return value
                 transmit data                       transmit data

Distributed Systems Frameworks                                                20
           Procedural API for Remote Invocation
 DCE (Distributed Computing Environment)
      OSF standard for RPC
      provides a common set of services
             Directory Services--Store the names of resources that are available
              within the distributed environment. The Cell Directory Service (CDS)
              supports naming within a cell, and the Global Directory Service (GDS)
              supports naming across all cells within an enterprise. GDS
              implements the X.500 directory service standard.
             Distributed File Service (DFS)--An optional DCE service that
              provides a seamless file system that operates across all computers
              contained within a cell.
             Distributed Time Service (DTS)--Used for synchronization.
             Security Service--Used for authentication and control access.
             DCE Threads--Similar to Java threads. They are lightweight
              processes that simplify the design of client/server applications.
Distributed Systems Frameworks                                                  21
    让应用程序开发者可以象使用本地对象一样使
    对象计算模型和分布计算模型的结合
          自然
              decentralized nature of dist. computing
              encapsulation required by distributed components
              information hiding requirements (location transparency,
               security, etc.)
          优越:

2012/5/4                       Institute of Computer Software       22
                                      Nanjing University
分布 对象
   Location Transparency


        Machine 1                                                Machine 2
                                   remote          Implementor

                        Distributed Systems Frameworks                       23
2012/5/4   Institute of Computer Software   24
                  Nanjing University

   Providing the same enhancements to procedural
    RPC toolkits that OO languages provide to
    conventional procedural languages
       实现对象计算的全面支持
           encapsulation, interface inheritance, object-based exception
       良好的软件组织
           promotes separation of interface from implementation
            (crucial for scalable distributed applications)
           甚至DbC

                              Distributed Systems Frameworks           25
                        Key Advantages of DOC
Enabling interworking between applications at a
 higher level of abstraction
      developing distributed applications using familiar
       techniques such as method calls on objects
      again, location transparency

Providing a foundation for building higher-level
 mechanisms that facilitate collaboration among
 services in distributed applications
      common object services (e.g., global naming, transactional
       messaging, quality of service facilities, etc.)

Distributed Systems Frameworks                                      26
    实现分布对象计算的几个核心概念
          接口
          对象引用
          参数传递
          相关服务设施
          底层通信协议

2012/5/4            Institute of Computer Software   27
                           Nanjing University
2012/5/4   Institute of Computer Software   28
                  Nanjing University
   allow clients to access objects regardless of
    implementation details
   allow object server flexibility in implementing objects
       existing services may be incorporated via wrappers
   platform-independent specification languages
       interface descriptions can be converted into server skeletons
        which can be compiled and implemented in any language
       some object interfaces also generate client stub interfaces.
   Examples:
       CORBA: Interface Definition Language (IDL)
       DCOM: Component Object Model language

                          Distributed Systems Frameworks                29
    对象通过相互引用来通信
          本地对象引用:仅在当前地址空间有效
          运行系统维护;
    远程对象引用
          不同地址空间?
          异构?
          生命周期?
    需要某种“对象管理器”来支持、维护之

2012/5/4             Institute of Computer Software   30
                            Nanjing University
对象管理器(Object Manager)
    The core of a distributed object system
    Manages object skeletons and object references on
     the server
    E.g., Object Request Broker (ORB) in CORBA or
     Registry Service in RMI
    When a client requests a new object, the object
        locates the skeleton for the class of the requested object
        creates new instance based on skeleton
        stores new object in the object storage
        sends a reference to the new object back to the client
                            Distributed Systems Frameworks            31
   Remote method calls by clients are routed by object
    manager to the proper object on the server
   Object manager may also destroy objects after clients
    are done
   Some other possible features of OM
       dynamic object activation/deactivation
       persistent objects

                          Distributed Systems Frameworks   32
Registration / Naming Service
    Acts as an intermediary between the object client and
     the object manager
    Once the interface to an object is defined, an
     implementation of the interface must be registered
     with the service so that it can be addressed by clients
    Through the naming service the client can specify
        the type of the object it needs
        or the name of a particular object, if it already exists

                             Distributed Systems Frameworks         33
   General protocol for handling remote object requests
   Must support a means of transmitting and receiving
    object and method references, and data in the form of
    objects or basic data types
   Ideally should be transparent to clients
       should interact with local object proxies (stubs) and let the
        object distribution scheme handle communication behind the

                          Distributed Systems Frameworks                34
                                  Registration                         Object           Object
                                    Service                           Skeleton          Storage

                                                                      Object Manager
                IDL Compilers

 Interface                                                          Naming Service

                                Client Stub

                                                                   Client Application
                                  Distributed Systems Frameworks
  Server Object
 Implementation                                  Object
                                                              4. Object
                    2. Resolve                                  Interactions

                          Object Manager Naming Service

       1. Request

                      3. Object                      Object
       Client           Handle                       Stubs

                    Distributed Systems Frameworks
               Comparing DOC Frameworks
 Distributed Object Computing Frameworks
         CORBA - Common Object Request Broker Architecture, an industry standard
          developed by OMG
         DCOM - Microsoft’s Distributed Component Object Model, a descendant of
          DCE RPC
         RMI - Java’s Remote Method Invocation

                  Cross          Cross   Complexity     Client     Server         Security
                 Platform        Lang.                Portability Portability
  CORBA               yes         yes     medium         high      medium       many options
  DCOM              limited       yes       high         low         low        NT security
  RMI                 yes         no        low          high        high         add-on

Distributed Systems Frameworks                                                                 37
OMG Reference Model

2012/5/4   Institute of Computer Software   38
                  Nanjing University
        Object Management Architecture
 Object Services
        Domain-independent foundational services for use by
         developers of implementation objects
        some published services:
                 Naming
                 Trading
                 Events
                 Transactions
                 Security

Distributed Systems Frameworks                                 39
        Object Management Architecture
 Common Facilities
        object services provide functionality for use by objects,
         CORBAfacilities provide standards for services used by
        generic functionality needed by many applications (e.g.,
         printing, document management, email, etc.)

Distributed Systems Frameworks                                   40
        Object Management Architecture
 Domain Interfaces
        provide domain-specific objects for vertical application
        Examples: Finance, Healthcare, Manufacturing,
         Telecom, Electronic Commerce, Transportation

 Application Interfaces
         Thus not standardized

Distributed Systems Frameworks                                      41
Common Object Request
Broker Architecture
    一个典型的分布对象计算架构
    The architecture
    对象 Objects and Clients
    接口 OMG IDL
    “对象管理器” ORB
    底层通信协议 IIOP
    其他

2012/5/4         Institute of Computer Software   42
                        Nanjing University
2012/5/4   Institute of Computer Software   43
                  Nanjing University
                Overview of CORBA Objects
 CORBA Object
        <identity, interface, implementation>
 CORBA objects differ from typical programming
  language objects:
         CORBA objects can be located anywhere on a network.
         CORBA objects (like Java objects) can run on any platform.
         CORBA objects can be written in any of several languages.
 CORBA object developers need know nothing of
  where their clients will be, what hardware or OS
  they will run on, or what language they will be
  written in.
         CORBA objects approach universal accessibility.

Distributed Systems Frameworks                                         44
                Overview of CORBA Objects
 An object implementation provides the
  semantics of the object, usually by defining data
  for the object instance and code for the object's
  methods. (called a “servant”)
 A client of an object has access to an object
  reference for the object, and invokes operations
  on the object.
         A client knows only the logical structure of the object according to its
          interface and experiences the behavior of the object through
         Client code has no knowledge of the implementation of the object or
          which ORB is used to access the implementation.

Distributed Systems Frameworks                                                       45
                                       Role of OMG IDL
                      Client Side                                            Object
                                                                       Implementation Side

                                       C                                    COBOL

                      C++                                                                  C
                                       IDL                                     IDL

                                 IDL                                                 IDL
           COBOL                                                                                 Ada
                          IDL                                                          IDL
                                             ORB                         ORB
                          IDL                      Internet InterORB                   IDL
                                                     Protocol (IIOP)                             Small
                                 IDL                                                 IDL          talk

                                       IDL                                     IDL

                      Small                                                                C++
                                  JAVA                                         JAVA

Distributed Systems Frameworks                                                                           46
                                 OMG IDL
 OMG Interface Definition Language (IDL):
        mappings for many languages/compilers;
        independent of any particular language/compiler;
        multiple-inheritance, public interface-structured
         specification language;
        not for implementation.
        primary support for interoperability between static and
         dynamic requests mechanisms.

Distributed Systems Frameworks                                     47
                                   OMG IDL
  IDL Structure
                                        Module auction {
        Module                           exception NotAllowed {};
                a namespace
                                            struct Sale {
        Interface                            int price;
                abstract type                string item;
                multiple inheritance       }
        Struct                             interface Auction {
                structured data              void bid (in long price)
                                                raises NotAllowed;

Distributed Systems Frameworks                                           48
                                           A Request
 A request consists of:
         Target object (target object identified by a unique object reference)
         Operation
         Parameters (the input, output and in-out parameters defined for the
          operation; may be specified individually or as a list)
         Optional request context

                                 Client                Object Implementation

                            Client Proxy                     Skeleton
                            (stub code)                        code


Distributed Systems Frameworks                                                    49
                       CORBA Framework Elements
 Object Request Broker (ORB)
         This is the object manager in CORBA

 Mechanisms for specifying interfaces
         Interface Definition Language (IDL) - for static interface definitions
         Dynamic Invocation Interface (DII) - lets clients access interfaces as
          first-class objects at run-time from an Interface Repository.

 Internet Inter-Orb Protocol (IIOP)
         A binary protocol for communication between ORBs.
         Was added in CORBA 2.0

Distributed Systems Frameworks                                                     50
                       Object Request Broker (ORB)
  The Object Manager in CORBA
  Both on the client side and the server side (allows user programs
   to act as both clients and servers of remote objects)
  On client side the ORB is responsible for
         accepting requests for a remote object
         finding implementation of the object
         accepting client-side reference to the remote object(converted to a language
          specific form, e.g., a Java stub object)
         routing client method calls through the object reference to the object
  On server side the ORB
         lets object servers register new objects
         receives requests from the client ORB
         uses object’s skeleton interface to invoke object’s activation method
         creates reference for new object and sends it back to client

Distributed Systems Frameworks                                                           51
         Internet Inter-Orb Protocol (IIOP)
  CORBA specification is neutral with respect to network protocols
         the CORBA standard specifies what is known as the General Inter-ORB Protocol (GIOP)
         GIOP is a high-level standard protocol for communication between ORBs
         not used directly; instead, it is specialized by a particular protocol that would then be
          used directly
  Internet Inter-ORB Protocol (IIOP)
         IIOP is the GIOP-based protocol for TCP/IP networks
         As of the 2.0 version of the CORBA specification, vendors are required to implement the
          IIOP protocol
  CORBA Networking Model
         CORBA applications are built on top of GIOP-derived protocols such as IIOP
         these protocols, in turn, rest on top of TCP/IP, DCE, or other underlying transport
          protocol the network uses
         an application architecture can be designed to use a bridge that would interconnect, for
          instance, DCE-based application components with IIOP-based ones.

Distributed Systems Frameworks                                                                       52
             Passing Objects by Reference
  In a distributed application, there are two possible methods for
   an application component to obtain access to an object in
   another process:
         When an object is passed by reference, the object itself remains "in place"
          while an object reference for that object is passed. Operations on the object
          through the object reference are actually processed by the object itself.
         When an object is passed by value, the object's state is copied and passed to its
          destination (via object serialization), where a new copy of the object is
          instantiated. Operations on that object's copy are processed by the copy, not by
          the original object.
         Note: in CORBA, objects are only passed by reference (however, the new
          CORBA specifications include facilities for passing objects by value).

Distributed Systems Frameworks                                                                53
                                 Object References
  An Object Reference is the information needed to specify an object
   within an ORB.
         The representation of an object reference handed to a client is only valid for the lifetime
          of that client.
         The language mapping also provides additional ways to access object references in a
          typed way for the convenience of the programmer.
         There is a distinguished object reference, the null reference, guaranteed to be different
          from all object references, that denotes no object. In Java, this is a Java null.
  To invoke a CORBA object, you need a reference for the object. There
   are two ways to get a reference for a CORBA object:
         from another object, such as a factory or a name service
         from a string that was specially created from an object reference
  Interoperable Object References
         CORBA uses IOR as a “pointer” to a specific instance of a class in a distributed
         encodes host, port, object identity
         may be externalized (using object_to_string)

Distributed Systems Frameworks                                                                          54
                             CORBA Components
  Client stub
         Each stub represents (it is a proxy) an object operation (a possible request) which a client
          invokes in a language-dependent manner (e.g., by calling a subroutine which represents
          the operation).
         The stubs make calls on the rest of the ORB using interfaces that are private to JavaIDL.
         Alternatively, a client may dynamically construct and invoke request objects which can
          represent any object operation.
  Implementation Skeleton
         Each skeleton provides the interface through which a method receives a request
          (dynamic and static skeletons)
  Object Adapter
         Purpose is to interface an object's implementation with its ORB
         Each object adapter provides access to those services of an ORB (such as activation,
          deactivation, object creation, object reference management) used by a particular type of
          object implementation.
  ORB Interface
         The interface to the small set of ORB operations common to all objects, e.g., the
          operation which returns an object's interface type.
Distributed Systems Frameworks                                                                        55
                             CORBA Components

                                 Client                                   Object Implementation

              Dynamic             Client                                   Implementation       Object
             Invocation           Stubs                                      Skeletons          Adapter

                                                          ORB Core

                                     standard interface                     Proprietary ORB interface

                                     One interface per object adaptor        Normal call interface
                                     One interface per object operation      Up call interface

Distributed Systems Frameworks                                                                            56
                                       Client Side
                           Clients perform requests using object references.

                                                      Clients may issue requests through
                                                      object interface stubs (static) or
                          Client                      dynamic invocation interface.

                                                           Clients may access general ORB
          Dynamic           Client          ORB
                                                                • Interface Repository.
         Invocation         Stubs         Interface             • Context Management.
                                                                • List Management.
                                                                • Request Management.

Distributed Systems Frameworks                                                              57
                                 Implementation Side
                Implementations receive requests through skeletons (without
                knowledge of invocation approach).

                                               Object Implementation

                                   ORB         Implementation    Object
                                 Interface       Skeletons       Adapter

                                   The Object Adapter provides for:
                                       • management of references;
                                       • method invocation;
                                       • authentication;
                                       • implementation registration;
                                       • activation/deactivation.

Distributed Systems Frameworks                                                58
                Static v. Dynamic Invocation
  Static Invocation
         Static interfaces are generated in form of client stubs by the IDL (pre-)
         This means that the structure of the object has to be known before hand (at
          compile time).
         Allows for better type checking; less runtime overhead; self-documentation.

  Dynamic Invocation
         Dynamic Invocation Interface (DII) allows clients to invoke operations on
          remote objects without having access to object stubs (another way to do this
          without dynamic invocation is to download static client stubs via a Java applet).
         Clients must discover interface-related information at runtime (e.g., using the
          interface repository)
         Servers can offer new services anytime without the need for recompilation on
          the client side.

Distributed Systems Frameworks                                                            59
                                 Dynamic Requests
  The Dynamic Invocation Interface (DII) allows clients to
             discover objects;
             discover objects’ interfaces;
             create requests;
             invoke requests;
             receive responses.
  Major features of Dynamic Invocation Interface:
         requests appear as objects themselves;
         requests are reusable;
         invocation may be synchronous or asynchronous;
         requests may be generated dynamically, statically or in combination approach.

Distributed Systems Frameworks                                                            60
                CORBA Interface Repository
  The Interface Repository is a service that provides persistent
   objects that represent the IDL information in a form available
   at runtime.
         Note: The JavaIDL runtime does not include an implementation of an Interface
          Repository and one is not generally required by clients at runtime.
         Using the IR, it is possible for a program to encounter an object whose
          interface was not known at compile time, yet be able to determine what
          operations are valid on the object and make invocation on it.
  Interface Repository provides:
         Dynamic client access to interface definitions to construct a request.
         Dynamic type-checking of request signatures.
         Traversal of inheritance graphs.
         ORB-to-ORB interoperability.

Distributed Systems Frameworks                                                       61
    CORBA Implementation Repository
  The Implementation Repository contains information that allows the
   ORB to locate and activate implementations of objects.
  Ordinarily, installation of implementations and control of policies
   related to the activation and execution of object implementations is
   done through operations on the Implementation Repository.
  In addition to its role in the functioning of the ORB, the
   Implementation Repository is a common place to store additional
   information associated with implementations of ORB objects. (e.g.,
   debugging information, administrative control, resource allocation,
   security, etc)
  The Implementation Repository supports the implementation of object
   servers. It is not needed by clients in order to access servers.

Distributed Systems Frameworks                                        62
            Summary of CORBA Interfaces
                                 IDL Interface                              Implementation
                                  Definitions                                 Installation

                Interface                                                       Implementation
               Repository                        Client    Implementation         Repository
                                                 Stubs       Skeletons

         Accesses                     Includes            Includes                       Describes

                                  Client                         Object Implementation

         All objects are defined in IDL by specifying their interfaces.
         Object definitions (interfaces) are manifested as objects in the Interface
          Repository, as client stubs, and as implementation skeletons.
         Descriptions of object implementations are maintained as objects in the
          Implementation Repository.

Distributed Systems Frameworks                                                                       63
Summary: CORBA Remote Method Invocation
  Clients use “object interfaces” through language mapping
         Java clients should work on any ORB that supports the Java language bindings.
         Clients can call any object instance remotely, so long as the object instance
          implements the interface.

  Clients can call remote objects statically or dynamically
         The server cannot tell whether the client is using static or dynamic invocation.

  Objects are identified using a unique id: Interoperable Object
   Reference (IOR)
         CORBA normally passes objects by reference
         IOR was Introduced in CORBA 2.0
         Object references can be converted to strings and back to “live” objects via
          ORB interface functions.

Distributed Systems Frameworks                                                               64
Java distributed object model
    Remote Method Invocation
    Java语言之内,充分利用这一点!
          Stub可下载!
          可以传“对象”!
          Garbage Collection!
    传“引用”
          java.rmi.Remote (RemoteException)

2012/5/4                   Institute of Computer Software   65
                                  Nanjing University
2012/5/4   Institute of Computer Software   66
                  Nanjing University
    Identity 语义问题
          两个指向同一远程对象的proxies???

    Self-inflicted deadlocks
          通常Java线程获得某锁后,可任意多次再获此锁
              实现上记录线程号,并对获锁次数计数
              但线程号仅在本地有效!
          分布情况下???

2012/5/4              Institute of Computer Software   67
                             Nanjing University
Web Services 和 SOA
    Web Service
          URI标记
          XML消息访问(SOAP)
          XML接口描述(WSDL)
          UDDI注册发表 查询

    比分布对象模型更为“松耦合”

2012/5/4           Institute of Computer Software   68
                          Nanjing University
Web Services 和 SOA
    SOA:面向Internet开放网络环境的松耦合计算模型
          “Software as a service”
          平台独立性
          业务流程显式化
    Orchestration 与 Choreography
          BPEL
          WS-CDL
    Semantic web service ??

2012/5/4                   Institute of Computer Software   69
                                  Nanjing University
    分布计算
    分布对象计算
          Principles
          does inheritance matter?
    CORBA 与 RMI
    “Web Service”

2012/5/4                   Institute of Computer Software   70
                                  Nanjing University

To top