Upload
antonia-reeves
View
222
Download
0
Tags:
Embed Size (px)
Citation preview
CS551 - Lecture 151
CS551 Object Oriented Middleware (IV) Dynamic Requests (Chap. 6 of EDO)
Yugi Lee
STB #555(816) 235-5932
www.cstp.umkc.edu/~yugi
2CS551 - Lecture 15
OutlineOutline
• Dynamic Invocation– The CORBA Dynamic Invocation Interface– COM IDispatch Interfaces
• Reflection– The CORBA Interface Repository– The COM Type Library
• Designing Generic Applications– Using CORBA– Using COM
• Dynamic Invocation– The CORBA Dynamic Invocation Interface– COM IDispatch Interfaces
• Reflection– The CORBA Interface Repository– The COM Type Library
• Designing Generic Applications– Using CORBA– Using COM
3CS551 - Lecture 15
Why Dynamic Request?Why Dynamic Request?
• Sometimes clients need to be built before their server interfaces are defined
• They need to defer request definition until they are executed
• Examples:– Object browser– Generic bridges– Scripting language interpreter
• Sometimes clients need to be built before their server interfaces are defined
• They need to defer request definition until they are executed
• Examples:– Object browser– Generic bridges– Scripting language interpreter
4CS551 - Lecture 15
Motivating Example: Object BrowserMotivating Example: Object Browser
Use run-time type information to find out about object typesattribute names
Use dynamic invocation interfaces to obtain attribute values
5CS551 - Lecture 15
Motivating Example: Generic BridgeMotivating Example: Generic Bridge
Client
ORB CoreORB Core
Obj. Imp.
DSI DII
• Generic and request-level bridge• Generic and request-level bridge
6CS551 - Lecture 15
Motivating Example: ScriptingMotivating Example: Scripting
7CS551 - Lecture 15
CommonalitiesCommonalities
• Discovery of type information at run-time
• Use of type information to build client objects that can cope with any type of server objects
• Definition of object requests at run-time
• Requires two primitives from middleware:– Dynamic invocation interfaces– Reflection mechanisms
• Discovery of type information at run-time
• Use of type information to build client objects that can cope with any type of server objects
• Definition of object requests at run-time
• Requires two primitives from middleware:– Dynamic invocation interfaces– Reflection mechanisms
8CS551 - Lecture 15
Dynamic Requests: PrinciplesDynamic Requests: Principles
• Any object request has to identify
– server object
– operation name
– actual parameters
– data structure for operation result
• In Dynamic Requests:
– server object identified by object reference
– operation name identified by string
– actual parameters as list of name/value pairs
– operation result determined by an address
• Any object request has to identify
– server object
– operation name
– actual parameters
– data structure for operation result
• In Dynamic Requests:
– server object identified by object reference
– operation name identified by string
– actual parameters as list of name/value pairs
– operation result determined by an address
9CS551 - Lecture 15
DynamicInvocation DynamicInvocation
ClientStubsClientStubs
ORBInterface ORBInterface
Implementation SkeletonsImplementation Skeletons
ClientClient Object ImplementationObject Implementation
ORB CoreORB Core
ObjectAdapter ObjectAdapter
Dynamic Requests in CORBA Dynamic Requests in CORBA
10CS551 - Lecture 15
Dynamic Requests in CORBADynamic Requests in CORBA
• Dynamic invocation interface (DII) supports dynamic creation of requests (objects).
• Request objects have attributes for – operation name,
– parameters and
– results.
• Request objects have operations to – change operation parameters,
– issue the request and
– obtain the request results.
• Dynamic invocation interface (DII) supports dynamic creation of requests (objects).
• Request objects have attributes for – operation name,
– parameters and
– results.
• Request objects have operations to – change operation parameters,
– issue the request and
– obtain the request results.
11CS551 - Lecture 15
Dynamic Request in CORBADynamic Request in CORBA
:Client:Client
rrr:Requestr:Request
:Server:Server
Op()Op()
rr=create_request(…,”Op”,…)=create_request(…,”Op”,…)
addadd_arg()_arg()
invoke()invoke()
delete()delete()
12CS551 - Lecture 15
Dynamic Requests in COMDynamic Requests in COM
• COM often used with interpreted scripting languages (e.g. VBScript)
• Interpreters of these languages need to make dynamic requests.
• Dynamic Requests in COM are defined in the IDispatch interface
• Any COM server that implements IDispatch can be requested dynamically
• COM often used with interpreted scripting languages (e.g. VBScript)
• Interpreters of these languages need to make dynamic requests.
• Dynamic Requests in COM are defined in the IDispatch interface
• Any COM server that implements IDispatch can be requested dynamically
13CS551 - Lecture 15
Dynamic Request in COMDynamic Request in COM
:Client:Client :Server:Server
QueryInterface(IID_IDispatch)QueryInterface(IID_IDispatch)
GetIDsOfNames(“Op”)GetIDsOfNames(“Op”)
Invoke()Invoke()
Op()Op()
GetIDsOfNames(“Op”)GetIDsOfNames(“Op”)
:ITypeInfo:ITypeInfo
Invoke()Invoke()
14CS551 - Lecture 15
Dual InterfacesDual Interfaces
• Are accessible both via stubs and via dynamic invocation
• Example: Interface Player: [object,dual,uuid(75DA6450-DD0E-00d1-8B59-0089C73915CB]interface DIPlayer: IDispatch { [id(1),propget] HRESULT Name([out] BSTR val); [id(2),propget] HRESULT Number([out] short val); [id(3)] HRESULT book([in] Date val)};
• Interfaces have to be defined as dual!
• Are accessible both via stubs and via dynamic invocation
• Example: Interface Player: [object,dual,uuid(75DA6450-DD0E-00d1-8B59-0089C73915CB]interface DIPlayer: IDispatch { [id(1),propget] HRESULT Name([out] BSTR val); [id(2),propget] HRESULT Number([out] short val); [id(3)] HRESULT book([in] Date val)};
• Interfaces have to be defined as dual!
15CS551 - Lecture 15
Transparency of Dynamic InvocationTransparency of Dynamic Invocation
• In both COM and CORBA:
– Client programs have to be written differently Use of dynamic invocation interfaces is not transparent to client programmers
• In COM:
– Interfaces of server objects have to be designed as dual Use of dynamic invocation not transparent in server design
• In CORBA:
– Server objects are unaware of dynamic invocation Use of DII is transparent
• In both COM and CORBA:
– Client programs have to be written differently Use of dynamic invocation interfaces is not transparent to client programmers
• In COM:
– Interfaces of server objects have to be designed as dual Use of dynamic invocation not transparent in server design
• In CORBA:
– Server objects are unaware of dynamic invocation Use of DII is transparent
16CS551 - Lecture 15
Reflection PrinciplesReflection Principles
• How do clients discover attributes & operations that servers have?– capture type information during interface compilation– store type information persistently – provide an interface for clients to obtain type
information during run-time
• Reflection interfaces provided by– CORBA Interface Repository– COM Type Library
• How do clients discover attributes & operations that servers have?– capture type information during interface compilation– store type information persistently – provide an interface for clients to obtain type
information during run-time
• Reflection interfaces provided by– CORBA Interface Repository– COM Type Library
17CS551 - Lecture 15
CORBA Interface RepositoryCORBA Interface Repository
• Makes type information of interfaces available at run-time.
• Achieves type-safe dynamic invocations.• Supports construction of interface browser• Used by CORBA implementations themselves• Persistent storage of IDL interfaces in abstract
syntax trees (ASTs)
• Makes type information of interfaces available at run-time.
• Achieves type-safe dynamic invocations.• Supports construction of interface browser• Used by CORBA implementations themselves• Persistent storage of IDL interfaces in abstract
syntax trees (ASTs)
18CS551 - Lecture 15
• Interface repository persistently stores ASTs of IDL modules, interfaces, types, operations etc.
• Interface repository persistently stores ASTs of IDL modules, interfaces, types, operations etc.
module SoccerMgmt {
};
module SoccerMgmt {
};
ModuleDefModuleDef
SoccerMgmtSoccerMgmt
InterfaceDefInterfaceDef
PlayerPlayer
InterfaceDefInterfaceDef
TeamTeam
TypedefDefTypedefDef
PlayerListPlayerList
ExceptionDefExceptionDef
InvalidNumberInvalidNumber
AttributeDefAttributeDef
membersmembers
interface Player; interface Player; interface Team {
};
interface Team {
};
typedef sequence<Player> PlayerList; typedef sequence<Player> PlayerList; exception Invalid {}; exception Invalid {}; attribute ATMList ATMs; attribute ATMList ATMs;
OperationDefOperationDef
addadd void add(in short number, in Player p); raises(InvalidNumber)
void add(in short number, in Player p); raises(InvalidNumber)
Abstract Syntax Trees (ASTs)Abstract Syntax Trees (ASTs)
19CS551 - Lecture 15
ContainerContainer
AST Node TypesAST Node Types
IRObjectIRObject
ContainedContained
OperationDefOperationDef
ExceptionDefExceptionDef
TypedefDefTypedefDef AttributeDefAttributeDef
ConstantDefConstantDef
ModuleDefModuleDefInterfaceDefInterfaceDef RepositoryRepository
20CS551 - Lecture 15
COM Type LibraryCOM Type Library
• COM’s provision of run-time type information
• Raw information generated by MIDL compiler
• Stored in tokenized form (.TLB files)
• Main interfaces:
• COM’s provision of run-time type information
• Raw information generated by MIDL compiler
• Stored in tokenized form (.TLB files)
• Main interfaces:
ITypeLibITypeLib ITypeInfoITypeInfo11 00..*..*
21CS551 - Lecture 15
ITypeLibITypeLib
• Provides operations to browse through all interfaces contained in the type library– GetTypeInfoCount (returns number of TypeInfo
objects in the library)– GetTypeInfo (can be used to obtain type info at a
particular index number)
• Locate ITypeInfo objects using the GUIDs
• Provides operations to browse through all interfaces contained in the type library– GetTypeInfoCount (returns number of TypeInfo
objects in the library)– GetTypeInfo (can be used to obtain type info at a
particular index number)
• Locate ITypeInfo objects using the GUIDs
22CS551 - Lecture 15
ITypeInfoITypeInfo
interface ITypeInfo : IUnknown {
HRESULT GetFuncDesc( UINT index, FUNCDESC **ppFuncDesc);
HRESULT GetIDsOfNames( OLECHAR **rgszNames,
UINT cNames, DISPID *pMemId);
HRESULT GetNames(DISPID memid, BSTR *rgBstrNames,
UINT cMaxNames, UINT *pcNames);
HRESULT GetTypeAttr(TYPEATTR **ppTypeAttr);
HRESULT GetVarDesc(UINT index, VARDESC **ppVarDesc);
HRESULT Invoke(VOID *pvInstance, DISPID memid, USHORT
wFlags, DISPPARAMS *pDispParams,
VARIANT *pVarResult,
EXCEPINFO *pExcepInfo, UINT *puArgErr);
...
};
interface ITypeInfo : IUnknown {
HRESULT GetFuncDesc( UINT index, FUNCDESC **ppFuncDesc);
HRESULT GetIDsOfNames( OLECHAR **rgszNames,
UINT cNames, DISPID *pMemId);
HRESULT GetNames(DISPID memid, BSTR *rgBstrNames,
UINT cMaxNames, UINT *pcNames);
HRESULT GetTypeAttr(TYPEATTR **ppTypeAttr);
HRESULT GetVarDesc(UINT index, VARDESC **ppVarDesc);
HRESULT Invoke(VOID *pvInstance, DISPID memid, USHORT
wFlags, DISPPARAMS *pDispParams,
VARIANT *pVarResult,
EXCEPINFO *pExcepInfo, UINT *puArgErr);
...
};
23CS551 - Lecture 15
Static InvocationStatic Invocation
• Advantages:– Requests are simple to define.– Availability of operations checked by programming
language compiler.– Requests can be implemented fairly efficiently.
• Disadvantages:– Generic applications cannot be build.– Recompilation required after operation interface
modification.
• Advantages:– Requests are simple to define.– Availability of operations checked by programming
language compiler.– Requests can be implemented fairly efficiently.
• Disadvantages:– Generic applications cannot be build.– Recompilation required after operation interface
modification.
24CS551 - Lecture 15
Dynamic InvocationDynamic Invocation
• Advantages:
– Components can be built without having the interfaces they use,
– Higher degree of concurrency through deferred synchronous execution.
– Components can react to changes of interfaces.
• Disadvantages:
– Less efficient,
– More complicated to use and
– Not type safe!
• Advantages:
– Components can be built without having the interfaces they use,
– Higher degree of concurrency through deferred synchronous execution.
– Components can react to changes of interfaces.
• Disadvantages:
– Less efficient,
– More complicated to use and
– Not type safe!
25CS551 - Lecture 15
Key PointsKey Points
• Dynamic requests are used when static requests are not viable
• Dynamic requests supported by both CORBA and COM• Dynamic requests are unsafe• Reflection mechanisms provided by COM and CORBA
make dynamic requests safe• IDL compilers store type information persistently so that
reflection implementations can provide them
• Dynamic requests are used when static requests are not viable
• Dynamic requests supported by both CORBA and COM• Dynamic requests are unsafe• Reflection mechanisms provided by COM and CORBA
make dynamic requests safe• IDL compilers store type information persistently so that
reflection implementations can provide them