EPDA - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

EPDA

Description:

... using.CopyUrl doesn't like my.next.door.neighbour to be able to call readFile() on it's machine! ... RPC requires a lot more overhead than RMI: ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 34
Provided by: psae
Category:
Tags: epda | door | overhead

less

Transcript and Presenter's Notes

Title: EPDA


1
EPDA
  • Enterprise Distributed Programming with Remote
    Method Invocation
  • (RMI)

2
Agenda
  • Introduction to RMI
  • RMI Architecture
  • RMI Implementation
  • An Example

3
Introduction
  • EJB is a scalable platform and is interoperable
    with heterogeneous clients
  • It can communicate with protocols such as IIOP
    (Internet Inter ORB) and JRMP (Java Remote
    Method) protocols through JNDI.
  • JNDI provides an interface for Java Naming and
    Directory services.
  • RMI uses JRMP
  • EJB containers can build functionality through
    technologies such as RMI, JNDI, JDBC,

4
Traditional Distributed Applications are
  • Concerned with the movement of data and files
    between hosts using protocols such as SMTP,
    FTP,HTTP, NFS,
  • Applications can also let one host run programs
    on another host.
  • Traditional examples of remote execution are
  • Telnet, RPC, rlogin,

5
RMI - introduction
  • Java has a facility called RMI to let objects on
    different hosts communicate.
  • A Java program can call certain methods on a
    remote server.
  • RMI doesnt need the client or the server to run
    an HTTP server.

6
RMI - introduction
  • Each remote object implements a remote interface
    that specifies which of its methods can be
    invoked by a client.
  • RMI is efficient
  • A client can ask a database object on a server to
    sum up a series of records
  • and return the result
  • rather than downloading all the records and
    summing them locally!

7
From programmers perspective
  • Remote methods work similar to the local ones.You
    need to
  • import one package,
  • make sure to catch the Remote Exceptions,
  • lookup the remote object in a registry
  • and use it the same way as a local one

8
Example
  • An object at sunsite.berkeley.edu has a query
    method that looks up information in a data base
  • A client on www.staffs.ac.uk can look up the
    object in sunsites registry to call the query
    method as it would do in a local object.
  • The remote object accepts arguments from
    www.staffs.ac.uk and returns the results back to
    it.

9
Security Issues
  • my.mirror.using.CopyUrl doesnt like
    my.next.door.neighbour to be able to call
    readFile() on its machine!
  • We can secure this by limiting the activities of
    the remote object using
  • a SecurityManager object that
  • checks all operations to make sure they are
    allowed by the server.

10
RPC and RMI
  • RPC is language and processor independent
  • RMI is processor-independent, but limited to
    Java.
  • RPC requires a lot more overhead than RMI
  • Convert arguments between architectures to use
    native data types
  • Little-endian and big-endian
  • RPC can only send primitive data types RMI can
    send objects.

11
The RMI Architecture RMI Layer Model
  • Ensures communication compatibility between a
    remote object client and a server.

Server Program
Client Program
Logical Path
Skeleton
Stub/Skeleton
Remote Reference Layer
Remote Reference Layer
The Internet
Transport Layer
Transport Layer
12
The RMI Layer Model
  • The client talks only to its stub which
  • passes the conversation along to the remote
    reference layer (RRL)
  • The transport layer on the client passes data
    across the Internet to
  • the transport layer of the server which talks to
    the RRL which
  • talks to a piece of server software called the
    skeleton

13
The RMI Layer Model
  • The skeleton communicates with the server itself
  • In the server-to-client direction this flow is
    reversed

14
How a client finds a server?
  • Where does the stub come from?
  • Client finds an appropriate server by using a
    registry.
  • The registry has a method called lookup() that
    finds the stub for the client.

15
The stub - Client side
  • Client uses it to invoke a remote method.
  • It doesnt have to be compiled into the client
    can be downloaded at run time.
  • The stubs are used in clients virtual machine in
    place of real objects and methods live on the
    server
  • Think of the stub as the remote objects
    surrogate on the client.

16
The Remote Reference Layer- Client side
  • Translates the local reference to the stub into a
    remote reference to the object on the server.
  • Then it passes the data to the transport layer

17
The Transport Layer- Client Side
  • Handles the actual movement of data across the
    Internet
  • Provides
  • Connection setup
  • Connection Management and
  • Tracking and dispatching of remote objects

18
The Transport Layer- Server Side
  • Listens for incoming connections
  • Forwards invocations to the remote reference layer

19
The Remote Reference Layer -Server Side
  • Converts the remote references into references
    for the local virtual machine
  • Then passes the request to the skeleton

20
The Skeleton- Server side
  • Reads the arguments and passes the data to the
    server program, which makes the actual method
    call.
  • If the method returns a value, the value is sent
    down through
  • the skeleton, remote reference , and transport
    layers across the Internet
  • and then up through the layers on the client side.

21
RMI Implementation Parameter passing
  • Pass by reference (by referring to
    something-address..)
  • only works if all objects are in the same virtual
    machine
  • Pass by value
  • primitive types such as boolean, int, double
  • complete copies are passed
  • Pass by remote reference
  • for objects that implement the Remote Interface

12/15/98
22
The RMI Implementation
  • Most of the methods are in four packages
  • java.rmi package
  • Defines classes, interfaces and exceptions on the
    client side
  • java.rmi.server package
  • Defines classes, interfaces and exceptions
    visible on the server side
  • java.rmi.registry package
  • Defines classes, interfaces and exceptions for
    locating and naming remote objects
  • java.rmi.dgc package
  • Handles distributed garbage collection

23
Implementing a server- A Hello Interface Java
Network Programming., E.R. Harold
  • To implement a remote object, first define an
    interface
  • This remote interface does not have methods of
    its own. It only tags objects as remote

// A simple interface for a Hello World remote
object implementing // a single method,
sayHello() import java.rmi. public interface
Hello extends java.rmi.Remote public String
sayHello() throws java.rmi.RemoteException
24
A Server-HelloImpl class
  • Now define a class that implements the remote
    interface.
  • This class extends java.rmi.UnicastRemoteObject
    that make remote invocation work
  • marshalling, unmarshalling, etc.
  • The HelloImpl class implements the remote
    interface Hello
  • It has a sayHello method that will be available
    to the client

25
A Server-HelloImpl class
  • The main method starts the remote server running

import java.rmi. import java.rmi.server. impor
t java.net. import java.util. public class
HelloImpl extends
java.rmi.server.UnicastRemoteObject implements
Hello public HelloImpl() throws
RemoteException super() public String
sayHello() throws RemoteException return
"Hello, World!"
26
A Server- HelloIMpl class
  • ...

public static void main(String args)
System.setSecurityManager (new
RMISecurityManager()) try HelloImpl h
new HelloImpl () Naming.rebind("HelloPServer"
, h) System.out.println("Hello Pirooz Server
ready.") catch (RemoteException re)
System.out.println("Exception in
HelloImpl.main " re) catch
(MalformedURLException e) System.out.println(
"MalformedURLException in HelloImpl.main "
e)
17
27
A server ..
  • The sayHello() Method returns the string Hello,
    world! to clients
  • An instance of HelloImpl object is bound to the
    name helloPserver in the Naming registry using
    rebind() method.

28
Now generate stubs and skeletons
  • The stub contains the information in the Remote
    interface (sayHello)
  • The skeleton is similar but on the server side.
  • To generate the stub and skeleton for HelloImpl
    remote object, run rmic on the .class file
  • rmic HelloImpl

29
rmic
  • produces .class file of the remote object, and
    produces .class files for the stubs and
    skeletons
  • Hello.class HelloImpl.class
    HelloImpl_Skel.class
  • Hello.java HelloImpl.java
    HelloImpl_Stub.class

30
Now start the registry and launch the server
  • rmiregistry 2050
  • runs the registry on port 2050 for the server to
    talk to it
  • and now launch the server

java HelloImpl Hello Pirooz Server Ready.
Now the server and the registry are ready to
accept remote method calls
31
The Client Side- The HelloClient
  • Client asks the registry on the server to
    retrieve a remote reference to remote object.
  • It calls the registrys lookup method
  • Before using the object you must cast it to the
    remote interface- pass an rmi URL to the lookup()
    method

Hello h (Hello) Naming.lookup
("rmi//enterprise.soc.staffs.ac.uk/HelloPServer")

32
The Client Side- The HelloClient
  • Now the client can call the remote methods

import java.rmi. public class HelloClient
public static void main(String args)
System.setSecurityManager (new
RMISecurityManager ()) try Hello h
(Hello) Naming.lookup ("rmi//enterprise.soc.staff
s.ac.uk/HelloPServer") String message
h.sayHello () System.out.println
("HelloClient " message)
catch (Exception e) System.out.println
("Exception in main " e)
33
Summary of what happened
  • The client talks to the registry and the server

Lookup() where is Hello?
Hello Client
Here it is
Registry
Send the stub
HelloImpl_Stub.class
This is the stub
Stub
HelloImpl_Skel.class
sayHello()
HelloImpl.class
Hello
Client
Server
Write a Comment
User Comments (0)
About PowerShow.com