Table of Contents

~~SLIDESHOW~~

Distributed Computing

Distributed Computing APIs

RMI (Remote Method Invocation)

Java RMI

Remote Interfaces


  1. Remote interface must be public.
  2. Must extend java.rmi.Remote.
  3. Must declare java.rmi.RemoteException in its throws clause (plus any other application-specific exceptions).
  4. Any object passed as an argument must be serializable.
  5. A remote object, passed as an argument or return value must be declared as the remote interface, not the implementation class.

Structure of an RMI Application

An RMI Application

A remote time service

1|Example 1: a remote time service (at-m42/Examples/lecture11/TimeHereI.java)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture11/TimeHereI.java

The remote object

1|Example 2: the remote object (at-m42/Examples/lecture11/TimeHere.java)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture11/TimeHere.java

Setting up the server

Starting the registry

start rmiregistry 2005

The Server

1|Example 3: register the remote method via Groovy (at-m42/Examples/lecture11/startTimeHere.groovy)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture11/startTimeHere.groovy
rmiregistry  2005 &

Some potential problems

Registration for RMI serving

LocateRegistry.createRegistry(2005);

We’re not finished yet!

networking infrastructure for RMI

The stub and skeleton

rmic uk.ac.swan.egm42.rmi.TimeHere

Now we can write the client

l|Example 4: RMI client in Groovy (at-m42/Examples/lecture11/displayTimeHere.groovy)
extern> http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture11/displayTimeHere.groovy

RMI Deployment

RMI deployment

Calling the remote method

Calling the remoet method

To Make it Work (1)

grant {
  permission java.security.AllPermission;
};

Not this setting effectively turns Java's security system. It should never be used on a production server!

To Make it Work (2)

<cli prompt='>'> e:\dev\at-m42-2009\Examples\lecture11>groovy startTimeHere.groovy Ready to tell time </cli>

<cli prompt='>'> e:\dev\at-m42-2009\Examples\lecture11>groovy displayTimeHere.groovy Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 Time on remote server: Thu Apr 16 19:44:33 BST 2009 </cli>

Distributed Computing APIs

Object Serialization

How RMI uses Serialization

Passing an Object 1

Passing an Object 1

Passing an Object 2

Passing an Object 2

Passing an Object 3

Passing an Object 3

Passing an Object 4

Passing an Object 4

Thought Question

Thought question

Hint

hint

Distributed Computing APIs

Naming and Directory Services

JNDI: Accessing Naming and Directory Services

JNDI – the facts

Distributed Computing APIs

CORBA and SOAP

What is CORBA?

CORBA vs. RMI

RMI-IIOP

A One Slide Guide to SOAP

Source: Technical Note: SOAP 1.1, 8/5/2000. http://www.w3.org/TR/SOAP.


A problem with SOAP is that it uses HTTP as a transport protocol, primarily to avoid firewall problems (HTTP messages are normally allowed through corporate firewalls).

Distributed Computing APIs

Restful Web Services

“Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The terms 'representational state transfer' and 'REST' were introduced in 2000 in Roy Fielding's doctoral thesis2).” Wikipedia article

In summary, the five key principles3)


Notes: Fielding was one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification. REST is a set of principles that define how Web standards, such as HTTP and URIs, are supposed to be used. If you adhere to REST principles you will end up with a system that exploits the Web's architecture to your benefit.

Give every "thing" an ID

On the web any individual object can have a URL:

http://game.com/players/1234
http://game.com/actions/2009/04/17/26
http://game.com/items/4554
http://game.com/processes/move/east

But so can collections:

http://example.com/actions/2007/11
http://example.com/items?weight=10 

This makes it easy for both web browsers and other programs to be able to find objects that need to be manipulated in a distributed system.

Some made up XML:

<inventory carrier='http://game.com/players/1234' > 
   <weight>120</weight> 
   <potency>12</potency>
   <item ref='http://games.com/items/4554' /> 
   <item ref='http://games.com/items/4556' /> 
</order> 

Represents the inventory of a player in our game (could of course be HTML is a web application, but I wanted to emphasize machine-to-machine communication). Note that we are using familiar concept to link to define relationships. Thus to find out more, e.g. about one of the items being carried, the application can navigate to that resource via its URL.

Use standard methods

A traditional Object-Based distributed game


You can see that there are two services defined here (without implying any particular implementation technology). The interface to these services is specific to the task – it's a GameManagement and PlayerManagement service we are talking about. If a client wants to consume these services, it needs to be coded against this particular interface – there is no way to use a client that was built before these interfaces were specified to meaningfully interact with them. The interfaces define the services' application protocol.

RESTful services


You can see that what have been specific operations of a service have been mapped to the standard HTTP methods – and to disambiguate, we have created a whole set of new resources.

Essentially, this makes your application part of the Web – its contribution to what has turned the Web into the most successful application of the Internet is proportional to the number of resources it adds to it. In a RESTful approach, an application might add a few million game item URIs to the Web; if it’s designed the same way applications have been designed in CORBA times, its contribution usually is a single “endpoint” – comparable to a very small door that provides entry to a universe of resource only for those who have the key.

The uniform interface also enables every component that understands the HTTP application protocol to interact with your application.

To summarize: For clients to be able to interact with your resources, they should implement the default application protocol (HTTP) correctly, i.e. make use of the standard methods GET, PUT, POST, DELETE.

Resources with multiple representations

GET /players/1234 HTTP/1.1
Host: game.com 
Accept: text/html
GET /players/1234 HTTP/1.1
Host: game.com 
Accept: application/atom+xml

There is a significant benefit of having multiple representations of a resource in practice: If you provide both an HTML and an XML representation of your resources, they are consumable not only by your application, but also by every standard Web browser — in other words, information in your application becomes available to everyone who knows how to use the Web.

Communicate statelessly

Impact of REST

Distributed Computing APIs

JINI: distributed services

JINI: Peer-to-Peer Networking

An example of JINI in use

Summary

What Should You Remember?

Apart from some special cases, current trend (as we'll see) is away from distributed computing using RMI, CORBA and SOAP towards a Web-Based architecture constructed from user-facing HTML clients consuming RESTful services over HTTP and with machine-to-machine communications exploiting XML resource exchange over HTTP. JINI is a niche technology that was in the doldrums for a long time. JNDI, RMI, and SOAP are still important in Enterprise Application Development, but over time, I would expect them to become relegated to very specialized “back office” applications.


Home | Previous Lecture | Lectures | Next Lecture

1)
must be full path to class rooted at remote server’s classpath.
2)
Fielding, Roy Thomas (2000) (HTML), Architectural Styles and the Design of Network-based Software Architectures, Doctoral dissertation, University of California, Irvine
3)
Stefan Tilkov, Stefan (2007), A Brief Introduction to REST, InfoQ, Dec 10.