16
Stéphane Frenot - Département Télécommunication - SID - [email protected] II - EJBcli 1 Le client EJB

Le client EJB

  • Upload
    oriole

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

Le client EJB. En gros. jndi. OM. 5. 3. 4. 1. Client. 2. Comment obtenir le stub du « home » ?. Réaliser un lookup sur le service de nommage JNDI afin d'obtenir. Pour localiser le ................... d'un EJB Robot lié en tant que « nono » : - PowerPoint PPT Presentation

Citation preview

Page 1: Le client EJB

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

II - EJBcli 1

Le client EJB

Page 2: Le client EJB

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

II - EJBcli 2

En gros....

OM

Client

jndi

1

2

34

5

Page 3: Le client EJB

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

II - EJBcli 3

Comment obtenir le stub du « home » ?

• Réaliser un lookup sur le service de nommage JNDI afin d'obtenir .....

Pour localiser le ................... d'un EJB Robot lié en tant que « nono » : // Obtenir un contexte de travail initial try{ RobotHome home=(RobotHome)context.lookup(« nono »); }catch(NamingException e){...}

Page 4: Le client EJB

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

II - EJBcli 4

L’interface .....

• Elle fournie un service de gestion du cycle de vie des EJB créés– création– suppression– métaDonnées– localisation des EJB d'implantation

Page 5: Le client EJB

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

II - EJBcli 5

L’interface EJBHome

• Toutes les interfaces « home » héritent de– javax.ejb.EJBHome

L'interface EJBHome :

public interface EJBHome extends Remote { public void remove (Handle handle) throws RemoveException; public void remove (Object object) throws RemoveException; public EJBMetaData getEJBMetaData(); }

Page 6: Le client EJB

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

II - EJBcli 6

Les méthodes de création

• L'interface home présente également un certain nombre de méthodes create qu'un client peut invoquer pour demander la fabrication d'un EJB

Syntaxe des méthodes create <RemoteIF> create() throws CreateException, RemoteException

Exemple de création de robots try{ RobotHome home=(RobotHome)context.lookup(« nono »); Robot jacques=home.create(); Robot bill=home.create(«Grosses Chenilles»); }catch(NamingException e){ }catch(CreationException e){ }catch(RemoteException e){}

Page 7: Le client EJB

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

II - EJBcli 7

Les ejb entité présentent des méthodes find

• Les entités EJB possèdent une ou plusieurs méthodes find dans l'interface « home » qui permettent de localiser les EJB persistants existants

Toutes les « homes » des EJB entity ont : <RemoteIF> findByPrimaryKey(<PKClass>) throws FinderException, RemoteException

L'interface « home » peut également définir d'autres méthodes de recherche : <RemoteIF> findNimporteQuoi() throws FinderException, RemoteException java.util.Enumeration findNimporteQuoi() throws FinderException, RemoteException

Page 8: Le client EJB

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

II - EJBcli 8

Exemple d'utilisation d'un entity EJB

On utilise des entity EJB qui représentent des adresses Mail :public interface EmailHome extends EJBHome { public Email create(String adresse)throws CreateException,

RemoteException public Email findByPrimaryKey(EmailPK pk) throws FinderException,

RemoteException public Enumeration findByDomain(String domain) throws FinderException,

RemoteException}Exemple d’utilisation de l'entité EJBtry{ EmailHome home=(EmailHome)context.lookup(« EmailEJB »); EmailPK pk=new EmailPK("[email protected]"); Email uneAdresseMail=home.findByPrimaryKey(pk); Enumeration enum=home.findByDomain("univ-lyon1.fr"); while(enum.hasMoreElements()){ Email email=(Email)enum.nextElement(); // Utilisation de l'EJB ici ! }}catch(Exception e){}

Page 9: Le client EJB

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

II - EJBcli 9

Que ce passe t'il au niveau du container ?

Type de l’EJB/Action du client

Stateless Session Stateful Session Enity

create() Peut créerl’instance enmémoire, peutlaisser le clientutiliser une nouvelleinstance pourchaque invocation

Crée l’instance enmémoire et fixe lesvaleurs initiales à lasession

Crée l’instance enmémoire,Crée l’instancedans le système depersistance

remove() Peut placer l’EJBdans le pool ou bienle détruire. Lesclients possèdentencore la référence,mais l’objet peut neplus exister

Les attributs del’instance sontnettoyés et lesclients possèdentencore un référencesur l’instance

Supprime la lignedans la base.L’instance EJB estencore référencéepar le client

find() N/A N/A Crée l’instance enmémoire ; Remplitl’instance avec lesdonnées provenantdu support depersistance

Page 10: Le client EJB

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

II - EJBcli 10

Vision client du cycle de vie : EJB Session

Non existantnon référencé

Non existantréférencé

existenon référencé

existe,référencé

home.create (...)

Le client invoque les méthodes

La référence client estlibérée

handle.getObject()

Crash du containerou timeOut du bean

object.remove()home.remove()Exception système du beanTimeOut du BeanCrash du container

NoSuchObjectException()

La référence client estlibérée

Page 11: Le client EJB

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

II - EJBcli 11

Vision client du cycle de vie : EJB Entity

Non existantnon référencé

Non existantréférencé

existenon référencé

existe,référencé

home.create (...)

Le client invoque les méthodes

La référence client estlibérée

home.find()

Insertion

directeobject.remove()home.remove()ou suppression directe

NoSuchObjectException()

La référence client estlibérée

Suppression directehome.remove()

Page 12: Le client EJB

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

II - EJBcli 12

L'interface Remote

• L'interface Remote liste les opérations métiers d'un EJB– Toutes les interfaces Remote étendent EJBObject– Toutes les méthodes peuvent lever une exception

RemoteException

Page 13: Le client EJB

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

II - EJBcli 13

L'interface EJBObject

• L'interface EJBObject fournit au client sa vue d ’un EJB

L'interface EJBObjectinterface EJBObject extends Remote { public EJBHome getEJBHome(); public Handle getHandle(); public Object getPrimaryKey(); public boolean isIdentical(EJBObject); public void remove() throws RemoveException;}

Toutes ces méthodes lèvent aussi RemoteException

Page 14: Le client EJB

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

II - EJBcli 14

L'interface Remote

• L'interface Remote définit surtout les opérations métiers de l'EJB

L'interface Remote pour un EJB entitépublic interface Email extends EJBObject{ public String getDomainName() throws RemoteException; public String getEmailAddress() throws RemoteException; public String getUserName() throws RemoteException;}

Exemple d'utilisation de l'EJBtry{ EmailHome home=(EmailHome)context.lookup("EmailEJB"); Email ejb=home.create("[email protected]"); String domain=ejb.getDomainName(); String user=ejb.getUserName(); System.out.println(" Adresse Mel :  "+user+"@"+domain);}catch(Exception e){...}

Page 15: Le client EJB

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

II - EJBcli 15

Comparaison d'EJB

• Utilisation de isIdentical(EJBObject) pour voir si deux références distances indiquent le même EJB

Comparaison d'identité RemoteStringHome home=...; //Obtient le home d'un stateful RemoteString r1=home.create(...); RemoteString r2=home.create(...); RemoteString r3=r2;

//comparaisons if (r1.isIdentical(r2)){...} if (r1.isIdentical(r1)){...} if (r2.isIdentical(r3){...}

Page 16: Le client EJB

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

II - EJBcli 16

Objets Handle

• Un Handle peut être utilisé pour stocker une connexion sur un EJB

• Un objet Handle :– Représente le contenu d'un remote stub

– Est sérialisable

– Est produit à partir de l'interface Remote

Définition de l'interface Handle public interface Handle{ public EJBObject getEJBObject() throws RemoteException; }

Pour fabriquer le Handle à partir de l'EJB public Handle getHandle() throws RemoteException;