1 / 16

Le client EJB

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 » :

oriole
Télécharger la présentation

Le client EJB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Le client EJB Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  2. En gros.... jndi OM 5 3 4 1 Client 2 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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){...} Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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(); } Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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){} Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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é EJB try{ EmailHome home=(EmailHome)context.lookup(« EmailEJB »); EmailPK pk=new EmailPK("sfrenot@insa-lyon.fr"); 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){} Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  9. Que ce passe t'il au niveau du container ? Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  10. Vision client du cycle de vie : EJB Session NoSuchObjectException() La référence client est libérée Non existant référencé Non existant non référencé object.remove() home.remove() Exception système du bean TimeOut du Bean Crash du container Crash du container ou timeOut du bean home.create (...) existe non référencé handle.getObject() existe, référencé La référence client est libérée Le client invoque les méthodes Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  11. Vision client du cycle de vie : EJB Entity NoSuchObjectException() La référence client est libérée Non existant référencé Non existant non référencé Insertion directe object.remove() home.remove() ou suppression directe home.create (...) Suppression directe home.remove() existe non référencé home.find() existe, référencé La référence client est libérée Le client invoque les méthodes Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  13. L'interface EJBObject • L'interface EJBObject fournit au client sa vue d ’un EJB L'interface EJBObject interface 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 Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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'EJB try{ EmailHome home=(EmailHome)context.lookup("EmailEJB"); Email ejb=home.create("stephf@lisiflory.insa-lyon.fr"); String domain=ejb.getDomainName(); String user=ejb.getUserName(); System.out.println(" Adresse Mel :  "+user+"@"+domain); }catch(Exception e){...} Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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){...} Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

  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; Stéphane Frenot - Département Télécommunication - SID - stephane.frenot@insa-lyon.fr

More Related