Java RMI and WS - PowerPoint PPT Presentation

About This Presentation
Title:

Java RMI and WS

Description:

Skeleton: A class of remote object has a skeleton that implements of the remote interface. ... For a method it marshals an object of class Method into the request. ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 39
Provided by: binarama
Learn more at: https://cse.buffalo.edu
Category:
Tags: rmi | java

less

Transcript and Presenter's Notes

Title: Java RMI and WS


1
Java RMI and WS
  • B. Ramamurthy

2
Inside RMI
  • http//java.sun.com/j2se/1.5.0/docs/index.html
  • Basic RMI classes /usr/java1.1/src/java/rmi
  • java.rmi.registry.
  • java.rmi.Naming class (static/class methods)
  • java.rmi.Remote interface (marker interface)
  • java.rmi.server.
  • Default RMI port 1099
  • Both lookup from local and remote are acceptable.

3
Implementation of RMI (5.2.5)
4
The role of proxy and skeleton in remote method
invocation
server

client
remote
skeleton
object B
object A
proxy for B
Request
dispatcher
for Bs class
Reply
servant
Communication
Remote reference
Communication
Remote
module
module
module
reference module
Object A invokes a remote object in Object B for
which it holds a remote object reference. System
Model
5
RMI Internals Communication Module
  • Carries out request-reply protocol
  • On the client side message type, message id,
    remote reference to object are gathered and sent
    out. At most once invocation semantics
  • On the server side, it gets local reference for
    remote reference from remote reference module,
    invokes a dispatcher with this reference.
  • See UnicastRemote (implements UnicastRemote)

6
RMI Internals Remote Reference module
  • Responsible for translating between local and
    remote object references and for creating remote
    object references.
  • A remote object table has a mapping between local
    and remote references. A table at server (entry
    for object ref for B) and a table at client
    (entry for object ref for proxy B).

7
RMI Internals Remote References
  • Action of remote reference module See
    RemoteRef.java interface
  • When a remote object is to be passed as argument
    or result for the first time, the remote ref is
    asked to create a remote ref object which is
    added to the table.
  • When a remote object reference arrives in a
    request or reply, the remote ref module is asked
    for corresponding local object ref, which may
    either a proxy or remote object. If it is not in
    the table RMI runtime creates it and asks remote
    ref module to add it to the table.

8
RMI Internals RMI software
  • Layer of software between application level
    objects and communication and remote reference
    modules Middleware
  • Proxy provides remote access transparency. One
    proxy for every remote object in the client.
  • Dispatcher A server has one dispatcher and
    skeleton for each class representing a remote
    object.
  • It receives request message from comm. Module
  • It used MessageId to select appropriate method in
    skeleton.
  • Proxy and dispatcher use same MessageId.
  • Skeleton A class of remote object has a skeleton
    that implements of the remote interface. All the
    access dependencies are hidden in this class. A
    remote object has a servant that directly
    implements the methods. Java 5 creates this
    dynamically.
  • Proxies, dispatcher and skeleton are
    automatically generated by interface compiler.
  • Binder binds textual names to remote object
    references. RMiRegistry is a binder Naming
    class see fig.5.13
  • Server Threads one thread per invocation
  • Distributed garbage collection See Andrew
    Birells paper 1995.

9
RMI Internals Distributed Garbage Collection
  • Based on reference counts.
  • Local garbage collectors and a distributed
    support.
  • Each server holds the list of processes that hold
    remote object references for example, B.Holders
  • When a client C first receives a remote reference
    to a particular remote object, say B, it makes a
    addRef(B) invocation to server of that remote
    object and then creates proxy server adds C to
    B.Holders.
  • When client Cs garbage collector finds that
    proxy is no longer reachable (ref count), it
    makes a removeRef(B) invocation to server and
    then deletes proxy the server removes C from
    B.Holders.
  • When B.Holders is empty, servers local garbage
    collector will reclaim the space occupied B
    unless there are any local holders.
  • These extra calls for updates occur during proxy
    creation and deletion and do not affect normal
    opertion.
  • Tolerates communication failures addRef() and
    removeRef() are idempotent effects of N gt 0
    identical requests is the same as for a single
    request.
  • If addRef() fails with an exception, proxy is not
    created, removeRef() is transmitted removeRef()
    failures are dealt with by leases (Jini kind).

10
RMI Internals Use of Reflection
  • What is reflection? (See Reflection package)
  • Reflection enables Java code to discover
    information about the fields, methods and
    constructors of loaded classes, and
  • To use reflected fields, methods, and
    constructors to operate on their underlying
    counterparts on objects, within security
    restrictions.
  • http//java.sun.com/docs/books/tutorial/reflect/cl
    ass/index.html
  • Reflection feature allowed for dynamic creation
    of skeleton and proxy in Java 2 version onwards.
  • Skeleton has been deprecated since JDk1.4.x
  • Read more about reflection model of computing.

11
A Little bit of Reflection
  • Method class, invoke method
  • Invoke method requires two parameters first the
    object to receive invocation, second an array of
    Object parameters.
  • Invoke executes the method on the object and
    returns result as Object.
  • Method m
  • Object result m.invoke(String, Args)

12
Using Reflection in RMI
  • Proxy has to marshal info. about a method and its
    arguments into a request message.
  • For a method it marshals an object of class
    Method into the request. It then adds an array of
    objects for the methods arguments.
  • The dispatcher unmarshals the Method object and
    its arguments from request message.
  • The remote object reference is obtained from
    remote ref. table.
  • The dispatcher then calls the invoke method on
    the object reference and array of arguments
    values.
  • After the method execution the dispatcher
    marshals the result or any exceptions into the
    reply message.

13
Putting it all together
  • Server side
  • Write a an interface and implement it. Implements
    Remote,
  • Inside code publishes the object by (exporting to
    runtime) and by registering it.
  • Client Side
  • Code look up server object name from the
    registry host, port
  • Invoke operations.

14
Lifecycle of a remote call
  • First time, an operation is invoked, remote
    object reference is obtained from remote
    registry, addRef() is sent to remote server, an
    entry made in the local ref table and proxy is
    created.
  • Proxy has message ids while the clients ref
    table has remote object reference.
  • Remote ref, method id and arguments are marshaled
    into a message and sent across via the
    communication module.

15
Lifecycle of a remote call (contd.)
  • On the server side RMI runtime maps the remote
    reference to a local object.
  • Unmarshalls the operation and parameters and uses
    reflection to invoke the method on the object
    reference.
  • The result is marshaled back into the response
    and sent back to the caller.
  • Skeleton that includes the dispatch is
    subsumed into the RMI runtime in the latest
    versions of Java.

16
Critique of RMI (Sun Javas) /RPC (Microsofts)
  • Performs very well for single-platform limited
    distributed system.
  • Platform dependent
  • Tightly coupled
  • Inherently synchronous (No chance for eventing or
    notification)
  • Object-oriented Objects not deployable units
  • Non-standard
  • Not scalable, location dependent, no global
    registry/discovery
  • Object reference passed as parameter and/or
    returned as result.

17
Interface Semantics
Process1
Process2
getCustomer()
retrieveCustomerData()
returnResult()
Semantics of the activity is explicitly stated in
the message/method call
18
Payload Semantics
Envelop With message
Process 1
Process 2
Requested transaction/activity is embedded in the
message Details of the activity not explicit the
semantics are embedded in the message
19
Payload Semantics
onMessage()
20
Payload semantics is generic
  • String transferMoney (amt decimal, accTo
    String)
  • String executeService (message String)

21
XML
  • XML is a markup language, developed by W3C (World
    Wide Web Consortium), mainly to overcome the
    limitations of HTML.
  • But it took a life of its own and has become a
    very popular part of distributed systems.
  • We will examine its definition, associated
    specifications (DTD, XSLT etc.), Java APIs
    available to process XML, protocols and services
    based on XML, and the role XML plays in a
    distributed computing environment.

22
Memo.html vs memo.xml
  • lt!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
    Transitional//EN"gt
  • lthtmlgt
  • ltheadgt
  • ltmeta http-equiv"content-type"
  • content"text/html charsetISO-8859-1"gt
  • lttitlegtmemo.htmllt/titlegt
  • lt/headgt
  • ltbodygt
  • lth3gtHello Worldlt/h3gt
  • Binaltbrgt
  • CSE4/586 Students ltbrgt
  • Good Morning everyoneltbrgt
  • BRltbrgt
  • ltbrgt
  • lt/bodygt
  • lt/htmlgt
  • lt?xml version"1.0" ?gt
  •   lt!DOCTYPE memo (View Source for full
    doctype...)gt
  • - ltmemogt
  •   ltheadergtHello Worldlt/headergt
  •   ltfromgtbinalt/fromgt
  •   lttogtCSE4/586 Studentslt/togt
  •   ltbodygt Good Morning everyonelt/bodygt
  •   ltsigngtbrlt/signgt
  •   lt/memogt

23
XML to SOAP
  • Simple xml can facilitate sending message to
    receive information.
  • The message could be operations to be performed
    on objects.
  • Simple Object Access Protocol (SOAP)

24
Web Services
  • Web Services is a technology that allows for
    applications to communicate with each other in a
    standard format.
  • A Web Service exposes an interface that can be
    accessed through messaging.
  • Deployable unit.
  • A Web service uses protocol to describe an
    operation and the data exchange with another web
    service. Ex SOAP
  • Platform independent, say, through WSDL.
  • Publishable, discoverable, searchable, queryable
  • Scalability issues A group of web services
    collaborating accomplish the tasks of a
    large-scale application. The architecture of such
    an application is called Service-Oriented
    Architecture (SOA).

25
Web Services and SOA
  • Web Services is a technology that allows for
    applications to communicate with each other in a
    standard format.
  • A Web Service exposes an interface that can be
    accessed through XML messaging.
  • A Web service uses XML based protocol to describe
    an operation or the data exchange with another
    web service. Ex SOAP
  • A group of web services collaborating accomplish
    the tasks of an application. The architecture of
    such an application is called Service-Oriented
    Architecture (SOA).

26
A Little bit of History XML to SOAP
  • Simple xml can facilitate sending message to
    receive information.
  • The message could be operations to be performed
    on objects.
  • Standardize the tags for object access.
  • Simple Object Access Protocol (SOAP).

27
SOAP Request (Not WS request)
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt ltsoapBodygt
ltgetProductDetails xmlns"http//warehouse.example
.com/ws"gt ltproductIdgt827635lt/productIdgt
lt/getProductDetailsgt lt/soapBodygt
lt/soapEnvelopegt
28
SOAP Reply
ltsoapEnvelope xmlnssoap"http//schemas.xmlsoap.
org/soap/envelope/"gt ltsoapBodygt
ltgetProductDetailsResponse xmlns"http//warehouse
.example.com/ws"gt ltgetProductDetailsResultgt
ltproductNamegtToptimate 3-Piece
Setlt/productNamegt ltproductIdgt827635lt/prod
uctIdgt ltdescriptiongt3-Piece luggage set.
Black Polyester.lt/descriptiongt
ltpricegt96.50lt/pricegt ltinStockgttruelt/inSto
ckgt lt/getProductDetailsResultgt
lt/getProductDetailsResponsegt lt/soapBodygt
lt/soapEnvelopegt
29
SOAP?Web Services (WS)
  • Take a look at
  • 1. http//www.w3.org/DesignIssues/WebServices.html
  • 2. OReilly book on Web Services Kim Topleys
    Webservices in a Nutshell http//www.oreilly.com/
    catalog/javawsian/index.html
  • This link has a sample chapter (SAAJ) and zip
    of all examples in the book.

30
Web Services (Colouris)
  • A web service provides a service interface
    enabling clients to interact with servers in a
    more general way than web browsers do.
  • Clients access operations in the interface
    usually by XML messages over http.
  • However other architectural models such as REST
    and CORBA could access WS.
  • WSDL provides additional details than for
    standard operation for encoding, security,
    communication and location.

31
Web services infrastructure and components
32
SOAP message in an envelope
envelope
header
header element
header element
body
body element
body element
33
Example of a simple request without headers
envenvelope
xmlnsenv namespace URI for SOAP envelopes
envbody
mexchange
xmlnsm namespace URI of the service description
marg1
marg2
Hello
World
In this figure and the next, each XML element is
represented by a shaded box with its name in
italic followed by any attributes and its content
34
Example of a reply corresponding to the request
in
35
Use of HTTP POST Request in SOAP client-server
communication
endpoint address
POST /examples/stringer
HTTP header
Host www.cdk4.net
Content-Type application/soapxml
action
Action http//www.cdk4.net/examples/stringerexch
ange
ltenvenvelope xmlnsenv
namespace URI for SOAP envelope
gt
ltenvheadergt lt/envheadergt
Soap message
ltenvbodygt lt/envbodygt
lt/envEnvelopegt
36
Services, ports and bindings
  • Service endpoint interface (SEI) or service
    endpoint that defines one or more operations that
    the web service offers.
  • Access to an endpoint is provided by binding it
    to a protocol stack through a port.
  • A port has an address that the client can use to
    communicate with the service and invoke its
    operations.
  • An endpoint can be bound to different ports each
    offering a different suite of protocols for
    interaction.

37
Endpoint, Port and binding
Web service
endpoint
Port1 port2
port3
Web services Client
SOAP 1.1 over https
SOAP1.1 Over http
Other. Ex ebXML over SMTP
https 1.1 transport soap1.1 messages
38
WS Interoperability Infrastructure
Service Description
WSDL
XML Messaging
SOAP
Network
HTTP
Write a Comment
User Comments (0)
About PowerShow.com