Stéphane Frenot - Département Télécommunication - SID - [email protected] II - EJB...

54
Stéphane Frenot - Département Télécommunication - SID - [email protected] II - EJB 1 Les Ejb Les EJB sont à CORBA ce quest le circuit précablé à la carte mère électronique

Transcript of Stéphane Frenot - Département Télécommunication - SID - [email protected] II - EJB...

Page 1: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 1

Les Ejb

Les EJB sont à CORBA ce qu’est le circuit précablé à la carte mère électronique

Page 2: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 2

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

Page 3: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 3

Les serveurs d'applications

Page 4: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 4

Architectures à Objet Distribués

Application 1

Application 2

MiddleWare

Services Métiers

Services d'infrastructure

Page 5: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 5

Serveur de composants de base

Application 1

Application 2

Services Métiers

Services standard d'infrastructure

jdbc

jts

version

cycle vie

Page 6: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 6

Serveur de composants intégré

Application 1

Application 2

container

jdbc jts version cycle vie

Composants Métiers

infrastructure

Logique métier

Service d'infrastructure de base

Gestion automatisée

Page 7: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 7

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

Page 8: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 8

Serveur Web dynamique

Application 1

Application 2

Serveur Web

Page 9: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 9

Serveur Web dynamique

Application 1

Application 2

Serveur Web

CGI

CGI

Page 10: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 10

Serveur Web dynamique

Application 1

Application 2

Serveur Web

Php

LiveWire

Page 11: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 11

Serveur Web dynamique (Servlets / JSP)

Application 1

Application 2

Serveur Web

Servlets

Servlets

Page 12: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 12

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

Page 13: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 13

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...

Page 14: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 14

The J2EE Architecture

Applet container

Applet

J2SE

Application

Client Container

J2SE

ApplicationClient

JMS

JND

I

RM

I/IIOP

JDB

C

Web container EJB container

ServletJSP

JMS

JND

I

JTA

Java Mail

RM

I/IIOP

JDB

CJAF

J2SE J2SE

JMS

JND

I

JTA

Java Mail

RM

I/IIOP

JDB

C

JAF

EJB

Databases

http/ssl

rmi/ssl

Page 15: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 15

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)

Page 16: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 16

Les serveurs d'EJB

Page 17: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 17

Serveur de composants intégré

Application 1

Application 2

container

jdbc jts versioncycle vie

Composants Métiers

infrastructureLogique métier

Service d'infrastructure de baseGestion automatisée

Page 18: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 18

Serveurs distribués

Appli 1

Appli 2

Container

jdbc

1

Services

Container

jdbc

2

Services

Page 19: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 19

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.

Page 20: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 20

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

Page 21: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 21

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

Page 22: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 22

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

Page 23: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 23

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

Page 24: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 24

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

Page 25: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 25

Stateful vs. Stateless EJBclientclient serveur

container

OMskell

clientclient

Les clients partagent le même contexte

clientclient serveurcontainer

OMskell

client

client

Un client possède son propre contexte sur un EJB stateful

OM

OM

Page 26: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 26

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

Instance d'une sourisint age=5

captureint age=7

Page 27: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 27

EJB Stateful identiques ?

• Deux EJB stateful sont identiques s'ils partagent le même contexte client !

clientclient serveurcontainer

OMskell

clientclient

Les clients partagent la même référence distante

Page 28: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 28

Comment obtenir la même référence distante ?

clientclient

serveurcontainer

OMskell

clientclient

1 Ce client crée la nouvelle instance

2 Le client dépose le handle dans une base

3 Ce client récupère le handle

4 Le client utilise le handlepour créer la même référence distante

Page 29: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 29

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

Page 30: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 30

Gestion de la persistance

• 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)

Clientid=98282nom=frenotadresse=34ville=villeurbanne

StockageMappage ?

Page 31: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 31

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

clientclient serveurcontainer

OMskell

client

client

OM

OM

Page 32: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 32

Type de persistance

• Il y a deux mode de gestion de la persistance– Container-Managed Persistence (CMP)– Bean-Managed Persistence (BMP)

container

OMCMP

1

OMBMP

Page 33: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 33

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– ...

Page 34: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 34

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

Page 35: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 35

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 ?

Page 36: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 36

Le fonctionnement global

OM

Client

jndi

1

2

34

5

Page 37: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 37

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)

Page 38: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 38

Les optimisations

Page 39: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 39

Pooling d'objets

• Un serveur d'application peut créer un pool d'objets « nus » qui peuvent être utilisés quand des requêtes sont faites

EJB poolclient

client

Page 40: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 40

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

Page 41: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 41

Pooling / Passivation sur Weblogic

EJB cache

client

client

Free Pool

Les objets sont plac₫s dans le pool libre quand les clients en ont fini

Objets passiv₫s

Un EJB est passiv₫ s ’il a d₫pass₫ idleTimeoutSeconds

Ne peut pas exc₫der maxBeansInFreePool

Ne peut pas exc₫der maxBeansInCache

Un client re₤oit CacheFullException si le cache est plein et rien ne peut ₨tre passiv₫

Page 42: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 42

Distribution, Equilibrage de charge, Tolérance de pannes

Application et logique métier

Nommage, Sécurité, Cycle de vie, Accès concurrents, Transaction, Persistance EJB C

ontai

ner

Serv

eur d

 ’app

licati

on

Logique d'application

Logique métier

Accès données

Ett

Ett

SesSes DBMS

Ses

SesIHM

Page 43: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 43

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

Page 44: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 44

Cycle de développement

• Implantation de la base de données (opt.)

• Implantation des EJB (SL/SF/Entity)

• Implantation des JSP

Page 45: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 45

Cycle de développement d'un EJB session

1) Définir les interfaces métierInterface Remote

2) Définir les méthodes de gestion du cycle de vieInterface 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

Page 46: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 46

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;

}

Page 47: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 47

Interface Home

Interface Home de l'EJB fibonaccipackage exemple.fibonacci;

import javax.ejb;

import java.rmi;

public interface FibonacciHome extends EJBHome {

public Fibonacci create() throws CreateException, RemoteException;

}

Page 48: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 48

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){...}

}

Page 49: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 49

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>

Page 50: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 50

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>

Page 51: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 51

Déploiement du bean

• Eventuellement (pré-compilation)

• Jar + cp

• Au déploiement – Inscription de l'Usine (interface Home) sur le

containeur– Dépôt du stub de manipulation de l'Usine sur le

service de nommage

Page 52: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 52

Développement d'un client

public class Client{

public static void main(String [] argv){

try{

FibonacciHome home=(RobotHome)context.lookup("fibonaci");

Fibonacci jacques=home.create();

}catch(NamingException e){

}catch(CreationException e){

}catch(RemoteException e){}

}

}

Page 53: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 53

Développement d'un client JSP

<html><head><title> <%= pagetitle %> </title></head>

<h2><font color=#DB1260><%= pagetitle %></font></h2>

<%@ page import="edt.matiere.*"%>

<%!String pagetitle = "JSP emploi du temps : Les FaceAFaces";%>

<%try {

ctx = getInitialContext();

homeFib = (FibonnacciHome) ctx.lookup("fibonnaci");

uneSuite=homeFib.create();

out.println("fib(7)="+uneSuite.getFibonacciNumber(7));

}catch(Exception e){e.printStackTrace();

}

%>

</body></html>

Page 54: Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr II - EJB 157 Les Ejb Les EJB sont à CORBA ce qu  est le circuit précablé

Stéphane Frenot - Département Télécommunication - SID - [email protected]

II - EJB 54

Points forts

• Notion de container– Robustesse, standardisation, évolution

• Interface de développement standardisées– Pas / Peu de phase de prise en main

• Automatisation de nombreuses tâches– Gestion de la persistance, transactions…

• Intégration à l'API java• Marché explosant