Distributed Programming in Java - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Distributed Programming in Java

Description:

Binding: registration of the service with the registry so remote clients can locate it ... bind(name, obj) Binds remote object to name. rebind(name, obj) ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 33
Provided by: peopleScs
Category:

less

Transcript and Presenter's Notes

Title: Distributed Programming in Java


1
Distributed Programming in Java
  • Distribution (2)

2
(No Transcript)
3
Remote Method Invocation
  • Remote Method Invocation (RMI)
  • Primary design goal for RMI is transparency
  • Should be able to invoke remote objects with same
    syntax and semantics as local ones
  • However, some important differences exit
  • Refresher in the introduction to this course we
    presented the key differences ...

4
Remote is not Like Local
  • Latency data transfer time is several orders of
    magnitude slower
  • Memory access refs in local address space are
    not valid in a remote address space
  • Concurrency may be unexpected and un-planned
    interaction of computing tasks
  • Partial failure can be indeterminacy due to the
    lack of a central authorityFamous paper by
    Waldo, J., et al, A Note on Distributed
    Computing, http//research.sun.com/techrep/1994/sm
    li_tr-94-29.pdf

5
Detailed Comparison (1)
  • Object behavior Interface
  • Object implementation class
  • Object creation directly create
  • Object reference variable
  • Exception catch

6
Detailed Comparison (2)
  • Object behavior
  • Behavior exported by a remote object is defined
    in an interface
  • Object implementation
  • Class that implements this interface
  • Object creation
  • Clients cannot directly create instances of a
    remote class (unless using activation)

7
Detailed Comparison (3)
  • Object access
  • Remote objects accessed through remote reference
    variable (a client proxy)
  • Active references
  • Remote objects are considered to have an active
    reference if they have been accessed recently
    (during a certain lease period)
  • Exceptions
  • Remote exceptions exposed to client

8
Separation of Behavior and Implementation
  • Remote object behavior defined in an interface
    (Service)
  • Remote object behavior implemented in a server
    class (ServiceImpl)
  • Proxy sends request to remote object

9
Broker pattern
10
RMIArchitecture Layers
Also see Layers pattern
11
Layers
  • Decouple the abstraction levels of an application
    by splitting it into several loosely connected
    layers (of related services)

12
Stubs and Skeletons
  • Stub
  • Represents server object on client side
  • Implements remote interface
  • Knows how to forward method calls
  • Skeleton
  • Represents client object on server side
  • Calls services on the service object
  • Knows how to forward results to client
  • Skeletons are no longer required, as the JDK
    invokes the server methods via reflection

13
Using RMI
  • Define interfaces for remote objects
  • Define implementations for interfaces
  • Create stub (and skeleton) classes
  • Develop a server that creates an instance of the
    service implementation
  • Develop a client that uses the service provided
    by the remote interface
  • Start the RMI registry, server and client

14
1. Define Remote Interface
  • Define an interface of the remote object
  • Contract between a server and its clients
  • Must extend the Remote interface
  • Methods may throw a RemoteException

15
2. Implement Interface
  • Implementation of the remote interface
  • Extends UnicastRemoteObject class (or exports a
    remote reference explicitly)
  • Constructor of base class exports object

16
3. Create Stubs
  • Generate stub (and skeleton) classes using the
    RMI compiler (rmic)
  • Generates a stub class
  • ServiceImpl_Stub (implements interface)
  • -keep option keeps stub source

17
4. Develop Server
  • Create an instance of the service (that is, the
    implementation of the remote interface)
  • Registers the service in naming service

18
Registry
  • RMI can use different naming services
  • A simple service is the Registry
  • Each RMI service is identified by a URL with the
    protocol rmi
  • Binding registration of the service with the
    registry so remote clients can locate it

19
rmi.Naming
  • bind(name, obj)Binds remote object to name
  • rebind(name, obj)Binds remote object to name,
    even if bound
  • unbind(name)Removes binding of name
  • lookup(url)Returns remote object bound to url
  • list(url)Returns list of names in registry

20
5. Develop Client
  • Develop a client that uses the service provided
    by the remote interface
  • Can be a local or a remote object
  • Client must first locate a remote object before
    its methods can be invoked

21
6. Starting the Application
  • Default port 1099
  • Registers instance under assigned name
  • We need to specify a security policy

22
Security Policy
  • Security policies introduced in JDK 1.2
  • A policy specifies which permissions (e.g. to
    read or write files, read from sockets) are
    available to code from different sources
  • Policy for an application specified in policy
    file, typically using policytool in JDK
  • Remote servers need to define a security manager
    in order to enforce policies

23
Example Policy
  • Grant permissions to all sources to connect and
    accept on sockets for the given ports
  • Restricts what actions downloaded classes (here,
    stubs) can perform
  • Connect/accept on ports 1024-65535
  • Connect on port 80 (web servers)

24
RMI example
  • An interesting use of RMI is described in
    http//www.itec.uni-klu.ac.at/harald/ds2001/rmi/p
    attern/pattern2.html

25
Print Server
  • Implements a print server to which one can submit
    print jobs, list, and cancel them
  • Users will be notified when job is complete
  • We will start with a design without notification,
    that is, only printer classes need to expose a
    remote interface ...
  • ... to add notification we need to support
    callbacks on the client (also interface)

26
Print Server
27
Printer
  • Defines remote interface
  • PrintJobs must be serializable

28
PrinterImpl_Stub
  • Let us look behind the scenes of how stubs work
    they implement ClientProxy, and use a Requestor
    in the form of a RemoteRef
  • Example PrinterImpl_Stub.java (which you can
    generate with the rmic -keep)

29
Most Common Errors
  • java.rmi.ConnectException
  • Registry not started
  • java.rmi.MarshalException
  • Not subclassing UnicastRemoteObject
  • Default constructor cannot handle the exception
    type RemoteException
  • No default constructor
  • Not a valid remote interface
  • Methods must throw RemoteExceptions
  • java.rmi.StubNotFoundException
  • No stub found

30
Callbacks
  • Users will be notified when job is complete

31
Callback Interface
  • PrinterClient is now the remote object, and needs
    to implement a Remote interface
  • Extend submit() method to allow clients to
    register themselves for notifications

32
PrinterClient
  • In the example we illustrate an alternative
    technique to export a remote reference
  • This has the same effect as subclassing from
    UnicastRemoteObject (why care?)
Write a Comment
User Comments (0)
About PowerShow.com