55
COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Embed Size (px)

Citation preview

Page 1: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

COP 4991Component Based Software

Development

Lecture #2Distributed and Web Computing

Onyeka Ezenwoye

Page 2: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Acknowledgement

Lou Somers

Alex Chaffee

Page 3: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

BASIC

Beginners All-purpose Symbolic Instruction Code

John Kemeny and Thomas Kurtz, 1963

General-purpose language

Easy to use?

Page 4: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

BASIC

10 REM a great BASIC program

20 PRINT “Hello There!”

30 INPUT “Please enter your age:” age

40 IF age > 1 AND age < 21 GOTO 60

50 IF age > 29 GOTO 70

60 PRINT “You are still a baby!” GOTO 80

70 PRINT “You are ready for retirement!”

80 END

Page 5: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

BASIC

• The GOTO problem• What on earth does line 2970 do?• Code in single continuous block• Great for “K-LOCers”

Unstructured

Not reusable

Not “easy to use”!

Page 6: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Structure in language

Program structure composed of sub-structures

Essentially functions and subroutines

y = add(a,b)

x = multiply(y, z)

Single point of entry, multiple points of exit.

Promote modularity

Page 7: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Object-oriented programming

More sophisticated form of modularity

The world is made of objects

Think objects, not procedures

y = Math.add(a,b)

x = Math.multiply(y,z)

Program is a collection of objects (class libraries)

Page 8: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Interface

Communication boundary between two entities (software)

Abstraction about software component

Well defined entry point

Enables interaction

Method signatures

int add(int, int)Math

multiply

add

Page 9: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Complexity

Need for modularity

Page 10: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Multi-tier applications

Split application logicReduce cost, improve maintainabilityImprove scalabilityUse multiple partners

three-tier application

client app server DB server

Page 11: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Client-server

Enables separation between modulesA request-response interaction style.Uniform interface: resources accessed with a generic interface (e.g., HTTP GET, POST). Named resources - the system is comprised of resources which are accessed using a URL.Easier to build, maintain and extend components

Standardization Interoperability

Page 12: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

HTTP (Hypertext Transfer Protocol)

Request/response communication protocol between client and server.

Est. TCP connection to port 80 on server

HTTP GET– Requests a resource, identified by the URL

HTTP POST– Sends data to be processed

Page 13: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RPC (remote procedure call)

The act of invoking a method over a networkRemote component integrationClient-Server message passingLocation transparentTight coupling between client and remote applications

Mathadd

y=Math.add(a,b) Internet

Page 14: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RPC

Client

Call

Client Stub

Pack and send parameters

Receive and unpack

parameters

Pack and send

results

Execute procedure

ReturnReceive and

unpack results

Server Stub Server

Message

Message

Page 15: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Client Java

objectJava RMI Java RMI

Remote Java

object

TCP

Java Remote Method Invocation

Page 16: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Remote Objects

Remote Objects– Live on server– Accessed as if they were local

Page 17: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Registries

Name and look up remote objects

Servers can register their objects

Clients can find server objects and obtain a remote reference

A registry is a running process on a host machine

Page 18: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Stubs and Skeletons

Stub – lives on client– pretends to be remote object

Skeleton– lives on server– receives requests from stub– talks to true remote object– delivers response to stub

Skeleton Remote object

StubClient object

Page 19: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Remote Interfaces and Stubs

Remote Interface

StubRemote Object

(Server)Client Skeleton

implements implements

Page 20: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI System Architecture

Client Virtual Machine

Client

Server Virtual Machine

Stub

Remote Object

Skeleton

Registry Virtual Machine

“Fred”

Server

Page 21: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI System Architecture

Client Virtual Machine

Client

Server Virtual Machine

Stub

Remote Object

Skeleton

Registry Virtual Machine

“Fred”

Server

1

2

1. Server Creates Remote Object2. Server Registers Remote Object

Page 22: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI System Architecture

Client Virtual Machine

Client

Server Virtual Machine

Stub

Remote Object

Skeleton

Registry Virtual Machine

“Fred”

Server

4

3. Client requests object from Registry4. Registry returns remote reference(and stub gets created)

3

Page 23: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI System Architecture

Client Virtual Machine

Client

Server Virtual Machine

Stub

Remote Object

Skeleton

Registry Virtual Machine

“Fred”

Server

6

5. Client invokes stub method6. Stub talks to skeleton7. Skeleton invokes remote object method

5 7

Page 24: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Creating Remote Objects

Define a Remote Interface– extends java.rmi.Remote

Define a class that implements the Remote Interface– extends java.rmi.RemoteObject– or java.rmi.UnicastRemoteObject

Page 25: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Remote Interface Example

import java.rmi.*;

public interface Adder

extends Remote

{

public int add(int x, int y)

throws RemoteException;

}

Page 26: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Remote Class Exampleimport java.rmi.*;

import java.rmi.server.*;

public class AdderImpl extends UnicastRemoteObject implements Adder

{

public AdderImpl() throws RemoteException

{

}

public int add(int x, int y)

throws RemoteException

{

return x + y;

}

}

Page 27: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Compiling Remote Classes

Compile the Java class– javac

• reads .java file

• produces .class file

Compile the Stub and Skeleton– rmic

• reads .class file

• produces _Skel.class and _Stub.class

Page 28: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Compiling Remote Classes (Diagram)

Adder.java(interface)

Adder.class(interface classfile)

javac

AdderImpl.java(remote class)

AdderImpl.class(classfile)

javacrmic

AdderImpl_Skel.class(skeleton classfile)

AdderImpl_Stub.class(stub classfile)

Page 29: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Registering Remote Classes

start the registry– running process

Unix: rmiregistry &

Windows: start /m rmiregistry

Page 30: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Create the server

Creates a new instance of the remote object

Registers it in the registry with a unique name

That’s it

Page 31: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI Server Example

try {

AdderImpl adder = new AdderImpl();

Naming.rebind("adder", adder);

System.out.println("Adder bound");

}

catch (RemoteException re) {

re.printStackTrace();

}

catch (MalformedURLException me) {

me.printStackTrace();

}

Page 32: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Launch the Server

% java AdderServer &

Adder bound

Page 33: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Server Logging

invoke from command line

java

-Djava.rmi.server.logCalls=true YourServerImpl

or enable inside program

RemoteServer.setLog(System.err);

Page 34: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Creating an RMI Client

Install a Security Manager– to protect from malicious stubs

Find a registry– use java.rmi.Naming

Lookup the name, returns a reference

Cast the reference to the appropriate Remote Interface

Just use it!

Page 35: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI URLs

rmi://host[:port]/name

default port is 1099

Specifies hostname of registry

can also use relative URLs – name only– assumes registry is on local host

Page 36: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

RMI Client Example

Adder a = (Adder) Naming.lookup(“rmi://localhost/adder");

int sum = a.add(2,2);

System.out.println("2+2=" + sum);

Page 37: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Object Serialization

aka Persistence

saves the state (data) of a particular instance of an object

serialize - to save

unserialize - to load

Page 38: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Java Serialization

writes object as a sequence of bytes

writes it to a Stream

recreates it on the other end

creates a brand new object with the old data

Page 39: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Not All Objects Are Serializable

Any object that doesn’t implement Serializable

Any object that would pose a security risk– e.g. FileInputStream

Any object whose value depends on VM-specific information– e.g. Thread

Page 40: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Limitations of RMI

Java-only

Page 41: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Middleware

“The glue which connects objects which are distributed across multiple heterogeneous computer systems”

“A software layer that serves to shield the application of the heterogeneity of the underlying computer platforms and networks”

Distribution Middleware

Page 42: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Middleware goals

Integrate existing components into a distributed system– Components may be off-the-shelf– Components may have incompatible requirements for hardware

and OS platforms– Scalability requires distribution (not centralized or client server).

Resolve heterogeneity– Facilitate communication and coordination of distributed

components– Build systems distributed across a local area network, the internet– Future: adaptive, reconfigurable

Page 43: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Requirements of middleware / 1

Network communication– Need higher level primitives than network operating system

primitives– Transport complex data structures over the network (marshalling /

unmarshalling)

Coordination– Three models:

• Synchronous: client waits for result• Deferred synchronous: client asks for result (e.g. by polling)• Asynchronous: server initiates result

– Group requests– Component activation / deactivation– Concurrent requests

Page 44: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Requirements of middleware / 2

Reliability – Error detection and correction mechanisms on top of

network protocols Scalability– Access to a component independent of whether it is

local or remote– Migration transparency– Replication transparency

Heterogeneity– Primitive data encoding– Different programming languages

Page 45: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Middleware categories

Transactional middleware– Offers a tuple abstraction (SQL)– Distributed transaction processing (DTP protocol)

Message oriented (MOM)– Offers a mailbox abstraction– Asynchronous messages

Procedural (RPC)– Offers a procedure abstraction– Synchronous client / server interaction

Object and component – Offers an object abstraction– (A)synchronous client / server interaction

Page 46: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Transactional middleware / 1

Transactions on distributed relational database– Two-phase commit protocol to implement distributed

transactions

Examples– IBM CICS

– BEA Tuxedo

– LDAP (simple protocol to access remote directories, no transactions)

Page 47: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Transactional middleware / 2

Network communication– Client and servers may reside on different hosts

Coordination– Synchronous and asynchronous

Reliability– DTP (Distributed Transaction Protocol): two phase commit– ACID properties:– Atomic: transaction is either complete or not– Consistent: system always in consistent state– Isolation: transaction is independent of other transactions– Durable: committed transaction survives system failures

Scalability– Load balancing and replication of server components

Heterogeneity– Different hardware and operating systems platforms– No data heterogeneity

Page 48: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Message oriented middleware / 1

Exchange messages between components– “Mailbox”

Examples– Java Message Queue

– IBM MQSeries

Page 49: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Message oriented middleware / 2

Network communication– Client sends message, server replies with result– Well suited for event notification and publish / subscribe

Coordination– Asynchronous– Synchronous has to be coded by client

Reliability– Message queues are stored on persistent memory– At-least-once semantics possible

Scalability– Local / remote differs

Heterogeneity– Marshalling code has to be written by hand

Page 50: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Procedural middleware / 1

Remote procedure calls (RPC)– Procedures can be called across the network

Examples– Unix RPC’s– DCE RPC (Distributed Computing

Environment)– Windows RPC’s– XML-RPC

Page 51: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Procedural middleware / 2Network communication– Server exports parameterized procedures– Clients call these across the network– Marshalling and unmarshalling by client and server stubs

(generated by the compiler)

Coordination– Synchronous interaction between one client and one server– Startup on demand possible (daemon needs a table that maps RPC

names to program locations in the file system)

Reliability– At-most-once semantics (exception if RPC fails)

No scalabilityHeterogeneity– Can be used between different programming languages– Across different hardware and OS platforms

Page 52: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Object middleware / 1

Objects are available across the network

Examples– Corba– COM, DCOM– Java RMI, Enterprise Java Beans

Page 53: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Enterprise A

Java RMI

App 1 App 2

Enterprise B

COM

App 1 App 2

Enterprise C

CORBA

App 1 App 2

COM/RMI bridge

COM/CORBA bridge

Page 54: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Enterprise A

Java RMI

App 1 App 2

Enterprise B

COM

App 1 App 2

Enterprise C

CORBA

App 1 App 2

COM/RMI bridge

COM/CORBA bridge

proto

col c

hange

Page 55: COP 4991 Component Based Software Development Lecture #2 Distributed and Web Computing Onyeka Ezenwoye

Reading List

Patricia Soares, “On Remote Procedure Call ”Birrell et. al., “Implementing Remote Procedure Calls”Eugster et. al., “The Many Faces of Publish/Subscribe”Talarian Corp., “Talarian: Everything You Need Know About Middleware”David B akken,”Middleware”Bertrand Meyer, “The Reusability Challenge” Ted Lewis, “Where is Client/Server Software Headed?”Scot Lewandowski,”Frameworks for Component-Based Client/Server Computing”