1 / 40

CSIS0402 System Architecture Distributed Computing - Middleware Technology (2)

CSIS0402 System Architecture Distributed Computing - Middleware Technology (2). K.P. Chow University of Hong Kong. Object Middleware. Calling an operation of an object that resides in another system Object in another system is accessed through the object reference Processing steps:

zack
Download Presentation

CSIS0402 System Architecture Distributed Computing - Middleware Technology (2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSIS0402 System Architecture Distributed Computing - Middleware Technology (2) K.P. Chow University of Hong Kong

  2. Object Middleware • Calling an operation of an object that resides in another system • Object in another system is accessed through the object reference • Processing steps: • Get a reference to an object • Call an operation of the object • E.g. AccountRef = AccountSet.GetAccount(012345678); AccountRef.GetNameAndBalance(…); // print account’s detail … // debit the account AccrountRef.Debit(100); RPC: GetNameAndBalance(012345678, Name, Balance); // print account’s detail Debit(012345678,100);

  3. How to obtain an object reference? Possible approaches: • A special object reference is returned to the client when it first connected to the middleware • The client calls a special “naming” service (directory) with a name, and the directory returns the object reference • The client requests that a new object of a certain class is created (through the object factory) and the new object reference is returned • An operation on one object returns a reference to another object

  4. Object Middleware Compilation and Interpretation Client Server Similar to RPC: • Operation is declared in IDL • IDL generates stubs and skeletons Stub Skeleton Compiled Runtime Environment Interface Definition Language (IDL) Unlike RPC: • Operations can be called through an interpretative interface Interface Repository Stub Skeleton Interpreted Runtime Environment

  5. Why use object middleware instead of RPC? • Object middleware fits naturally with object-oriented languages: data and logic are in the object • Object middleware is more flexible: • Interface is de-linked from the program, e.g. an interface can be implemented by many servers • Updates to interface can be incremented, i.e. a server object can keep both the old and the new interfaces simultaneously • Force the programmer writing the client to think about state in the server

  6. Object Middleware Technologies • CORBA • Object can last for ages • One can convert a CORBA object reference to a string and send the string to somebody else, the recipient can write a program that convert the string back to an object reference and calls the object • COM/DCOM • COM object is pinned to a memory location and belongs to an active object • Object is automatically deleted when reference count to the object is 0 • Java RMI (Remote Method Invocation)

  7. CORBA • A standard, not a product; developed by OMG (Object Management Group, a consortium of major software vendors and user organizations) • Common Object Request Broker Architecture • CORBA model: DI: Dynamic InvocationOI: ORB InterfaceSIS: Static IDL SkeletonDS: Dynamic IDL Skeleton Object Implementation Client DS D I SIS IDL Stub O I O I Object Adapter ORB Core ORB Core IIOP

  8. CORBA Structure • CORBA defines GIOP (General Inter-ORB Protocol), IIOP is GIOP over TCP/IP • CORBA client programming: • Initialization • Obtain object reference • Call operations on object reference • ORB is also an object • Many services, naming, event notification, transaction, … • 2 kinds of interfaces: • Compiled interface: IDL is used to create the IDL stub for client and Static IDL skeleton for the server, stub and skeleton are used to marshal the parameters • Interpreted interface: client use Interface Repository to find out about the interface, server uses Dynamic Skeleton for interpreted interface

  9. Compiled Interface // Interface definition interface ThisOrThatServer { string doThis(in string what); string doThat(in string what); }; public interface ThisOrThatServer extends org.omg.CORBA.Object { String doThis(String what); String doThat(String what); } public classThisOrThatServerImpl extends _ThisOrThatServerImplBase { public ThisOrThatServerImpl() { } public String doThis(String what) { return doSomething(“this”, what); } public String doThat(String what) { return doSomething(“that”, what); } private String doSomething(String todo, String what) { … } } idltojava ThisOrThatServer // client implementation objRef = object referemce of the target object; objRef.doThis(“what”);

  10. Java RMI • RMI is a java-specific version of a CORBA framework • An object on one system can call a method in an object somewhere else on the network Client Server Stub Skeleton Client method calls into local stub Skeleton calls server method • RMI characteristics: • Objects are sent between client and server across the network • Type of the object arguments are sent with the data • If class doesn’t exist on the receiving side, the class object is also loaded over the network (mobile code)

  11. COM – Component Object Model • From Microsoft, a standard for components • Designed to support OLE: Object Linking and Embedding Technology • A COM component: a separate code file that has one or more object interfaces (not source, and can be written in any language) • To start a COM component, the client needs to supply: • Class ID (CLSID): 128-bit integer, used to search the registry for the component’s code file and initiates it if needed • Interface ID (IID): 128 integer, use to identify the required interface • Both can be generated by the system • When an object is created, an interface pointer is returned of type IID • Details to be discussed

  12. What is COM? • A distributed object architecture • Objects can be written in any language, adhere to a few rules, the objects will be able to communicate with client applications that want to use them and with one another across process and network boundaries • Object exports its functionalities by interfaces, which are groups of logically related functions • Example in C++ class ICalc { public: virtual Add()=0; virutal Subtract()=0; }; class IFinancial { public: virtual GetMortgagePayment()=0; virtual GetPrimeRate()=0; }; class CalcObject: public ICalc, public IFinancial { };

  13. Interface • Act as a contract between client and object: all methods declared in the interface must be defined • Clients can think about objects as black boxes that support one or many interfaces • Server object can implement the functions any way it chooses Add() IUnknown Subtract() ICalc ComCalc IFinancial GetMortgagePayment() GetPrimeRate()

  14. COM object Client Origin of COM Interfaces stub proxy • RPC • Proxy: an entity that stands in for something else and appears to a client to be an actual instance of that something else • Stub: proxy’s packaged information is unpackaged by an entity called stub on the server • RPC IDL: • IDL compiler (MIDL.EXE) generates C code from an .IDL file, generates code defines a proxy and stub • E.g. [ uuid (C2557720-CA46-1067-B31C-00DD010662DA), ] interface Calc { int Add([in] int x, [in] int y); int Subtract([in] int x, [in] int y); }

  15. COM and RPC • Today’s COM is built on RPC • Additional features: • Support for languages other than C • Support for objects, not just flat, ANSI-C style functions • Capability to automatically find and run server when client requests it • MS implementation: type library (TLB file) • a universal, binary header file • a compiled, tokenized form of an IDL file • contains all the function prototypes, interface definitions, coclasses • can be parsed and read by an application or development environment using Win32 functions • used for marshalling, i.e. construct the proxy and stubs necessary for communication • does not need to compiled into the client and server: COM read the type library at runtime

  16. COM object definition in C++ (1) import “oaidl.idl”; import “ocidl.idl”; [ object, uuid(638094E5-758F-11d1-8366-0000E83B6EF3), dual, … ] interface ICalc : IUnknown { [id(1), helpstring(“method Add”)] HRESULT Add([in] int x, [in] int y, [out,retval] int *r); [id(2), helpstring(“method Divide”)] HRESULT Divide([in] int x, [in] int y, [out,retval] int *r); };

  17. COM Object definition in C++ (2) [ uuid(638094E0-758F-11d1-8366-0000E83B6EF3), version(1.0), helpstring(“calcsdk 1.0 Type Library”) ] library COMCALCLib { importlib(“stdole32.tlb”); importlib(“stdole2.tlb”); [ uuid(638094E0-758F-11d1-8366-0000E83B6EF3), helpstring(“Calc Class”) ] coclass CalcSDK { [default] interface ICalc; }; }; C++ class implements ICalc interface

  18. C++ Implementation #include “comcalc.h” class CalcSDK: public ICalc { public: STDMETHODIMP QueryInterface(REFIID riid, void **ppv); STDMETHODIMP _(ULONG) AddRef(void); STDMETHODIMP _(ULONG) Release(void); STDMETHOD(Add)(int x, int y, int *r) { *r = x + y; return S_OK; } STDMETHOD(Subtract)(int x, int y, int *r) { *r = x - y; return S_OK; } ComCalc() { }; };

  19. What is IUnknown? • All interfaces must inherit from IUnknown • IUnknown contains 3 methods: • QueryInterface(): to enable clients to get one or many interfaces from objects • AddRef(): to control lifetime of the objects • Release() • Example: const GUID CLSID_Calc = {0x638094e0, 0x758f, 0x11d1, {0x83,0x66,0x00,0x00,0xe8,0x3b,0x6e,0xf3} }; const GUID IID_ICalc = {0x638094e5, 0x758f, 0x11d1, {0x83,0x66,0x00,0x00,0xe8,0x3b,0x6e,0xf3} }; const GUID IID_IFinancial = { … }; ICalc *pICalc; IFInancial *PIFin;

  20. What is IUnknown? (cont) // create an instance of the object whose GUID is CLSID_Calc and get me // the interface of the object whose GUID is IID_ICalc and put that // interface in variable pICalc CoCreateInstance(CLSID_Calc,NULL,CLSCTX_ALL,IID_ICalc, (void **)&pICalc); int result = pICalc->Add(1,2); pICalc->QueryInterface(IID_IFinancial, (void **)&pIFin); float rate = pIFin->GetPrimeRate(); pICalc->Release(); pIFin->Release(); Add() IUnknown Subtract() ICalc ComCalc IFinancial GetMortgagePayment() GetPrimeRate()

  21. Dynamic Link Libraries (DLL) • In early Windows, DLLs were groupings of functions that could be loaded into an application when the application wanted them, and discarded when no longer needed, allowed EXEs to be smaller • A binary standard: sources can be written in any language and compiled into DLLs, which can be interoperable: clean up the call stack, list exported functions, … • COM DLL: • Other names for COM DLL: OCX, ActiveX Component, ActiveX Control, ActiveX server • Repositories for COM objects (COM object is the actual implementation of a specific coclass in a type library) • A DLL can contain many objects • A DLL also has a .TLB file (type library): describes the objects and interfaces

  22. COM DLL • Example: 2 coclasses and its type library IUnknown Resource Section ISomeInterface coclass1 Type Library IUnknown IOtherInterface coclass2

  23. Registry and Self-Registration • Type library and component are 2 separate things, how can COM associate the two? • Self-registration: COM object needs to know how to put the entries in the Registry, which can then be used later • How COM DLL put the entry in the registry? (DLLs are loaded and acted upon by a host process (EXE)) • 2 approaches: manually or use utility regsvr32.exe, e.g. • regsvr32.exe comcalc.dll

  24. COM and Virtual Table • Virtual Table: • Also called vtable, used in C++ for dynamic binding • An array of pointers to virtual function • Used in COM to implement interface COMCalc: ICalc, IFinancial QueryInterface() AddRef() Address of ICalc vtable COM Interface Release() Address IFinancial vtable Add () QueryInterface() Subtract () AddRef() ICalc: IUnknown Release() MortgagePayment () IFinancial: IUnknown Virtual Table GetPrimeRate ()

  25. Putting it all together COM DLL • RPC, DLL, Type Libraries, vtables Type Library RPC Client IUnknown request COM service coclass1 Service Control Manager ISomeInterface vtable regsvr32.exe xyz.dll Registry

  26. COM Object Creation • Call CoCreateInstance with arguments: CLSID and IID, and others: • Map the given CLSID to an actual component that contains the requested class, and the mapping is stored in the registry • Create a COM object that is instantiated from the COM class • Return an interface of the request type IID • The registry stores which servers are available and which classes they support: 3 types of servers • In-process server: objects that live in the client’s process, started by loading and linking a DLL • Local server: objects on the same machine, but in a separate process, started by a separate executable (EXE) • Remote server: objects on a different machine, started by loading and starting the required server on the remote machine through the service control manager (SCM)

  27. Compound Document and OLE • OLE is Microsoft’s compound document standard • OLE is a single document-centric paradigm • Some objects are created and existed in OLE setting only, e.g. ActiveX object • Some standard-alone applications can be integrated with OLE • OLE can be viewed as a collection of predefined COM interfaces • OLE compound document can be divided into following parts: • Document server: provides some content model and the capabilities to display and manipulate that content • Document container: has no native content, but can accept parts provided by arbitrary document servers • Some document containers are also document servers, e.g. MS Word, Excel, …

  28. OLE – Object Linking and Embedding • Object embedding: • In-place editing in MS Office applications • In-place activation: the container has to hand off part of the container’s screen state to the server of an embedded part, need to change all menus, toolbars, and others • Object linking: • A container stores a reference to the linked object • The linked object advises the container of changes

  29. OLE Containers and Servers • In-process server: container and server are in the same process • Local out-of-process server: need a “representative” of the server object, executing in the container process, called in-process handler • Remote server: an out-of-process server on a remote machine In-process handler Container Local server IOleClientSite IAdviseSink IOleObject IOleObject Client site object IDataObject IDataObject PersistentStorage IPersistentStorage Others Others

  30. Controls • Visual Basic controls (VBX): • Simple and fixed model: controls are embedded into forms • A form binds the embedded controls together and allows the attachment of scripts that enable the controls to interact • Entire applications can be assembled by composing controls into forms • OLE controls (OCX): • Migrate the VBX concept to the OLE containers • OCXs are COM objects • To qualify as an OLE control, a COM object has to implement a large number of interfaces, e.g. IOleInPlaceActiveObject, IOleInPLaceObject, … • ActiveX controls: • Revised specification for OCX: large number of features and interactions, and all of them are optional • ActiveX controls are COM objects supported by a special server • Has to be implemented by a self-registering server

  31. Building Application out of OCX Controls Compound document Spell checker Word processing data Elementary word processor made from OCX controls Page layout Print services Screen layout Controls can be reused Spreadsheet data Arith. evaluation Elementary spreadsheet from OCX controls Screen layout Numeric I/O Table Server Container

  32. Transactional Component Middleware • Also called COMWare and Object Transaction Managers (OTM) • Covers following technologies • Microsoft Transaction Server (MTS), part of COM+ • Enterprise Java Beans EJB • CORBA-based standard for transactional component middleware from OMG • Components: • Runtime code with an object interface that can be taken out of one context and run in another • E.g. COM code files and EJB

  33. COM Component vs. Enterprise Java Beans • COM component • Run in any Windows operating systems • DCOM to call remote COM objects • Can call database systems and perform transactions • Enterprise Java Beans: • Run in any Java Virtual Machine • RMI to call remote EJB • Can call database systems and perform transactions

  34. Transactional Component Middleware Structure • Makes transaction processing systems easier to implement and more scalable based on object oriented framework • Container • Likes the the transaction monitor for traditional systems • Provides many useful features, e.g. transaction support and resource pooling • Provides standard facilities instead of component implementer to write the “ugly” system calls • Components can be deployed with different settings to behave in different ways, e.g. change the security environment

  35. Transactional Environment • Typical transactional environments (supported by COM+ and EJB): • Requires a transaction: either the client is in transaction state (within the scope of a transaction) or COM+/EJB will start a new transaction when the component’s object is created • Requires a new transaction: COM+/EJB will start a new transaction when the component’s object is created, even if the caller is in transaction state • Supports transactions: the client may or may not be in transaction state, the component’s object does not care • Does not support transactions: the object will not run in transaction state, even if the client is in transaction state • Develop components to support transaction handling: • Component developer defines the transactional environment supported by the component • Container defines the transaction start and end points (based on the transactional environment) • Coding: program code needs to do only commit or abort • Attribute setting: deployer sets the attributes for transactional environment

  36. COM+ Explorer: • For administrator to provide information to the container, e.g. transactional requirement COM+ Model IMyInterface IMyInterface Object Wrapper User-Written COM Object Client DCOM Life Cycle Control IClassFactory IClassFactory IObjectContext • Client reference: • Does not point to user-written component, only interacts with the object wrapper Context Object COM+ Container

  37. Object Wrapper • A barrier between the client and the component • Every operation call is intercepted: can provide additional security checking • Performance improvement by saving resource: • Object wrapper can deactivate component objects without the client knowing about the deactivation • When client next tries to use the object, the wrapper reactivates the object again • E.g. the application support thousands of end users, there will be thousands of clients, which will needs many thousands of objects, object deactivation will make the memory utilization more efficient • Connection pooling (managed by container): • Pool of database connection shared by objects • When an object is deactivated, the connection will be returned to the pool • When an object is activated, it reuses an inactive connection from the pool

  38. Administrator uses XML to provide information to the container, e.g. transactional requirement EJB Model MyInterface MyInterface Object Wrapper User-Written Enterprise Java Bean RMI or IIOP Client EJBHome MyHomeInterface MyHomeInterface Java.ejbSessionContext • Client reference: • Does not point to user-written component, only interacts with the object wrapper Context Object EJB Container

  39. COM+ • Extension of the COM model by merging MTS into core COM implementation • Underlying protocol: DCOM • SOAP (Simple Object Access Protocol): an alternative network protocol which uses XML, may allow a client running on a non-Microsoft platform to call a COM+ server • Object deactivation: • Same as elimination, i.e. object is recreated every time • Can be deactivated after every operation: same as traditional transaction monitor, data object attributes are reset to their initial state at the beginning of an operation • Can be at the end of a transaction: allows the client to make several calls to the same object, e.g. search for a record in the DB in a call, update the DB in another call • Does not support temporary data on a session basis: in traditional transaction monitor, data area is provided to store temporary data which can be used by multiple transactions from the same terminal

  40. EJB • A standard, not a product • EJB products by BEA, IBM, Oracle, … • Network connection to EJB is RMI and IIOP • 3 kinds of components: Entity beans, session beans and message beans • Entity beans • An entity bean is designed to represent a row in the database: a proxy object • Persistence: can be container managed or bean managed • Session beans • A session bean implements a business process that is performed on the behalf of the client in a single session: an agent object • Can be stateless or stateful • Message-driven beans: use the Java Message Services to support asynchronous interactions between clients and beans • More details in the EJB tutorial

More Related