info
-
Upload
kurt-mk-jim -
Category
Documents
-
view
212 -
download
0
description
Transcript of info
-
Remote Method Invocation
Remote Method Invocation
Jean-Michel [email protected]
http://www.info.univ-angers.fr/pub/richer
M2 Informatique 2010-2011
1 / 22
-
Remote Method Invocation
Plan
Plan
1 Introduction
2 RMI en details
3 Exemple
4 Application
2 / 22
-
Remote Method Invocation
Introduction
Introduction
Introduction
3 / 22
-
Remote Method Invocation
Introduction
Principe
Le principe applications distribuees (ex. Agence de Voyage) appel de services distants (interaction avec des
objets/services situes sur une autre machine) obtention de donnees distantes (communication donnees
resultat)
4 / 22
-
Remote Method Invocation
Introduction
Technologies
Les technologiesIl existe plusieurs protocoles/frameworks/technologies :
RPC (Remote Procedure Call) RMI (Remote Method Invocation) SUN CORBA (Common Object Request Broker Architecture)-
OMG (Object Management Group) DCOM - Microsoft
5 / 22
-
Remote Method Invocation
Introduction
RMI - SUN
Proprietes de RMI echange dinformation entre deux JVM (Java Virtual
Machine) oriente objet serialisation des objets Java chargement dynamique des objets/services
6 / 22
-
Remote Method Invocation
RMI en details
RMI en details
RMI en details
7 / 22
-
Remote Method Invocation
RMI en details
RMI
RMI-JRMP (Java Remote Method Protocol) version dorigine integree au langage simple dutilisation
RMI-IIOP (Internet InterORB(Object Request Broker) Protocol) version recente comptatible CORBA plus difficile a` mettre en oeuvre
8 / 22
-
Remote Method Invocation
RMI en details
Differences JRMP-IIOP
Differences implantation dun objet distant :
JRMP : UnicastRemoteObject IIOP : PortableRemoteObject
ramasse miettes (garbace collector) : JRMP : implicite (DGC) IIOP : a` realiser (unreferenced())
9 / 22
-
Remote Method Invocation
RMI en details
RMI
Service distantLes fonctionnalites dun service distant sont definies par uneinterface
sur le serveur : linterface est implantee sur le client : linterface sert de proxy (serveur mandataire)
10 / 22
-
Remote Method Invocation
RMI en details
le Skeleton ou` partie Serveur
Le Skeleton (Squelette) objet distant qui implemente les methodes visibles reception des donnees (unmarshall) execution de la methode envoi du resultat (marshall)
NoteAvec Java 2, le squelette est devenu obsole`te.
11 / 22
-
Remote Method Invocation
RMI en details
le Stub ou` partie Client
Le Stub (Souche) representant local de lobjet distant qui implemente les
methodes visibles envoi des parame`tres (marshall) recuperation des donnees (unmarshall)
12 / 22
-
Remote Method Invocation
Exemple
Exemple
Exemple
13 / 22
-
Remote Method Invocation
Exemple
Exemple
ExempleAppel dun objet distant qui realise laddition de deux nombresreels.
14 / 22
-
Remote Method Invocation
Exemple
Interface
Interfacedefinition de linterface de communication : methode add
etend Remote chaque methode est susceptible de generer une exception
partie interface
1 import java.rmi.*;23 public interface Service extends Remote {4 public float add(float a, float b) throws RemoteException;5 }67
15 / 22
-
Remote Method Invocation
Exemple
Implantation
Implantation etend UnicastRemoteObject implante linterface Service implantation de la methode add
partie implantation
1 import java.rmi.*;2 import java.rmi.server.*;34 public class ServiceImpl extends UnicastRemoteObject implements Service {56 public ServiceImpl() throws RemoteException {7 super();8 }9
10 public float add(float a, float b) throws RemoteException {11 return a+b;12 }13 }14
16 / 22
-
Remote Method Invocation
Exemple
Serveur
Implantationenregistrement du service Naming.rebind()partie serveur
1 import java.rmi.*;23 public class ServiceServer {45 public ServiceServer() {6 try {7 ServiceImpl s=new ServiceImpl();8 Naming.rebind(rmi://localhost:1099/Service, s);9 } catch(Exception e) {
10 System.out.println(e.getMessage());11 }12 }1314 public static void main(String args[]) {15 new ServiceServer();16 }17 }18
17 / 22
-
Remote Method Invocation
Exemple
Client
Implantationappel du service Naming.lookup()
partie client
1 import java.rmi.*;23 public class ServiceClient {45 public static void main(String args[]) {6 try {7 Service s=(Service) Naming.lookup(rmi://localhost:1099/Service);8 System.out.println( s.add(4.2f, 3.7f) );9 } catch(Exception e) {
10 System.out.println(e.getMessage());11 e.printStackTrace();12 }13 }14 }15
18 / 22
-
Remote Method Invocation
Exemple
Compilation et execution
Compilationjavac *.javarmic ServiceImpl
Executionshell1> rmiregistryshell2> java ServiceServershell3> java ServiceClient
19 / 22
-
Remote Method Invocation
Application
Application
Application
20 / 22
-
Remote Method Invocation
Application
Application
Partie ServeurCreer un objet distant qui sera charge de fournir la liste despersonnes stockees dans une base de donnees et dont le nomou prenom correspond a` des valeurs fournies en parame`tres.
Partie ClientInterrogation du service distant et affichage des personnessusceptibles de repondre aux crite`res fournis.
21 / 22
-
Remote Method Invocation
Application
Bibliographie
Developpement Web avec J2EE, O Reilly, Eric Sarrion,Paris, 2005, ISBN 2-35402-140-2
Au coeur de Java 2 - Fonctions avancees, Campus Press,Hortsmann et Cornell, 2002, ISBN 2-7440-1332-3
22 / 22
PlanIntroductionRMI en dtailsExempleApplication