1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South...

48
1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    0

Transcript of 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South...

Page 1: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

1

From Objects to Components

joint lectureby

Prof. Judith Bishop, University of Pretoria, South AfricaStephan Herrmann, TU Berlin

Page 2: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

2Pretoria

Page 3: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

3Distributed Objects

Need a connection between processes e.g. sockets

Need memory independent object identifiers e.g. #1, #2, #3

Need remote method calls send (“#4 print_yourself”)

Need to encode parameters (and return value..)Need to receive return value

result = read ()

Implement all this for every single method call??

Page 4: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

4Encapsulate Communication

class AccountImpl implements Account extends RemoteObject {

private String id;

public int deposit(int amount) {

String amount_str = encode_int(amount);

send(id + “ deposit ” + amount_str);

String new_balance = readString();

return decode_int(new_balance);

}

public int get_balance () { ... }

}

Account a = new AccountImpl(“#15”);

int nb = a.deposit(1000000);

Page 5: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

5Proxy Pattern

Client does not see difference between `real impl´ and proxySuperclass RemoteObject provides basic functions for socket handling value conversion

(includes creation of proxies for referenced objects)

Handcode proxies??What about the receiving side?? decode messages assign object IDs

Client

AccountProxyAccountImpl

Account RemoteObject

Page 6: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

6Java 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 nameDeclare it as remoteDeclare it as remote

Package namePackage name

Wolfgang Emmerich 2000©

Page 7: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

7Architecture

ServerServerClientClient

StubStub RegistryRegistryInterfacesInterfaces

SkeletonSkeleton ActivationActivationInterfacesInterfaces

RMI Runtime (RMI Runtime (rmidrmid,rmiregistry,rmiregistry))

Wolfgang Emmerich 2000©

Page 8: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

8Activation 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

Wolfgang Emmerich 2000©

Page 9: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

9Java 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

Wolfgang Emmerich 2000©

Page 10: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

10Goals 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

Wolfgang Emmerich 2000©

Page 11: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

11Programming Languages

RMI is fine for Java, but

What if I want to implement my objects in different programming languages?

Page 12: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

12OMG Interface Definition Language

Language for expressing all concepts of the CORBA object model

OMG/IDL isprogramming-language independentorientated towards C++not computationally complete

Different programming language bindings are available Explanation of Model and Language by Example

Wolfgang Emmerich 2000©

Page 13: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

13Object Model and Interface Definition

Objects Types Modules Attributes Operations Requests Exceptions Subtypes

Wolfgang Emmerich 2000©

Page 14: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

14CORBA 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

Wolfgang Emmerich 2000©

Page 15: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

15CORBA 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

Wolfgang Emmerich 2000©

Page 16: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

16

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

Architecture

Wolfgang Emmerich 2000©

Page 17: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

17Goal 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

Wolfgang Emmerich 2000©

Page 18: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

18Key Points

CORBA, RMI and other middleware (like COM)– 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

Wolfgang Emmerich 2000©

Page 19: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

19Wait?

This int deposit(int) method was silly.

Why should I wait for a result??

Page 20: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

20Request Synchronization

Synchronous requests might block clients unnecessarily. Examples:User Interface ComponentsConcurrent Requests from different servers

OO-Middleware: synchronous requests.OO-Middleware: synchronous requests.

:Server:Server:Server:Server:Client:Client:Client:ClientOp()Op()

Wolfgang Emmerich 2000©

Page 21: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

21Oneway Requests

Return control to client as soon as request has been taken by middleware

Client and server are not synchronized Use if

Server does not produce a resultFailures of operation can be ignored by client

:Server:Server:Server:Server:Client:Client:Client:Clientoneway()oneway()

Wolfgang Emmerich 2000©

Page 22: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

22Oneway using Java Threads

class PrintSquad { static void main(String[] args) { Team team; Date date; // initializations of team and date omitted ... OnewayReqPrintSquad a=new OnewayReqPrintSquad(team,date); a.start(); // continue to do work while request thread is blocked... }}

// thread that invokes remote methodclass OnewayReqPrintSquad extends Thread { Team team; Date date; OnewayReqPrintSquad(Team t, Date d) { team=t; date=d; } public void run() { team.print(date); // call remote method and then die }}

Wolfgang Emmerich 2000©

Page 23: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

23Oneway requests in CORBA

Declared statically in the interface definition of the server object

IDL compiler validates thatoperation has a void return typedoes not have any out or inout parametersdoes not raise type specific exceptions

Example:interface Team {

oneway void mail_timetable(in string tt);

};

Wolfgang Emmerich 2000©

Page 24: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

24

r:Requestr:Request

:Server:Server:Client:Client

send()send()

r=create_request()r=create_request()

delete()delete()

Oneway requests in CORBA

If oneway declarations cannot be used: Use dynamic invocation interface

Op()Op()

Wolfgang Emmerich 2000©

Page 25: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

25

:Server:Server:Server:Server:Client:Client:Client:Client :Request:Request:Request:Request

Deferred Synchronous Requests

Return control to client as soon as request has been taken by middleware

Client initiates synchronization Use if

Requests take long timeClient should not be blockedClients can bear overhead of synchronization

send()send() op()op()

get_result()get_result()

Wolfgang Emmerich 2000©

Page 26: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

26Deferred Synchronous Requests with Threads

class PrintSquad { public void print(Team t, Date d) { DefSyncReqPrintSquad a=new DefSyncReqPrintSquad(t,d); // do something else here. a.join(this); // wait for request thread to die. System.out.println(a.getResult()); //get result and print }}// thread that invokes remote methodclass DefSyncReqPrintSquad extends Thread { String s; Team team; Date date; DefSyncReqPrintSquad(Team t, Date d) {team=t; date=d;} public String getResult() {return s;} public void run() { String s; s=team.asString(date);// call remote method and die }}

Wolfgang Emmerich 2000©

Page 27: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

27CORBA Deferred Synchronous Requests

Determined at run-time with using DII By invoking send() from a Request object And using get_response() to obtain result

:Server:Server:Server:Server:Client:Client:Client:Client

r:Requestr:Requestr:Requestr:Request

op()op()

get_response()get_response()

r=create_request(“op”)r=create_request(“op”)

send()send()

Wolfgang Emmerich 2000©

Page 28: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

28Asynchronous Requests

Return control to client as soon as request has been taken by middleware

Server initiates synchronization Use if

Requests take long timeClient should not be blockedServer can bear overhead of synchronization

:Server:Server:Server:Server:Client:Client:Client:Clientop()op()

Wolfgang Emmerich 2000©

Page 29: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

29Asynchronous Requests with Threads

Client has interface for callback Perform request in a newly created thread Client continues in main thread New thread is blocked Requested operation invokes callback to pass result New thread dies when request is complete

Wolfgang Emmerich 2000©

Page 30: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

30Asynchronous Requests with Threads

interface Callback { public void result(String s);}class PrintSquad implements Callback { public void Print(Team team, Date date){ A=new AsyncReqPrintSquad(team,date,this); A.start(); // and then do something else } public void result(String s){ System.out.print(s); }}class AsyncReqPrintSquad extends Thread { Team team; Date date; Callback call; AsyncReqPrintSquad(Team t, Date d, Callback c) { team=t;date=d;call=c; } public void run() { String s=team.AsString(date); call.result(s); }}

Wolfgang Emmerich 2000©

Page 31: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

31Asynchronous Requests using Message Queues

Messaging is starting to be provided by object-oriented middlewareMicrosoft Message QueueCORBA Notification ServiceJava Messaging Service

Request and reply explicitly as messages Using two message queues Asynchronous requests can be achieved

Wolfgang Emmerich 2000©

Page 32: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

32Asynchronous Requests using Message Queues

ClientClient ServerServer

Request QueueRequest Queue

Reply QueueReply Queue

enterenter removeremove

removeremove enterenter

Wolfgang Emmerich 2000©

Page 33: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

33Difference between Thread and MQs

Threads Communication is

immediate Do not achieve guaranteed

delivery of request Can be achieved using

language/OS primitives

Message Queues Buffer Request and Reply

messages Persistent storage may

achieve guaranteed delivery Imply additional licensing

costs for Messaging

Wolfgang Emmerich 2000©

Page 34: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

34Request Multiplicity

OO Middleware: unicast requestsTwo components: client and serverOne operation executionNon-anonymous

Other forms: multicast requestsMore than two components (group requests)More than one operation (multiple requests)

Wolfgang Emmerich 2000©

Page 35: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

35

:Trader:Trader:Trader:Trader :Channel:Channel:Channel:Channel :Ticker:Ticker:Ticker:Ticker :Ticker:Ticker:Ticker:Ticker :Ticker:Ticker:Ticker:Ticker

Group Requests

Example: Stock Exchange Ticker

connect()connect()

push()push()

push()push()

disconnect()disconnect()connect()connect()

connect()connect()

push()push()

push()push()push()push()

push()push()Wolfgang Emmerich 2000©

Page 36: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

36Group Communication Principles

Group communication informs a group of components about a particular event.

Two roles:Event producerEvent consumer

Producers and consumers do not know each other. Two forms of request:

push-type: producer initiates communicationpull-type: consumer initiates communication

Wolfgang Emmerich 2000©

Page 37: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

37Some Architecture

Can’t we use some style of Model-View-Control for distributed applications?

business logic

client client

pure model

view&control

e.g. as servlet

e.g. as applet

... and we need a DB for

connected via http

within a web server

persistency

Wow, just invented a 3-tier-architecture!

Page 38: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

38EJB Roles and Deployment

Page 39: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

39Developer Roles

EJB Technology divides naturally into five developer roles:

server provider, container provider, Enterprise Beans (component!!) provider, application assemblers, and deployers.

Page 40: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

40Enterprise JavaBeans Components

Application Servers (42) Authoring Tools (5) Charts&Graphs (4) Database Connectivity (21)

Database Servers (6)

Development Tools (47)

EJB Components (34) EJB-based Applications (49)

Electronic Commerce (38) Electronic Publishing (5) Entertainment (1) Financial Services (20) Legacy Support (10) Manufacturing (4)

Multimedia (3) Network Administration (1) Object Transaction Monitors

(1) Productivity/Groupware (18) Report Generation (5) Retail (6) System Administration (4) Telecommunications (15) Transaction Servers (5) UI Elements (1) Utilities&Services (13) Web Servers (9) Workflow (6)

Page 41: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

41What is a component?

"Reusable software components are self contained, clearly identifiable pieces that describe and/or perform specific

functions, have clear interfaces, appropriate documentation and a defined reuse status".

Page 42: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

42Cross platform

An Enterprise Bean executes in a container An EJB can be taken from one environment to another

without recoding. Communication via RMI as default EJBs can also be accessed via Corba-IIOP Corba details are hidden from the EJB developer

Page 43: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

43Writing an EJB

The bean provider adheres to two contracts: – the client’s view, and – the component’s view as seen from the container.

The bean provider therefore produces:– EJB remote interface class file– EJB home interface class file– EJB class file

An EJB can be developed provide the EJB and JNDI classes are installed.

JNDI stands for Java Naming Directory Interface

Page 44: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

44

When talking about components, don’t only say “functionality” but pay for properties like

persistenceperformancesecurityavailabilityportability...

Naming and Trading

Know the instance? Object ID (exact reference)

Know the provider (who)? Naming (white pages)

Know the service (what)? Trading (yellow pages)

based on the declaration of properties like:fee, bandwidth, availability ...

“Quality of Service” (QoS)

attention to

Some of these are implemented e.g. as CORBA services

Page 45: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

45Provide, deploy and use

Provide – the remote interface for all the visible business

methods of the bean– the home interface to install instances of a bean on a

client– the bean class with the implementation of the business

methods

EJB provider tool will set up a descriptor and details of EJB deployment to a runtime container.

Package it all up in an ejb-jar file Set up RMI in client to use the new service

Page 46: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

46Packaging

A Component can be more than just compiled binary code: Help files Images Prototypes (Design Pattern Prototype)

(cf. prototype based languages) provide pre-configured values.

Localisation etc.

use cloning for creation

Page 47: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

47todays lesson:

Dispite differences of sizefunctionservicesstyle

... component development through all phases is the future.

Page 48: 1 From Objects to Components joint lecture by Prof. Judith Bishop, University of Pretoria, South Africa Stephan Herrmann, TU Berlin.

48References

Wolfgang Emmerich: „Engineering Distributed Objects“ Wileys, 2001www.distributed-objects.com

www.javasoft.com Clemens Szyperski: „Component Software - Beyond

Object-Oriented Programming“Addison Wesley, 1998

See also http://www.cms.dmu.ac.uk/nmsampat/research/subject/reuse/components/index.htm