Upload
jonah-king
View
217
Download
5
Embed Size (px)
Citation preview
CS551 - Lecture 131
CS551 Object Oriented Middleware (II) (Chap. 4 of EDO)
Yugi Lee
STB #555(816) 235-5932
www.cstp.umkc.edu/~yugi
2CS551 - Lecture 13
OutlineOutline
• CORBA– CORBA Object Model– CORBA Interface Definition Language– CORBA Architecture
• COM– Common Object Model– Microsoft IDL– COM Architecture
• RMI– Java (RMI) Object Model– Interface Definition in Java– RMI Architecture
• CORBA– CORBA Object Model– CORBA Interface Definition Language– CORBA Architecture
• COM– Common Object Model– Microsoft IDL– COM Architecture
• RMI– Java (RMI) Object Model– Interface Definition in Java– RMI Architecture
3CS551 - Lecture 13
Who is the OMG?Who is the OMG?
• Non-profit organization with HQ in the US, representatives in United Kingdom, Germany, Japan, India, and Australia.
• Founded April 1989, more than 800 members.• Dedicated to creating and popularizing object-
oriented industry standards for application integration, e.g.– CORBA– ODMG-93– UML
• Non-profit organization with HQ in the US, representatives in United Kingdom, Germany, Japan, India, and Australia.
• Founded April 1989, more than 800 members.• Dedicated to creating and popularizing object-
oriented industry standards for application integration, e.g.– CORBA– ODMG-93– UML
4CS551 - Lecture 13
Goal of CORBAGoal of CORBA
• Support distributed and heterogeneous object request in a way transparent to users and application programmers
• Facilitate the integration of new components with legacy components
• Open standard that can be used free of charge
• Based on wide industry consensus
• Support distributed and heterogeneous object request in a way transparent to users and application programmers
• Facilitate the integration of new components with legacy components
• Open standard that can be used free of charge
• Based on wide industry consensus
5CS551 - Lecture 13
Application ObjectsApplication Objects
CORBAfacilitiesCORBAfacilities
CORBAservicesCORBAservices
DomainInterfacesDomain
Interfaces
Object Request BrokerObject Request Broker
Object Management ArchitectureObject Management Architecture
6CS551 - Lecture 13
Object Model and Interface DefinitionObject Model and Interface Definition
• Objects
• Types
• Modules
• Attributes
• Operations
• Requests
• Exceptions
• Subtypes
• Objects
• Types
• Modules
• Attributes
• Operations
• Requests
• Exceptions
• Subtypes
7CS551 - Lecture 13
OMG Interface Definition LanguageOMG Interface Definition Language
• Language for expressing all concepts of the CORBA object model
• OMG/IDL is– programming-language independent– orientated towards C++– not computationally complete
• Different programming language bindings are available
• Explanation of Model and Language by Example
• Language for expressing all concepts of the CORBA object model
• OMG/IDL is– programming-language independent– orientated towards C++– not computationally complete
• Different programming language bindings are available
• Explanation of Model and Language by Example
8CS551 - Lecture 13
Running ExampleRunning Example
Team
-name:string
+bookGoalies()
coaches 1..*
1..*Player
-name:string-Number:int
+book()
+transfer(p:Player)
Club
-noOfMembers:int-location:Address
Trainer
-name:string
Organization
#name:string
works forworks for
1 1..*usesuses
plays in
1 11..16
has1
*
+train()
9CS551 - Lecture 13
CORBA Object Model: ObjectsCORBA Object Model: Objects
• Each object has one identifier that is unique within an ORB
• Multiple references to objects
• References support location transparency
• Object references are persistent
• Each object has one identifier that is unique within an ORB
• Multiple references to objects
• References support location transparency
• Object references are persistent
10CS551 - Lecture 13
CORBA Object Model: TypesCORBA Object Model: Types
typedef struct _Address {
string street;
string postcode;
string city;
} Address;
typedef sequence<Address> AddressList;
interface Team { ... };
typedef struct _Address {
string street;
string postcode;
string city;
} Address;
typedef sequence<Address> AddressList;
interface Team { ... };
Atomic typesAtomic types
Object typeObject type
Constructed typesConstructed types
11CS551 - Lecture 13
CORBA Object Model: ModulesCORBA Object Model: Modules
module Soccer { typedef struct _Address { string street; string postcode; string city; } Address;};module People { typedef struct _Address { string flat_number; string street; string postcode; string city; string country; } Address;};
module Soccer { typedef struct _Address { string street; string postcode; string city; } Address;};module People { typedef struct _Address { string flat_number; string street; string postcode; string city; string country; } Address;};
ModulesModulesSoccer::AddressSoccer::Address
People::AddressPeople::Address
12CS551 - Lecture 13
CORBA Object Model: AttributesCORBA Object Model: Attributes
interface Player;
typedef sequence<Player> PlayerList;
interface Trainer;
typedef sequence<Trainer> TrainerList;
interface Team {
readonly attribute string name;
attribute TrainerList coached_by;
attribute Club belongs_to;
attribute PlayerList players;
...
};
interface Player;
typedef sequence<Player> PlayerList;
interface Trainer;
typedef sequence<Trainer> TrainerList;
interface Team {
readonly attribute string name;
attribute TrainerList coached_by;
attribute Club belongs_to;
attribute PlayerList players;
...
};
Attribute typeAttribute type Attribute nameAttribute name
changeablechangeable
Clients cannotchange valueClients cannotchange value
13CS551 - Lecture 13
CORBA Object Model: OperationsCORBA Object Model: Operations
interface Team {
...
void bookGoalies(in Date d);
string print();
};
interface Team {
...
void bookGoalies(in Date d);
string print();
};
Parameter listParameter list
Parameter kindParameter kind
Parameter typeParameter typeParameter nameParameter nameOperation name
used in requestsOperation nameused in requests
Return typesReturn types
14CS551 - Lecture 13
CORBA Object Model: RequestsCORBA Object Model: Requests
• Requests are defined by client objects
• Request consist of– Reference of server object– Name of requested operation– Actual request parameters– Context information
• Request is executed synchronously
• Requests can be defined – statically– dynamically
• Requests are defined by client objects
• Request consist of– Reference of server object– Name of requested operation– Actual request parameters– Context information
• Request is executed synchronously
• Requests can be defined – statically– dynamically
15CS551 - Lecture 13
CORBA Object Model: ExceptionsCORBA Object Model: Exceptions
• Generic Exceptions (e.g. network down, invalid object reference, out of memory)
• Type-specific Exceptions
• Generic Exceptions (e.g. network down, invalid object reference, out of memory)
• Type-specific Exceptions
exception PlayerBooked{sequence<Date> free;}; interface Team { ... void bookGoalies(in Date d) raises(PlayerBooked); };
exception PlayerBooked{sequence<Date> free;}; interface Team { ... void bookGoalies(in Date d) raises(PlayerBooked); };
Exception dataException data
Operations declareexceptions they raiseOperations declareexceptions they raise
Exception nameException name
16CS551 - Lecture 13
CORBA Object Model: SubtypesCORBA Object Model: Subtypes
interface Organization { readonly attribute string name; };interface Club : Organization { exception NotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raises NotInClub; };
interface Organization { readonly attribute string name; };interface Club : Organization { exception NotInClub{}; readonly attribute short noOfMembers; readonly attribute Address location; attribute TeamList teams; attribute TrainerList trainers; void transfer(in Player p) raises NotInClub; };
Inherited by ClubInherited by Club
SupertypeSupertype
Implicit supertype:ObjectImplicit supertype:Object
17CS551 - Lecture 13
One standardised interface
One interface per object operation
ORB-dependent interfaceOne interface per object adapter
DynamicInvocation DynamicInvocation
ClientStubsClientStubs
ORBInterface ORBInterface
Implementation SkeletonsImplementation Skeletons
ClientClient Object ImplementationObject Implementation
ORB CoreORB Core
ObjectAdapter ObjectAdapter
CORBA Architecture CORBA Architecture
18CS551 - Lecture 13
Goals of COMGoals of COM
• Provide a component object model that facilitates binary encapsulation and binary compatibility– Binary encapsulation: Clients do not have to be re-
compiled if server objects change– Binary compatibility: Client and server objects can be
developed with different development environments and in different languages
• COM is proprietary de-facto standard
• Provide a component object model that facilitates binary encapsulation and binary compatibility– Binary encapsulation: Clients do not have to be re-
compiled if server objects change– Binary compatibility: Client and server objects can be
developed with different development environments and in different languages
• COM is proprietary de-facto standard
19CS551 - Lecture 13
Object Model and Interface DefinitionObject Model and Interface Definition
• Interfaces
• Implementations and Objects
• Classes
• Attributes
• Operations
• Requests
• HRESULTS
• Inheritance
• Interfaces
• Implementations and Objects
• Classes
• Attributes
• Operations
• Requests
• HRESULTS
• Inheritance
20CS551 - Lecture 13
Microsoft IDL (MIDL)Microsoft IDL (MIDL)
• Language for expressing all COM concepts• MIDL is
– programming-language independent– evolved from OSF/RPC IDL– not computationally complete
• Different programming language bindings are available• Explanation of Model and Language by same example
• Language for expressing all COM concepts• MIDL is
– programming-language independent– evolved from OSF/RPC IDL– not computationally complete
• Different programming language bindings are available• Explanation of Model and Language by same example
21CS551 - Lecture 13
COM InterfacesCOM Interfaces
[object,
uuid(1CF2B120-547D-101B-8E65-08002B2BD118)]
interface IOrganization : IUnknown {
...
};
[object,
uuid(1CF2B120-547D-101B-8E65-08002B2BD116)]
interface IClub : IOrganization {
...
};
[object,
uuid(1CF2B120-547D-101B-8E65-08002B2BD118)]
interface IOrganization : IUnknown {
...
};
[object,
uuid(1CF2B120-547D-101B-8E65-08002B2BD116)]
interface IClub : IOrganization {
...
};
UUIDUUID
InterfacesInterfaces
Interface InheritanceInterface Inheritance
Root InterfaceRoot Interface
22CS551 - Lecture 13
COM ImplementationsCOM Implementations
• Implement Interface in Prog. Lang., e.g. C++• Implement Interface in Prog. Lang., e.g. C++#include "Soccer.h"class Player : public IPlayer { private: char* name; short Number; protected: virtual ˜TrainerPlayer(void); public: TrainerPlayer(void); IMPLEMENT_UNKNOWN(TrainerPlayer) BEGIN_INTERFACE_TABLE(TrainerPlayer) IMPLEMENTS_INTERFACE(ITrainer) IMPLEMENTS_INTERFACE(IPlayer) END_INTERFACE_TABLE(TrainerPlayer) void book(); // IPlayer methods};
#include "Soccer.h"class Player : public IPlayer { private: char* name; short Number; protected: virtual ˜TrainerPlayer(void); public: TrainerPlayer(void); IMPLEMENT_UNKNOWN(TrainerPlayer) BEGIN_INTERFACE_TABLE(TrainerPlayer) IMPLEMENTS_INTERFACE(ITrainer) IMPLEMENTS_INTERFACE(IPlayer) END_INTERFACE_TABLE(TrainerPlayer) void book(); // IPlayer methods};
23CS551 - Lecture 13
COM: ObjectsCOM: Objects
• Instances of COM Implementations
• References to COM objects are called interface pointers
• Interface pointers refer to main memory locations
• References support location transparency
• Object references are persistent
• Instances of COM Implementations
• References to COM objects are called interface pointers
• Interface pointers refer to main memory locations
• References support location transparency
• Object references are persistent
24CS551 - Lecture 13
COM ClassesCOM Classes
• Named implementations
• Have one or several interfaces
• Are the principal mechanism to create COM objects
• Can return interface pointers to specific COM objects
• Named implementations
• Have one or several interfaces
• Are the principal mechanism to create COM objects
• Can return interface pointers to specific COM objects
25CS551 - Lecture 13
implementsimplements
1..*1..*
1..*1..*
InterfaceInterface
uuid : GUIDuuid : GUID
implementsimplements
instantiatesinstantiates 0..*0..*
11
ImplementationImplementation
1..*1..*
instantiatesinstantiates
1111
ClassClass
clsid : GUIDclsid : GUID
1..*1..*
0..*0..*
ObjectObject
location : intlocation : int
0..*0..*
11
creates&locatescreates&locates
ClassObjectClassObject
1111
0..*0..*
COM Objects, Interfaces and ClassesCOM Objects, Interfaces and Classes
26CS551 - Lecture 13
COM: AttributesCOM: Attributes
• COM does support attributes
• Attributes must be represented as set and get operations by the designer
• COM has a keyword to designate this
• Example:
• COM does support attributes
• Attributes must be represented as set and get operations by the designer
• COM has a keyword to designate this
• Example:
interface IOrganization : IUnknown { [propget] HRESULT Name([out] BSTR val);};
interface IOrganization : IUnknown { [propget] HRESULT Name([out] BSTR val);};
27CS551 - Lecture 13
COM: OperationsCOM: Operations
interface IClub : IOrganization { [propget] HRESULT NoOfMembers([out] short *val); [propget] HRESULT Address([out] ADDRESS *val); [propget] HRESULT Teams([in] long cMax, [out] long *pcAct, [out,size_is(cMax),length_is(*pcAct)] ITeam *val); [propput] HRESULT Teams([in] long cElems, [in,size_is(cElems)] ITeam *val); [propget] HRESULT Trainers([out] ITrainer *val[3]); [propput] HRESULT Trainers([in] ITrainer *val[3]); HRESULT transfer([in] IPlayer *p);};
interface IClub : IOrganization { [propget] HRESULT NoOfMembers([out] short *val); [propget] HRESULT Address([out] ADDRESS *val); [propget] HRESULT Teams([in] long cMax, [out] long *pcAct, [out,size_is(cMax),length_is(*pcAct)] ITeam *val); [propput] HRESULT Teams([in] long cElems, [in,size_is(cElems)] ITeam *val); [propget] HRESULT Trainers([out] ITrainer *val[3]); [propput] HRESULT Trainers([in] ITrainer *val[3]); HRESULT transfer([in] IPlayer *p);};
Operation nameOperation name
Parameter listParameter listParameter kindParameter kind
Return value indicating success/failureReturn value indicating success/failure
Parameter, e.g.Interface pointerParameter, e.g.Interface pointer
28CS551 - Lecture 13
3131 30-2930-29 28-1628-16 15-015-0
COM: HRESULTSCOM: HRESULTS
• HRESULTS are 32-bit integers
• Structured into four fields
• HRESULTS are 32-bit integers
• Structured into four fields
SeverityCode
SeverityCode ReservedReserved
FacilityCode
FacilityCode
InformationCode
InformationCode
29CS551 - Lecture 13
COM Operation InvocationsCOM Operation Invocations
• Invocation is defined by client objects• Invocation determines
– Interface pointer of server object– Name of invoked operation– Actual parameters
• Invocation is executed synchronously• Invocation can be defined
– statically– dynamically
• Clients have to interpret HRESULTS!
• Invocation is defined by client objects• Invocation determines
– Interface pointer of server object– Name of invoked operation– Actual parameters
• Invocation is executed synchronously• Invocation can be defined
– statically– dynamically
• Clients have to interpret HRESULTS!
30CS551 - Lecture 13
Three Implementations of RequestsThree Implementations of Requests
Inter-process call withlight-weight RPC
Method call
Client Object
Local Object inIn-Process DLL
Local Objectin EXE Server
Object onRemote Host
Remote call withreal RPC
Inter-process call withlight-weight RPC
Method call
Client Object
Local Object inIn-Process DLL
Local Objectin EXE Server
Object onRemote Host
Remote call withreal RPC
31CS551 - Lecture 13
COM Architecture COM Architecture
ObjectObjectProxyProxy
COMCOMLibraryLibraryInterfaceInterface
proxyproxy
ClientClient
ObjectObjectstubstub
COMCOMLibraryLibraryInterfaceInterface
stubstub
SCMSCM
RegistryRegistry
SCMSCM
RegistryRegistry
OXIDOXIDResolverResolver
OXIDOXIDResolverResolver
Microsoft Microsoft RPCsRPCsOXIDOXIDObjectObject
ApplicationApplicationLayerLayer
PresentationPresentationLayerLayer
SessionSessionLayerLayer
ServerServer
ImplementationImplementation
COM ClassCOM Class
32CS551 - Lecture 13
COM Architecture
• Application Layer:
– Client object: has a pointer to an interface proxy
– an implementation of the interface and a COM class (creating new instances of the implementation and locate these instances)
• Presentation Layer: (un)marshalling
– (un)marshalling interface pointers and create an interface proxy for a requested interface (object proxy, object stub)
– (un)marshalling and unmarshalling the parameters of all operations contained in the interface (interface proxy, interface stub)
• Session Layer:
– object activation: SCM (Service Control Manager)
– the mapping of interface pointers to RPC bindings and references of server objects for remote method invocation, OXID (Object Exporter Identifier) resolver
33CS551 - Lecture 13
Goals of RMIGoals of RMI
• In Java 1.0 object communication confined to objects in one Virtual Machine
• Remote Method Invocation (RMI) supports communication between different VMs, potentially across the network
• Provide tight integration with Java
• Minimize changes to Java language/VM
• Work in homogeneous environment
• In Java 1.0 object communication confined to objects in one Virtual Machine
• Remote Method Invocation (RMI) supports communication between different VMs, potentially across the network
• Provide tight integration with Java
• Minimize changes to Java language/VM
• Work in homogeneous environment
34CS551 - Lecture 13
Java Object ModelJava Object Model
• Interfaces and Remote Objects
• Classes
• Attributes
• Operations
• Exceptions
• Inheritance
• Interfaces and Remote Objects
• Classes
• Attributes
• Operations
• Exceptions
• Inheritance
35CS551 - Lecture 13
Java Interfaces and Remote ObjectsJava Interfaces and Remote Objects
• Java already includes the concept of interfaces
• RMI does not have a separate interface definition language
• Pre-defined interface Remote
• Remote interfaces extend Remote
• Remote classes implement remote interfaces
• Remote objects are instances of remote classes
• Java already includes the concept of interfaces
• RMI does not have a separate interface definition language
• Pre-defined interface Remote
• Remote interfaces extend Remote
• Remote classes implement remote interfaces
• Remote objects are instances of remote classes
36CS551 - Lecture 13
Java Remote Interface ExampleJava Remote Interface Example
package soccer;interface Team extends Remote {public: String name() throws RemoteException; Trainer[] coached_by() throws RemoteException; Club belongs_to() throws RemoteException; Players[] players() throws RemoteException; void bookGoalies(Date d) throws RemoteException; void print() throws RemoteException;};
package soccer;interface Team extends Remote {public: String name() throws RemoteException; Trainer[] coached_by() throws RemoteException; Club belongs_to() throws RemoteException; Players[] players() throws RemoteException; void bookGoalies(Date d) throws RemoteException; void print() throws RemoteException;};
Remote operationsRemote operations
Interface nameInterface name
Declare it as remoteDeclare it as remote
Package namePackage name
37CS551 - Lecture 13
AttributesAttributes
• RMI does not attributes
• Attributes must be represented as set and get operations by the designer
• Example:
• RMI does not attributes
• Attributes must be represented as set and get operations by the designer
• Example:interface Club extends Organization, Remote {public: int noOfMembers() throws RemoteException; Address location() throws RemoteException; Team[] teams() throws RemoteException; Trainer[] trainers() throws RemoteException; ...};
interface Club extends Organization, Remote {public: int noOfMembers() throws RemoteException; Address location() throws RemoteException; Team[] teams() throws RemoteException; Trainer[] trainers() throws RemoteException; ...};
Attribute get operations
38CS551 - Lecture 13
Combining Classes and Remote InterfacesCombining Classes and Remote Interfaces
interface Organization { private: String name() RemoteException;};class Address { public: String street; String postcode; String city;};interface Club extends Organization, Remote { public: int noOfMembers() throws RemoteException; Address location() throws RemoteException; Team[] teams() throws RemoteException; Trainer[] trainers() throws RemoteException; void transfer(Player p) throws RemoteException;};
interface Organization { private: String name() RemoteException;};class Address { public: String street; String postcode; String city;};interface Club extends Organization, Remote { public: int noOfMembers() throws RemoteException; Address location() throws RemoteException; Team[] teams() throws RemoteException; Trainer[] trainers() throws RemoteException; void transfer(Player p) throws RemoteException;};
Club makes name() remotely accessibleClub makes name() remotely accessible
Club can return an address objectClub can return an address object
39CS551 - Lecture 13
Parameter PassingParameter Passing
• Atomic types are passed by value• Remote objects are passed by reference• Non-Remote objects are passed by value
• Atomic types are passed by value• Remote objects are passed by reference• Non-Remote objects are passed by value
class Address { public: String street; String postcode; String city;};interface Club extends Organization, Remote { public: Address location() throws RemoteException; ...};
class Address { public: String street; String postcode; String city;};interface Club extends Organization, Remote { public: Address location() throws RemoteException; ...};
returns a copy of the address!returns a copy of the address!
40CS551 - Lecture 13
ExceptionException
• Pre-Defined Exception RemoteException• Type-Specific Exceptions• Example:
• Pre-Defined Exception RemoteException• Type-Specific Exceptions• Example:
class PlayerBooked extends Exception {};interface Team extends Remote { public: ... void bookGoalies(Date d) throws RemoteException, PlayerBooked; ...};
class PlayerBooked extends Exception {};interface Team extends Remote { public: ... void bookGoalies(Date d) throws RemoteException, PlayerBooked; ...};
Type-specific ExceptionType-specific Exception
Operation declares that it may raise itOperation declares that it may raise it
41CS551 - Lecture 13
JAVA (RMI) ArchitectureJAVA (RMI) Architecture
ServerServerClientClient
StubStub RegistryRegistryInterfacesInterfaces
SkeletonSkeleton ActivationActivationInterfacesInterfaces
RMI Runtime (RMI Runtime (rmidrmid,rmiregistry,rmiregistry))
42CS551 - Lecture 13
Activation in Java Activation in Java
Client Host
StubFaultingReference
Liveref
Host www.bvb.de
Activa-tion ID
ActivatorActivation Descriptors:ActGroup ClassName URL InitAG1 Team www.bvb.de/…AG2 Player www.bvb.de/…AG2 Player www.bvb.de/…AG2 Player www.bvb.de/…
Java VM1 Java VM2
AG1 AG2
1: activate
2: create objectin VM
3: passobject ref
4: updatelive ref
43CS551 - Lecture 13
Key PointsKey Points
• CORBA, COM and RMI – enable objects to request operation execution from
server objects on remote hosts– identify server objects by object references– distinguish between interface and implementation– treat attributes as operations– provide mechanisms to deal with failures– have statically typed object models – compile stubs from their IDLs– support on-demand activation
• CORBA, COM and RMI – enable objects to request operation execution from
server objects on remote hosts– identify server objects by object references– distinguish between interface and implementation– treat attributes as operations– provide mechanisms to deal with failures– have statically typed object models – compile stubs from their IDLs– support on-demand activation