Top Banner
1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El-Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005
49

1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

Dec 27, 2015

Download

Documents

Abigail Fox
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

1

Distributed Objects

Naim R. El-Far, PhD Candidate

TA for SEG3202 Software Design and Architecture with N. El-Kadri (Summer 2005)

Tutorial 3 of 4 – 10/6/2005

Page 2: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

2

About this Material

Some of the slides in today’s presentation are based on slides by Dr. J. S. Chase of the Duke University (http://www.cs.duke.edu/~chase/), Dr. J. Ng of the University of Hong Kong (http://www.comp.hkbu.edu.hk/~jng), and public domain slides from Rensselaer Polytechnic Institute (www.rpi.edu/dept/cct/public/j2ee).

Page 3: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

3

Outline of Today’s Presentation

A look at distributed objects Java Remote Method Invocation (RMI) Java 2 Enterprise Edition (J2EE)

Page 4: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

4

What’s in a Name?

Distributed Objects:

Software modules (objects) that are designed to work together but reside in multiple computer systems throughout an organization. A program in one machine sends a message to an object in a remote machine to perform some processing. The results are sent back to the local machine.

Page 5: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

5

“The Network is the Computer”

SomeClass AnotherClass

method call

returned object

computer 1 computer 2

Page 6: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

6

What exactly do we mean by “objects”? Objects are units of data with the following properties:

– typed and self-contained• Each object is an instance of a type that defines a set of methods

(signatures) that can be invoked to operate on the object.

– encapsulated• The only way to operate on an object is through its methods; the

internal representation/implementation is hidden from view.

– dynamically allocated/destroyed• Objects are created as needed and destroyed when no longer

needed, i.e., they exist outside of any program scope.

– uniquely referenced• Each object is uniquely identified during its existence by a

name/OID/reference/pointer that can be held/passed/stored/shared.

Page 7: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

7

Why are objects useful?

The properties of objects make them useful as a basis for defining persistence, protection, and distribution.– Objects are self-contained and independent.

• Objects are a useful granularity for persistence, caching, location, replication, and/or access control.

– Objects are self-describing.• Object methods are dynamically bound, so programs can import

and operate on objects found in shared or persistent storage.

– Objects are abstract and encapsulated.• It is easy to control object access by verifying that all clients

invoke the object’s methods through a legal reference.• Invocation is syntactically and semantically independent of an

object’s location or implementation.

Page 8: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

8

Distributing Objects

“Trick”: Extend the object name space outside of a

process and across a distributed system. Extend the object name space across

secondary storage. Define RPC services as objects

(namespacing, wrapping). Make object references unforgeable and

reject invocation attempts with invalid references

Page 9: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

9

Issues Vital to Distributed Object Systems1. Can we use distributed objects as a basis for interoperability among

software modules written in different languages?2. Can objects interact across systems with different data formats?3. Can objects interact securely across mutually distrusting nodes

and/or object infrastructures by different vendors?

4. How can we find objects in the presence of node failures?

5. What should we do about pending activities in failed nodes/objects?

6. How can we recover object state after failures?

7. Can we safely execute object invocations from nodes with intermittent connectivity?

8. What about long-term storage of objects, and invocation of stored objects that are not currently active?

Page 10: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

10

Distributed Object Technologies

1. Remote Method Invocation (RMI)• API and architecture for distributed Java objects

2. Microsoft Component Object Model (COM/DCOM)• binary standard for distributed objects for Windows platforms

3. CORBA (Common Object Request Broker Architecture)

• platform and location transparency for sharing well-defined objects across a distributed computing platform

4. Enterprise Java Beans (EJB)• CORBA-compliant distributed objects for Java, built using RMI

5. Web services and SOAP• protocols and standards used for exchanging data between

applications

Page 11: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

11

Page 12: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

12

Introduction to Java RMI

Java RMI allowed programmer to execute remote function class using the same semantics as local functions calls.

Local Machine (Client)

SampleServer remoteObject;int s;…

s = remoteObject.sum(1,2);

System.out.println(s);

Remote Machine (Server)

public int sum(int a,int b) { return a + b;}

1,2

3

Page 13: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

13

The General RMI Architecture

Local/Remote machines

Registry Skeleton Stub

RMI Server

skeleton

stub

RMI Client

Registry

bind

lookupreturn call

Local Machine

Remote Machine

Page 14: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

14

The Stub and Skeleton

A client invokes a remote method, the call is first forwarded to stub. The stub is responsible for sending the remote call over to the server-side skeleton

The stub opening a socket to the remote server, marshaling (encoding in standard, independent format) the object parameters and forwarding the data stream to the skeleton.

A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation.

Stu

b

RMI Client RMI Server

skeleton

return

call

Page 15: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

15

Steps for Developing an RMI System1. Define the remote interface

2. Develop the remote object by implementing the remote interface

3. Develop the client program

4. Compile the Java source files

5. Generate the client stubs and server skeletons

6. Start the RMI registry

7. Start the remote server objects

8. Run the client

Page 16: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

16

Step 1: Defining the Remote Interface

To create an RMI application, the first step is the defining of a remote interface between the client and server objects.

/* SampleServer.java */import java.rmi.*;

public interface SampleServer extends Remote{ public int sum(int a,int b) throws RemoteException;}

Page 17: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

17

Step 2: Develop the Remote Object and its InterfaceThe server is a simple unicast remote server.

Create server by extending java.rmi.server.UnicastRemoteObject.

/* SampleServerImpl.java */

import java.rmi.*;

import java.rmi.server.*;

import java.rmi.registry.*;

public class SampleServerImpl extends UnicastRemoteObject implements SampleServer

{

SampleServerImpl() throws RemoteException

{

super();

}

Page 18: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

18

Step 2: Develop the remote object and its interface

Implement the remote methods

/* SampleServerImpl.java */

public int sum(int a,int b) throws RemoteException

{

return a + b;

}

}

Page 19: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

19

Step 2: Develop the remote object and its interface

/* SampleServerImpl.java */ public static void main(String args[]) { try {

//set the security manager System.setSecurityManager(new RMISecurityManager());

//create a local instance of the object SampleServerImpl Server = new SampleServerImpl();

//put the local instance in the registry Naming.rebind("SAMPLE-SERVER" , Server);

System.out.println("Server waiting....."); } catch (java.net.MalformedURLException me) { System.out.println("Malformed URL: " + me.toString()); } catch (RemoteException re) { System.out.println("Remote exception: " + re.toString()); } }

Page 20: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

20

Step 3: Develop the client program In order for the client object to invoke methods on the server, it

must first look up the name of server in the registry. You use the java.rmi.Naming class to lookup the server name.

The server name is specified as URL in the form (rmi://host:port/name )

Default RMI port is 1099. The name specified in the URL must exactly match the name

that the server has bound to the registry. In this example, the name is “SAMPLE-SERVER”

The remote method invocation is programmed using the remote interface name (remoteObject) as prefix and the remote method name (sum) as suffix.

Page 21: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

21

Step 3: Develop the client programimport java.rmi.*;

import java.rmi.server.*;

public class SampleClient

{

public static void main(String[] args)

{

// set the security manager for the client

System.setSecurityManager(new RMISecurityManager());

//get the remote object from the registry

try

{

System.out.println("Security Manager loaded");

String url = "//localhost/SAMPLE-SERVER";

SampleServer remoteObject = (SampleServer)Naming.lookup(url);

System.out.println("Got remote object");

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

}

catch (RemoteException exc) {

System.out.println("Error in lookup: " + exc.toString()); }

catch (java.net.MalformedURLException exc) {

System.out.println("Malformed URL: " + exc.toString()); }

catch (java.rmi.NotBoundException exc) {

System.out.println("NotBound: " + exc.toString());

}

}

}

Page 22: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

22

Step 4 & 5: Compile the Java source files & Generate the client stubs and server skeletons

Once the interface is completed, you need to generate stubs and skeleton code. The RMI system provides an RMI compiler (rmic) that takes your generated interface class and procedures stub code on its self.

javac SampleServer.java

javac SampleServerImpl.java

rmic SampleServerImpl

javac SampleClient.java

Page 23: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

23

Step 6: Start the RMI registry

RMI Registry must be started manually. The rmiregistry us uses port 1099 by default. You can also

bind rmiregistry to a different port by indicating the new port number as : rmiregistry <new port>

rmiregistry (Unix)

start rmiregistry (Windows)

Page 24: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

24

Steps 7 & 8: Start the remote server objects & Run the client Once the Registry is started, start the

server. Set the security policy

java –Djava.security.policy=policy.all SampleServerImpl

java –Djava.security.policy=policy.all SampleClient

More at http://www.neward.net/ted/Papers/JavaPolicy/

Page 25: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

25

Page 26: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

26

ExternalApplication

Java Technologies

J2EE Framework

Page 27: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

27

J2EE Container

Component Based Architecture

Applications are built from components– Java class files

– Configuration files (usually XML)

– Data files (html, images, directories,…)

Components are packaged into archives for deployment– jar : Java Application Resource

– war : Web Application Resource

– ear : Enterprise Application Resource

Page 28: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

28

N-tier application

View application server as a data store Leverage data abstraction

Today

Page 29: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

29

N-Tier Application

Page 30: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

30

N-Tier Application

OVER

LDAP

Page 31: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

31

N-Tier Application

Page 32: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

32

N-Tier Application

Page 33: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

33

N-Tier Application

Page 34: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

34

N-Tier Complexity

Page 35: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

35

Business Logic

Page 36: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

36

Business Logic

datadata

PROCESS

OUTPUT

INPUT

datadata

Page 37: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

37

N-Tier Complexity

Page 38: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

38

N-Tier Complexity

Page 39: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

39

N-Tier Complexity

Page 40: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

40

N-Tier Complexity

Page 41: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

41

N-Tier Complexity

Page 42: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

42

N-Tier Complexity

Page 43: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

43

ServletsJSP/XML/XSLT

SessionBeans

EntityBeans

Page 44: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

44

Java Technologies

ExternalApplication

Page 45: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

45

EJB

Enterprise Java Bean

Bean – originally a Java class with get() and set() methods– e.g.: getFirstName(), setFirstName()

EJBs come in 3 flavors:

Page 46: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

46

EJB – Entity Bean

Entity Bean

Represent actual data items (e.g. rows in a result set)

Two forms of Entity Bean– Container managed persistence:

DB interactions handled by the J2EE environment– Bean managed persistence: requires that the bean carries out DB interactions

itself

May be called across network connection (RMI)

Page 47: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

47

Session Bean

Model a process or task

Represent resources private to the client

May update shared data

Two forms of Session Bean

– Stateful: state maintained between method calls

– Stateless

One client per session bean instance

EJB – Session Bean

Page 48: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

48

Used in conjunction with Java Messaging System

Activated on JMS message arrival

No state maintained between activations

APPLICATION

message queue

EJB – Message Driven Bean

*****

*

*session facade

Page 49: 1 Distributed Objects Naim R. El-Far, PhD Candidate TA for SEG3202 Software Design and Architecture with N. El- Kadri (Summer 2005) Tutorial 3 of 4 – 10/6/2005.

49

Conclusion

Applying engineering principles to software

Need Scalability Distribution, modularity, OO, etc

Distributed Objects – the main idea Distributed Object technologies: Java

RMI, J2EE, and next time … .NET and CORBA