570 likes | 672 Views
Les Ejb. Les EJB sont à CORBA ce qu est le circuit précablé à la carte mère électronique. Introduction. Les applications monolithique Pas de réutilisation des modèles de données Pas de réutilisation des modèles de traitements Les applications C/S (au sens large)
E N D
Les Ejb • Les EJB sont à CORBA ce quest le circuit précablé à la carte mère électronique Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Introduction • Les applications monolithique • Pas de réutilisation des modèles de données • Pas de réutilisation des modèles de traitements • Les applications C/S (au sens large) • Réutilisation des modèles de données • Pas de réutilisation des modèles de traitement • Les applications à base de middleware • Réutilisation des modèles de données et de traitements • Notion de composants serveurs Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les serveurs d'applications Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Architectures à Objet Distribués MiddleWare Services Métiers Application 1 Application 2 Services d'infrastructure Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur de composants de base Services Métiers Application 1 Services standard d'infrastructure jts cycle vie Application 2 jdbc version Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur de composants intégré Composants Métiers Application 1 Logique métier container infrastructure Gestion automatisée Service d'infrastructure de base Application 2 jdbc jts version cycle vie Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Services du container d'EJB • Services internes • Gestion de la charge du serveur • (cycle de vie, accès client, passivation...) • Service de nommage • Gestion des accès aux objets métiers • Services externes • Gestion du mapping sur BD relationnelle • Gestion des transactions • Gestion des échanges de messages Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur Web dynamique Serveur Web Application 1 Application 2 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur Web dynamique Serveur Web Application 1 CGI CGI Application 2 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur Web dynamique Serveur Web Application 1 LiveWire Php Application 2 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur Web dynamique (Servlets / JSP) Serveur Web Application 1 Servlets Servlets Application 2 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Services du container de pages Web • Servlet / JSP • Services internes • Gestion de la charge du serveur • cycle de vie • Gestion des autorisations d'accès • Services externes • API Java Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Un serveur d'application • Application Java • Hébergeant : • Des containers • Pages Web • Composants Métier (EJB) • Des services • Nommage • Base de données/Mapping sur Base • Moniteurs transactionnels • Déploiement ... • Des API sur les services • JDBC/JTS/JMS... Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
The J2EE Architecture Applet Servlet EJB JSP Application Client Databases Applet container Web container EJB container J2SE http/ssl Java Mail Java Mail JMS JMS Application Client Container JNDI JNDI JDBC JDBC RMI/IIOP RMI/IIOP JTA JTA JAF JAF J2SE J2SE rmi/ssl JMS JNDI JDBC RMI/IIOP J2SE Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les offres de serveur d'applications • Serveur d'application J2EE • Weblogic BEA,WebSphere IBM, Iplanet Sun, Oracle • WebObject (Jonhatan/Jonas) INRIA • Jboss (Free) • Autres serveurs d'applications • Microsoft .net • Zope (Python) • Serveur CORBA (OrbixWeb) Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les serveurs d'EJB Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveur de composants intégré Composants Métiers Application 1 Logique métier container infrastructure Gestion automatisée Service d'infrastructure de base Application 2 jdbc jts version cycle vie Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Serveurs distribués Container Container Appli 1 2 1 Services Services Appli 2 jdbc jdbc Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Enterprise JavaBeans • Enterprise Java Beans : • Composants logiciels serveur • Objectif • Standardiser le développement et le déploiement de composants serveurs écrits en Java • Le développement ne se fait que sur l'interface métier de l'objet • Le développeur ne prend en compte que la logique métier de l'EJB. Le reste est prise en charge par le containeur. Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Principe de conception des EJB • Le modèle des EJB est fondé sur trois concepts pour la conception de systèmes distribués • Approche de serveurs sans-états • Approche orientée session • Approche objet persistant • Les spécifications EJB parlent de • Session Beans • Stateless Session Bean • Statefull Session Bean • Entity Beans • Container-Managed Persistence • Bean-Managed Persistence Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Le Bean "stateless Session" • Leurs comportements • Fournissent un service pour un seul utilisateur • Ne maintiennent pas d'état par rapport au client • Ne survivent pas à un crash du serveur d'EJB • Sont plutôt destinés à vivre sur une courte période • Deux instances d'un même bean « sans état » sont identiques Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les Bean "statefull Session" • Leurs comportements • Interagissent d'une manière conversationnelle • Maintiennent un état sur le client connecté • Ne survivent pas à un crash du serveur d'EJB • Vivent rapidement • Une instance est hébergée par un seul thread • Une instance peut être partagée par plusieurs clients Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Stateful vs. Stateless • Un bean stateful maintient un état conversationnel qui est récupéré entre deux invocations • Un bean stateless n'a pas d'état entre les appels sur ses méthodes Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Exemples de Beans Session Session Stateless Un EJB qui calcule le cos(x) Un décompacteur Un EJB qui vérifie si une donnée est valide Un EJB qui calcule le coût d'une communication téléphonique Session Statefull Un EJB qui gère une réservation Un EJB qui commande les pièces détachées d'un véhicule Un EJB qui gère le flux d'information d'un centre d'appel Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Stateful vs. Stateless EJB client client serveur container skell OM client client Les clients partagent le même contexte client client serveur container client OM skell OM client OM Un client possède son propre contexte sur un EJB stateful Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Etat d’un EJB Session Stateful • L’état d'un EJB de type stateful est défini comme la fermeture transitive des objets visibles par les champs du bean Instance d'un chat int age=5 Instance d'une souris capture int age=7 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
EJB Stateful identiques ? • Deux EJB stateful sont identiques s'ils partagent le même contexte client ! client client serveur container skell OM client client Les clients partagent la même référence distante Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Comment obtenir la même référence distante ? client client Ce client crée la nouvelle instance 1 serveur container Le client dépose le handle dans une base skell 2 OM Ce client récupère le handle 3 Le client utilise le handle pour créer la même référence distante 4 client client Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les EJB Entité (Entity EJB) • Leurs comportement • Ils représentent les données persistantes • Ils survivent à un crash • Plusieurs clients peuvent utiliser des EJB qui "pointent" sur les mêmes données • L'instance EJB contient une copie des données du système de stockage Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Gestion de la persistance Stockage Mappage ? • Les attributs d'un objet doivent être déposés sur un support persistant • Exemples de supports de persistance : • Sérialisation • Accès à une base sur le JDBC (mappage) Client id=98282 nom=frenot adresse=34 ville=villeurbanne Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Partage d'EJB entity • Quand plusieurs clients partagent un EJB entity ils • reçoivent leurs propres instance d'EJB • partagent les données sous-jacentes • n'ont pas à gérer la synchronisation sur les données client client serveur container client OM skell OM client OM Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Type de persistance • Il y a deux mode de gestion de la persistance • Container-Managed Persistence (CMP) • Bean-Managed Persistence (BMP) 1 container OM CMP OM BMP Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
EJB Entité • Exemples : • Un EJB qui représente les statistiques d’un site • Un EJB qui représente l'évolution d'une cotation • Un EJB qui représente une séquence du génôme • ... Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Rôle du développeur d'EJB • Définition des interface distantes • L'interface « Remote » contient les opérations « métier » d'un EJB • Définition de l'usine de fabrication des EJB • L'interface « Home » d'un EJB • Est utilisée par les clients pour créer et/ou retirer un EJB • Fournit des méta informations sur l'EJB • Est partagée par tous les clients de l'EJB • Voit son stub d'invocation placé dans le service de nommage au déploiement • Définition du corps de l'EJB • Implantation concrète des services métier Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Exercice • Un EJB qui implante C-MesCources ? • Un EJB qui gère un cours en vidéo ? • Un EJB qui gère le passage du TOEIC ? • Un EJB qui calcule de la vitesse de rotation des planètes ? • Un EJB qui représente le compte bancaire d'une personne ? • Un EJB qui gère un appel de support technique ? • Un EJB qui calcule la valeur de remboursement d'un prêt ? • Un EJB de gestion de chaîne Hi-Fi ? • Un EJB qui liste les personnes connectées sur un réseau ? • Un EJB qui contrôle la validité d'un cookie d'une page Web ? • Un EJB qui représente un document Word ? • Un EJB qui représente une enchère sur un site ? Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Le fonctionnement global jndi 5 3 4 1 Client 2 OM Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Deux principes clés : les interfaces • Interface « home » • Interface de l'usine de fabrication des OM • Est utilisée par les clients pour créer un EJB • Est utilisée par un client pour retirer un EJB • Fournit des méta informations sur l'EJB • Est partagée par tous les clients de l'EJB • Voit son stub d'invocation placé dans le service de nommage au déploiement • Interface « remote » • Représente l'OM distant (stub) Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les optimisations Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Pooling d'objets client client • Un serveur d'application peut créer un pool d'objets « nus » qui peuvent être utilisés quand des requêtes sont faites EJB pool Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
La passivation • La passivation est le fait de placer un EJB sur un support secondaire • La passivation : • A lieu quand un EJB dépasse son idle-timeout • Permet à un serveur d'application de réclamer des ressources • Placer une instance sérialisée de l'EJB dans son support de stockage Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Pooling / Passivation sur Weblogic client client Ne peut pas exc₫der maxBeansInCache Objets passiv₫s EJB cache Un client re₤oit CacheFullException si le cache est plein et rien ne peut ₨tre passiv₫ Un EJB est passiv₫ s il a d₫pass₫ idleTimeoutSeconds Les objets sont plac₫s dans le pool libre quand les clients en ont fini Ne peut pas exc₫der maxBeansInFreePool Free Pool Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Application et logique métier Logique d'application Logique métier Accès données IHM DBMS Ses Ett Ses Ses Ses Ett EJB Container Nommage, Sécurité, Cycle de vie, Accès concurrents, Transaction, Persistance Serveur d ’application Distribution, Equilibrage de charge, Tolérance de pannes Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Les rôles dans le monde EJB • Fournisseur de serveur d'application • Fournit le serveur intégré avec des services de base • Fournisseur de container • Fournit les containeurs d'EJB • Fournisseur d'EJB • Expert dans un domaine vertical; crée les composants EJB • Développeur d'application • Assemble les applications à partir de composants EJB préfabriqués • Spécialiste du déploiement • Déploie les applications • Maîtrise les principes d'architecture Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Cycle de développement • Implantation de la base de données (opt.) • Implantation des EJB (SL/SF/Entity) • Implantation des JSP Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Cycle de développement d'un EJB session 1) Définir les interfaces métier Interface Remote 2) Définir les méthodes de gestion du cycle de vie Interface Home 3) Définir les caractéristiques intrinsèques du bean dans un fichier de description 4) Définir les caractéristiques de déployement 5) Déployer le bean 6) Réaliser le(s) clients qui utilisent le service Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Interface Métier Interface Remote de l'EJB fibonacci package exemple.fibonacci; public interface Fibonacci extends javax.ejb.EJBObject { public int getFibonacciNumber(int n) throws java.rmi.RemoteException; } Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Interface Home Interface Home de l'EJB fibonacci package exemple.fibonacci; import javax.ejb; import java.rmi; public interface FibonacciHome extends EJBHome { public Fibonacci create() throws CreateException, RemoteException; } Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Développement du Bean package exemple.fibonacci; import java.rmi.*; import javax.ejb.*; public class FibonacciBean implements SessionBean { public void ejbPassivate(){} public void ejbActivate(){} public void ejbRemove(){} public void setSessionContext(SessionContext ctx){} public void ejbCreate() { System.out.println("Cet EJB Fibonacci est créé"; } public int getFibonacciNumber(int n){...} } Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Descripteur du Bean <?xml version="1.0"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> <enterprise-beans> <session> <ejb-name>Fibonacci</ejb-name> <home>exemple.fibonacci.FibonacciHome</home> <remote>exemple.fibonacci.Fibonacci</remote> <ejb-class> exemple.fibonacci.FibonacciBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> ... </enterprise-beans> </ejb-jar> Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr
Descripteur du déploiement <?xml version="1.0"?> <!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd" > <weblogic-ejb-jar> <weblogic-enterprise-bean> <ejb-name>fibonacci</ejb-name> <stateless-session-descriptor> <pool><max-beans-in-free-pool>100</max-beans-in-free-pool></pool> </stateless-session-descriptor> <transaction-descriptor> <trans-timeout-seconds>300</trans-timeout-seconds> </transaction-descriptor> <jndi-name>fibonnaci</jndi-name> </weblogic-enterprise-bean> </weblogic-ejb-jar> Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr