Mini project - 2001/2 Jini - a new computing paradigm.

Slides:



Advertisements
Similar presentations
CS Network Programming CS 3331 Fall CS 3331 Outline Socket programming Remote method invocation (RMI)
Advertisements

Message Passing Vs Distributed Objects
1 Jini Tutorial, Part 3 Jini Programming. 2 Tutorial outline Part 1 Introduction Distributed systems Java basics Remote Method Invocation (RMI) Part 2.
Jini, third verse Richard Chapman October 13, 1999.
1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Remote Method Invocation
Introduction to Jini & JavaSpaces
Notes to the presenter. I would like to thank Jim Waldo, Jon Bostrom, and Dennis Govoni. They helped me put this presentation together for the field.
J2ME RMI 1 Java 2 Platform, Micro Edition Implementation of J2ME RMI Application Farooq Sheikh.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
6/13/2015B.Ramamurthy1 System Models Bina Ramamurthy (Based on Slides from CDK text)
Comparison of the RMI and the socket APIs
CS 603 Jini April 10, What is Jini? Java Middleware Tools to construct federation –Multiple devices, each with Java Virtual Machine –Multiple services.
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Jini Connection Technology Kaushik Lahoti. Jini: A Vision n Areas to focus on –Simplicity –Reliability –Scalability.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
RMI Components java.rmi: client-side RMI classes, interfaces, and exceptions java.rmi.server: server-side RMI classes, interfaces, and exceptions java.rmi.registry:
1 Java Programming II Java Network II (Distributed Objects in Java)
Introduction - What is Jini Technology?
1 Vrijendra Gokhale, Bernard Menezes K. R. School of Information Technology IIT Bombay User Interfaces for Jini Services The Jini Pattern Language Workshop.
+ A Short Java RMI Tutorial Usman Saleem
Sun’s Jini Lab 2 Service Registration Client Lookup.
A Look at Jini Jian He Roy Patrick Tan. Outline History Design Goals An Example Basic Components Top View Infrastructures --- Proxies, Discovery/join.
Java Remote Method Invocation (RMI) ). Distributed Systems  a collection of independent computers that appears to its users as a single coherent system.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Example: RMI Program How to write it.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
1 Lecture 16 Jini Technology Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
1 JSK 1.1 A practical Approach Contents –Working with JSK 1.1 –Jini environments –Writing Jini software revisited –Important software packages in the JSK.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Jini Architectural Overview Li Ping
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Distributed programming in Java Faculty:Nguyen Ngoc Tu Session 5 - RMI.
Jini Technology 제 1 회 한국 자바 개발자 컨퍼런스 발표자 : 강신동 Mobile : 소속 : ㈜ idosi.com 대표이사 주최 : JavaCommunity.Org.
Netprog Java RMI1 Remote Method Invocation.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 20 A little more on RMI Getting started with.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
Java Distributed Computing
Java Distributed Computing
Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
The Jini Technology: An overview
Creating a Distributed System with RMI
Jini Instructors: Geoffrey Fox and Bryan Carpenter
Creating a Distributed System with RMI
Remote Method Invocation
JINI ICS 243F- Distributed Systems Middleware, Spring 2001
Creating a Distributed System with RMI
Introduction to Web Services
Could Jiro™ Extend the Jini™ Pattern Lanuguage?
Java Remote Method Invocation
Changing the way of designing distributed applications
Creating a Distributed System with RMI
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Mini project /2 Jini - a new computing paradigm

Our first jini steps … basic topics: 1.RMI overview. 2.a first jini application: “ hello world ”. rmi

RMI-remote method invocation provides a way for Java applications running on different JVM ’ s/host computers to “ talk ” to each other.

basic ideas/concepts: 1.remote interface. 2.stubs and skeletons - rmic. client server Remote interface Remote impl stubskeleton

3.serialization. 4.parameters and return values. 5.dynamic code loading. 6.security implications. 7.marshaled objects. 8.the activation framework - rmid.

Jini basics

3 main components 1.service 2.client 3.jini environment - rmi,web server, lookup service...

service Device that shares its capabilities with other devices Devices Requirement –Memory & CPU –Connection to Network E.g. TV, Microwave,Printer,PC,Software

client A device that uses services Requirement –Memory & CPU –Connection to Network E.g. PDA, WAP Phone, PC, Coke Machine

The Jini environment Service Consumer Service Provider Jini Lookup Service

How does it works? 1.create the jini environment-lookup server online. 2.services discover,join and register on lookup servers. 3.clients discover and finds matching and downloading services, then using them.

Our first jini application - hello world! 1.compiling & running the jini env. 2.compiling & running a)server. b)client.

Creating The jini environment: 1.run a http server (jini provides a simple but efficient one) 2.run a rmi daemon (exists on Java 2) 3.run a lookup server (supplied with the reggie.jar files in jini)

Running the environment command lines: http server: java -jar java archive /usr/local/Java/jini1_1/lib/tools.jar jini’s http -port dir /usr/local/Java/jini1_1/lib the server’s root directory -verbose& Rmi daemon: rmid -J-Dsun.rmi.activation.execPolicy=none -port log /tmp/rmid_log& rmi log directory-recvering...

Running the environment command lines: Lookup server: java -Djava.security.policy=/usr/local/Java/jini1_1 /example/lookup/policy.all policy -jar /usr/local/Java/jini1_1/lib/reggie.jar lookup service codebase /usr/local/Java/jini1_1/example/lookup/policy.all /tmp/reggie_log1 public& policy

Compiling the server and client programs: Compile the server class: javac -classpath /usr/local/Java/jini1_1/lib/jini- core.jar:/usr/local/Java/jini1_1/lib/jini- ext.jar:/usr/local/Java/jini1_1/lib/sun- util.jar:/users/studs/bsc/2000/liyboviz/files/service -d /users/studs/bsc/2000/liyboviz/files/service /users/studs/bsc/2000/liyboviz/files/corejini/chapter5/HelloWorldS erviceInterface.java /users/studs/bsc/2000/liyboviz/files/corejini/chapter5/HelloWorldS ervice.java Compile the client class: javac -classpath /usr/local/Java/jini1_1/lib/jini- core.jar:/usr/local/Java/jini1_1/lib/jini- ext.jar:/usr/local/Java/jini1_1/lib/sun-util.jar: -d /users/studs/bsc/2000/liyboviz/files/client /users/studs/bsc/2000/liyboviz/files//corejini/chapter5/HelloWorld ServiceInterface.java /users/studs/bsc/2000/liyboviz/files/corejini/chapter5/HelloWorldC lient.java

Running - first the server, then the client: Server http: java -jar /usr/local/Java/jini1_1/lib/tools.jar -port dir /users/studs/bsc/2000/liyboviz/files/service-dl -verbose& The Service: java -cp /usr/local/Java/jini1_1/lib/jini- core.jar:/usr/local/Java/jini1_1/lib/jini- ext.jar:/usr/local/Java/jini1_1/lib/sun- util.jar:/users/studs/bsc/2000/liyboviz/files/service -Djava.rmi.server.codebase= -Djava.security.policy=/usr/local/Java/jini1_1/example/lookup /policy.all corejini.chapter5.HelloWorldService&

Running – then, the client: The Client: java -cp /usr/local/Java/jini1_1/lib/jini-core.jar: /usr/local/Java/jini1_1/lib/jini-ext.jar: /usr/local/Java/jini1_1/lib/sun-util.jar: /users/studs/bsc/2000/liyboviz/files/client -Djava.security.policy=/usr/local/Java/jini1_1/example/lookup /policy.all corejini.chapter5.HelloWorldClient&

Screen output From the service: >discovered a lookup service! >set serviceID to e91bb ty7554 From the client: >Got matching service. >Its message is: Hello, world!

What ’ s behind the screen?

The client/server known interface: // This is the interface that the service's proxy // implements package corejini.chapter5; public interface HelloWorldServiceInterface { public String getMessage(); }

The server ’ s code: // This is the first iteration of a Hello, World // service--it publishes a proxy that returns // a string when asked by clients. package corejini.chapter5; import net.jini.discovery.DiscoveryListener; import net.jini.discovery.DiscoveryEvent; import net.jini.discovery.LookupDiscovery; import net.jini.core.lookup.ServiceItem; import net.jini.core.lookup.ServiceRegistrar; import net.jini.core.lookup.ServiceRegistration; import java.util.Hashtable; import java.io.IOException; import java.io.Serializable; import java.rmi.RemoteException; import java.rmi.RMISecurityManager;

// This is the proxy object that will be downloaded // by clients. It's serializable and implements // our well-known HelloWorldServiceInterface. class HelloWorldServiceProxy implements Serializable, HelloWorldServiceInterface { public HelloWorldServiceProxy() { } public String getMessage() { return "Hello, world!"; }

// HelloWorldService is the "wrapper" class that // handles publishing the service item. public class HelloWorldService implements Runnable { // 10 minute leases protected final int LEASE_TIME = 10 * 60 * 1000; protected Hashtable registrations = new Hashtable(); protected ServiceItem item; protected LookupDiscovery disco; // Inner class to listen for discovery events class Listener implements DiscoveryListener { // Called when we find a new lookup service. public void discovered(DiscoveryEvent ev) { System.out.println("discovered a lookup service!"); ServiceRegistrar[] newregs = ev.getRegistrars(); for (int i=0 ; i<newregs.length ; i++) { if (!registrations.containsKey(newregs[i])) { registerWithLookup(newregs[i]); }}}

// Called ONLY when we explicitly discard a // lookup service, not "automatically" when a // lookup service goes down. Once discovered, // there is NO ongoing communication with a // lookup service. public void discarded(DiscoveryEvent ev) { ServiceRegistrar[] deadregs = ev.getRegistrars(); for (int i=0 ; i<deadregs.length ; i++) { registrations.remove(deadregs[i]);}}} public HelloWorldService() throws IOException { item = new ServiceItem(null, createProxy(), null); // Set a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager());} // Search for the "public" group, which by // convention is named by the empty string disco = new LookupDiscovery(new String[] { "" }); // Install a listener. disco.addDiscoveryListener(new Listener()); }

protected HelloWorldServiceInterface createProxy() { return new HelloWorldServiceProxy();} // This work involves remote calls, and may take a while to complete //Thus, since it's called from discovered(), it will prevent us // from responding in a timely fashion to new discovery events. An // improvement would be to spin off a separate short- // lived thread to do the work. protected synchronized void registerWithLookup(ServiceRegistrar registrar) { ServiceRegistration registration = null; try { registration = registrar.register(item, LEASE_TIME); } catch (RemoteException ex) { System.out.println("Couldn't register: " + ex.getMessage()); return;} if (item.serviceID == null) { item.serviceID = registration.getServiceID(); System.out.println("Set serviceID to " + item.serviceID);} registrations.put(registrar, registration); }

// This thread does nothing but sleep, but it // makes sure the VM doesn't exit. public void run() { while (true) { try { Thread.sleep( ); } catch (InterruptedException ex) { }}} // Create a new HelloWorldService and start // its thread. public static void main(String args[]) { try { HelloWorldService hws = new HelloWorldService(); new Thread(hws).start(); } catch (IOException ex) { System.out.println("Couldn't create service: " + ex.getMessage());}}}

The client ’ s code: // A simple Client to exercise the HelloWorldService package corejini.chapter5; import net.jini.discovery.DiscoveryListener; import net.jini.discovery.DiscoveryEvent; import net.jini.discovery.LookupDiscovery; import net.jini.core.lookup.ServiceRegistrar; import net.jini.core.lookup.ServiceTemplate; import java.util.Vector; import java.io.IOException; import java.rmi.RemoteException; import java.rmi.RMISecurityManager;

public class HelloWorldClient implements Runnable { protected ServiceTemplate template; protected LookupDiscovery disco; // An inner class to implement DiscoveryListener class Listener implements DiscoveryListener { public void discovered(DiscoveryEvent ev) { ServiceRegistrar[] newregs = ev.getRegistrars(); for (int i=0 ; i<newregs.length ; i++) { lookForService(newregs[i]); } public void discarded(DiscoveryEvent ev) { }

public HelloWorldClient() throws IOException { Class[] types = { HelloWorldServiceInterface.class }; template = new ServiceTemplate(null, types, null); // Set a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } // Only search the public group disco = new LookupDiscovery(new String[] { "" }); // Install a listener disco.addDiscoveryListener(new Listener()); }

// Once we've found a new lookup service, search // for proxies that implement // HelloWorldServiceInterface protected Object lookForService(ServiceRegistrar lusvc) { Object o = null; try { o = lusvc.lookup(template); } catch (RemoteException ex) { System.err.println("Error doing lookup: " + ex.getMessage()); return null;} if (o == null) { System.err.println("No matching service."); return null; } System.out.println("Got a matching service."); System.out.println("It's message is: " + ((HelloWorldServiceInterface) o).getMessage()); return o;}

// This thread does nothing--it simply keeps the // VM from exiting while we do discovery. public void run() { while (true) { try { Thread.sleep( ); } catch (InterruptedException ex) { }}} // Create a HelloWorldClient and start its thread public static void main(String args[]) { try { HelloWorldClient hwc = new HelloWorldClient(); new Thread(hwc).start(); } catch (IOException ex) { System.out.println("Couldn't create client: " + ex.getMessage()); }}}

A policy file example grant { // Allow everything for now permission java.security.AllPermission; };

The End To be continued...