41
A Look at Jini Jian He Roy Patrick Tan

A Look at Jini Jian He Roy Patrick Tan. Outline History Design Goals An Example Basic Components Top View Infrastructures --- Proxies, Discovery/join

Embed Size (px)

Citation preview

A Look at Jini

Jian HeRoy Patrick Tan

Outline

• History• Design Goals• An Example• Basic Components• Top View• Infrastructures ---Proxies, Discovery/join and Lookup

• Programming Models --- Leasing, Events andTransactions

• Transactions

• Hello World!

• JavaSpaces

• Comparisons

• Jini and Corba

• Jini and EJB

• Jini and OAA

• Current State

• References

History

• 1990, Oak. • 1994, WebRunner HotJava• 1995, Java made Internet history.• Bill Joy leads Sun’s new project ---Jini

“Jini Is Not Initials”• 1999, Jini becomes public. “It is fulfillment of original Java idea of an environment for embedded systems.”

Design Goals

• Robust software infrastructure• Enable a service-based architecture• Support “plug and participate” networking• Devices can form spontaneous communities• Ease distributed computing

– Network latency– Concurrency/Synchronization

– Memory management– Inevitable partial failure

An Example- a Jini-enabled printer

An Example (cont.)

Multicast query for lookup services

An Example (cont.)

LUS (lookup service) is discoverdiscovered.

An Example (cont.)

Printer registers (joins) service object (proxy) with LUS.

Client asks LUS for printer.

An Example (cont.)

An Example (cont.)

LUS returns the printer service object (proxy) to client.

Client talks to the printer by using the service object (proxy).

An Example (cont.)

Basic Components

• A service• A client• A lookup service

Top View

Top View (cont.)

?

Infrastructure --- Proxies

• Downloadable• Zero-administration• Proxy scenarios:

– it may perform the service itself;– it may be an RMI stub for some remote service;– it may act as a “smart” adapter, which provides a Jini interface to legacy (non-Java) services (sockets, CORBA, hardware-dependent protocols, etc.).

Infrastructure --- Discovery/Join/Lookup

• Services: discover and join a group of services by using UDP multicast. Unicast is also supported to connect to a particular lookup service. • Lookup services: store authenticated services as Java objects and periodically advertise to network by using UDP multicast.• Clients: download service proxies on demand from lookup services.

Infrastructure (cont.)

Programming Model --- Leasing

• Why? -- Self-healing for partial failures.• What? -- Time-based grants of

– Services: the registered status in lookup services.– Clients: the allocated services.

• How? It can be– Renewed– Cancelled– Expired

Programming Model -- Leasing

ServiceLookupService

Leaseregister(proxy, lease)

Proxy

LookupService

Proxy

Programming Model -- Leasing

Service

Leaserenew()

cancel() Lease

Programming Model --- Events

• Why? -- Interesting external changes.• What? -- Extended Java event model

– Asynchronous (JavaBeans, JFC)– Out of order delivery and partial failures

• How?– RemoteEvent class– RemoteListener interface– EventRegistration interface

Programming Model --Transactions

• Jini supports transactions – distributed object coordination

• Two-phase commit• Implemented as Transaction

Manager service• Not often used

Two Phase Commit: Prepare

TransactionManager

Svc 2

Svc 1Prepare

Prepare

Ok!

Ok!

Two Phase Commit: Commit

TransactionManager

Svc 2

Svc 1Commit!

Commit!

TransactionParticipant

public interface TransactionParticipant extends Remote, TransactionConstants {

int prepare(TransactionManager mgr, long id);

void commit(TransactionManager mgr, long id);

void abort(TransactionManager mgr, long id);

int prepareAndCommit(TransactionManager mgr, long id);

}

Hello World!

First declare the interface

public interface HelloWorldService {

public string getMessage();

}

The Hello World Proxy• Proxy – the code to be downloaded

class HelloWorldServiceProxy implements Serializable, HelloWorldServiceInterface {

public HelloWorldServiceProxy() { }

public String getMessage() {return "Hello, world!";

} }

The Hello World Service

public class HelloWorldService implements Runnable { // 10 minute leases protected final int LEASE_TIME = 10 * 60 * 1000; … class Listener implements DiscoveryListener { … public void discovered(DiscoveryEvent ev) { ServiceRegistrar[] newregs = ev.getRegistrars(); … if (!registrations.containsKey(newregs[i])) { registerWithLookup(newregs[i]); } } }

Hello World Service (cont’d)

protected synchronized void registerWithLookup(ServiceRegistrar registrar) {

ServiceItem item; item = new ServiceItem(null, createProxy(), null); ServiceRegistration registration = null; try { registration = registrar.register(item, LEASE_TIME); } catch (RemoteException ex) { System.out.println("Couldn't register: " + ex.getMessage()); return; }}

Hello World Clientpublic class HelloWorldClient implements Runnable { … class Listener implements DiscoveryListener { … }

public HelloWorldClient() throws IOException { Class[] types = { HelloWorldServiceInterface.class }; template = new ServiceTemplate(null, types, null); … // Only search the public group disco = new LookupDiscovery(new String[] { “Public" }); // Install a listener disco.addDiscoveryListener(new Listener()); }

Hello World Client (cont’d)

protected Object lookForService(ServiceRegistrar lusvc) { Object o = null; try { o = lusvc.lookup(template); } catch (RemoteException ex) { System.err.println("Error doing lookup: "); } if(o != null) { System.out.println("Got a matching service."); System.out.println("It's message is: " + ((HelloWorldServiceInterface) o).getMessage()); } return o;}

JavaSpaces

• One of the first Jini services• Based on tuple spaces (Linda)• 3 fundamental operations:

– Read– Write– Take

JavaSpaces

JavaSpaces

JavaSpaces• JavaSpaces has typed entries for example:

• Use transactions to move objects between JavaSpaces

Import net.jini.core.entry.Entrypublic class Student implements Entry { public String pid; public String name; public Student() {}}

JavaSpaces

• Different approach to distributed computing

• Information Sharing -- shared message board.

• Compute serving -- Image Processing compute farm

• Workflow -- Document routing

Jini and CORBA

• Jini has code mobility (proxy objects are more than stubs)

• Jini solves initial reference problem• CORBA is cross-language• CORBA components can be

wrapped as Jini services

Jini and EJB

• EJB is used for “static” server environment

• Jini is designed for more volatile services

• Jini can be used for web services as well. Example: travel services consolidator.

Jini and OAA

• Similar technologies• Jini has code mobility• Facilitator more intelligent than Jini

lookup services• Jini is Java based, OAA is multi-

language

Current State of Jini

• Not very popular• 75 Commercial Licensees• 80,000 downloads• Free to try: SCSL Licensing• Reorienting from devices to (web)

services

References

• http://www.sun.com/jini • http://www.jini.org • W. Keith Edwards, Core Jini, Prentice Hall, 1999• W.Keith Edwards, Jini Example by Example, Prentice

Hall, 2001• Stephen L. Halter, Java Spaces• http://billday.com/Work/ • http://www.eng.auburn.edu/center/irsc/comp0690/

jinioverview.ppt