Object Oriented Software Design - I - Object Oriented Design
Presentation 4: Principles of Object-Oriented Middleware
-
Upload
euridice-cerelia -
Category
Documents
-
view
23 -
download
1
description
Transcript of Presentation 4: Principles of Object-Oriented Middleware
Presentation 4:Principles of
Object-Oriented Middleware
Types of Middleware- and why to use …
Ingeniørhøjskolen i ÅrhusSlide 3 af 23
Rolling your own distributed object
• We may build directly on the TCP or UDP protocols to build a distributed system
• In Java: quite easy – thanks to the java.net package – which contains a complete network API incl. socket support for TCP/UDP
• BUT: if we want to ensure OO – more complex
• Let us take a look at how this may be done
Ingeniørhøjskolen i ÅrhusSlide 4 af 23
The Basic Class to OO Class
public class HelloWorldBasic { public static void main(String[] args) { System.out.println("HelloWorld!"); }}
HelloWorld – canit be more simple?
public class HelloWorldOO { public HelloWorldOO() { } public void sayHelloWorld() { return “HelloWorld"; } public static void main(String[] args) { HelloWorldOO helloWorldOO = new HelloWorldOO(); System.out.println(helloWorldOO.sayHelloWorld()); }}
To OO:
Ingeniørhøjskolen i ÅrhusSlide 5 af 23
First Issue: Making the Object Distributed- Method Call vs. Object Request
CalledCalledCalledCalled
StubStub
StubStubStubStub
CallerCaller
CalledCalledCalledCalled
CallerCallerCallerCaller
Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)Transport Layer (e.g. TCP or UDP)
Ingeniørhøjskolen i ÅrhusSlide 6 af 23
Repetition Group Work
• You already know how to do this from Dist• 10 Minutes group work – followed by discussion
– On paper – using pseudo code – describe what to code in order to make HelloWorldOO distributed depending solely on the datagram API (UDP) technology
– Optimize the code for access transparency– Consider introducing location transparency– Consider introducing scalability transparency– Change the interface to allow for returning a HelloWorldData
object with:• Name• Greetings Text• java.util.Data object
– Consider how to allow a C++ client to access the code– Consider the problems of your design – what might fail?
Ingeniørhøjskolen i ÅrhusSlide 7 af 23
Direct Use of Network Protocols implies
• Manual mapping of complex request parameters to byte streams or datagrams – is complex & error prone
• Manual resolution of data heterogeneity– encoding differs on NT & UNIX (what is the format of an Integer?)
• Manual identification of components– References must be established manually (host add., port nr. etc.)
• Manual implementation of component activation• No guarantees for type safety• Manual synchronization of interaction between distributed
components– Developers need to handle TCP/UDP output stream/responses
• No quality of service guarantees– Transactions, Security, Concurrency, Scalability, Reliability
Ingeniørhøjskolen i ÅrhusSlide 8 af 23
= Reason for Using Middleware
• Layered between Application and OS/Network• Makes distribution transparent• Resolves heterogeneity of
– Hardware– Operating Systems– Networks– Programming Languages
• Provides development and run-time environment for distributed systems
• “Gets you of the hook” – concerning the nasty stuff in network programming
Ingeniørhøjskolen i ÅrhusSlide 9 af 23
Types of Middleware
• Transaction-Oriented– Suited for Database Applications– IBM CICS– BEA Tuxedo– Encina
• Message-Oriented– Suited for Asynchronous (EDI,Batch)– IBM MQSeries– DEC Message Queue– NCR TopEnd– (SOAP)
• RPC Systems– Suited for Access transparency etc– ANSA– Sun ONC– OSF/DCE– (SOAP)
• Object-Oriented– OMG/CORBA– DCOM– Java/RMI/EJB– .NET Remoting– (SOAP)
• First look at RPCs to understand origin of object-oriented middleware
Ingeniørhøjskolen i ÅrhusSlide 10 af 23
Remote Procedure Calls
• Enable procedure calls across host boundaries• Call interfaces are defined using an Interface
Definition Language (IDL)• RPC compiler generates presentation and session
layer implementation from IDL• RPC is the “legacy” of oo middleware
Ingeniørhøjskolen i ÅrhusSlide 11 af 23
Type Safety and Heterogenity
• How can we make sure that – servers are able to perform
operations requested by clients?– actual parameters provided by
clients match the expected parameters of the server?
– results provided by the server match the expectations of client?
• Middleware acts as mediator between client and server to ensure type safety.
• Achieved by interface definition in a mutually agreed upon language
• Supports Heterogenity
Ingeniørhøjskolen i ÅrhusSlide 12 af 23
IDL Example (Unix RPCs)
const NL=64;
struct Player {
struct DoB {int day; int month; int year;}
string name<NL>;
};
program PLAYERPROG {
version PLAYERVERSION {
void PRINT(Player)=0;
int STORE(Player)=1;
Player LOAD(int)=2;
}= 0;
} = 105040;
Ingeniørhøjskolen i ÅrhusSlide 13 af 23
RPC Marshalling and Unmarshalling
• Marshalling: Disassemble data structures into transmittable form
• Unmarshalling: Reassemble the complex data structure
char * marshal() { char * msg; msg=new char[4*(sizeof(int)+1) + strlen(name)+1]; sprintf(msg,"%d %d %d %d %s", dob.day,dob.month,dob.year, strlen(name),name); return(msg);};void unmarshal(char * msg) { int name_len; sscanf(msg,"%d %d %d %d ", &dob.day,&dob.month, &dob.year,&name_len); name = new char[name_len+1]; sscanf(msg,"%d %d %d %d %s", &dob.day,&dob.month, &dob.year,&name_len,name);};
char * marshal() { char * msg; msg=new char[4*(sizeof(int)+1) + strlen(name)+1]; sprintf(msg,"%d %d %d %d %s", dob.day,dob.month,dob.year, strlen(name),name); return(msg);};void unmarshal(char * msg) { int name_len; sscanf(msg,"%d %d %d %d ", &dob.day,&dob.month, &dob.year,&name_len); name = new char[name_len+1]; sscanf(msg,"%d %d %d %d %s", &dob.day,&dob.month, &dob.year,&name_len,name);};
Ingeniørhøjskolen i ÅrhusSlide 14 af 23
RPC Stubs
• Creating code for marshalling and unmarshalling is tedious and error-prone.
• Code can be generated fully automatically from interface definition.
• Code is embedded (hidden away – de-coupled) in stubs for client and server.
• Client stub represents server for client, Server stub represents client for server.
• Stubs achieve type safety.• Stubs also perform synchronization.• NOT object-oriented, no support for exceptions or
advanced error handling
Object-Oriented Middleware
Ingeniørhøjskolen i ÅrhusSlide 16 af 23
Interface Definition Language
• Every object-oriented middleware has an interface definition language (IDL)
• Beyond RPCs, object-oriented IDLs support object types as parameters, failure handling (exceptions) and inheritance
• Object-oriented middleware provide IDL compilers that create client and server stubs to implement session and presentation layer
Ingeniørhøjskolen i ÅrhusSlide 17 af 23
IDL Example
interface Player : Object { typedef struct _Date { short day; short month; short year; } Date; attribute string name; readonly attribute Date DoB;};interface PlayerStore : Object { exception IDNotFound{}; short save (in Player p); Player load(in short id) raises(IDNotFound); void print(in Player p);};
Ingeniørhøjskolen i ÅrhusSlide 18 af 23
Presentation Layer Implementation
• Ensuring compatible encoding across platforms• In addition to RPC presentation layer
implementation, object-oriented middleware needs to– define a transport representation for object references– deal with exceptions– need to marshal inherited attributes
Ingeniørhøjskolen i ÅrhusSlide 19 af 23
ObjectReferences Hosts Processes Objects
Session Layer Implementation- Mapping of Object references to hosts-Activation & deactivion of objects-Invocation of requested operation-Synchronization of client & server (state)
- Mapping of Object references to hosts-Activation & deactivion of objects-Invocation of requested operation-Synchronization of client & server (state)
Developing with Object-Oriented Middleware
Ingeniørhøjskolen i ÅrhusSlide 21 af 23
InterfaceDefinition
Design
Server StubGeneration
Client StubGeneration
ServerCoding
ClientCoding
ServerRegistration
Development Steps
Ingeniørhøjskolen i ÅrhusSlide 22 af 23
Team.idlTeam.idl
included ingeneratesreads
IDL-Compiler
Teamcl.hh
Teamcl.cc Teamsv.cc
Teamsv.hh
Stub Generation
Team.wsdlTeam.wsdlTeam.javaTeam.java
Team.midlTeam.midl
Ingeniørhøjskolen i ÅrhusSlide 23 af 23
C++ Compiler, Linker
Server
Client.ccClient.cc Server.ccServer.cc
C++ Compiler, LinkerC++ Compiler, Linker
Client
Team.idlTeam.idl
included ingeneratesreads
IDL-Compiler
Teamcl.hh
Teamcl.cc Teamsv.cc
Teamsv.hh
Client and Server Implementation