EJB - KIV

Transcription

EJB - KIV
Plan
1.
2.
3.
4.
5.
6.
7.
Department of
Informatics
Application Servers
Servlets, JSP, JDBC
J2EE: Vue d’ensemble
Distributed Programming
Enterprise JavaBeans
Enterprise JavaBeans: Special Topics
Prise de recul critique
5. Enterprise JavaBeans
Enterprise JavaBeans
1. Definitions
2. Global View
3. Entity Beans
4. Session Beans
5. Message Beans
6. Implementation
Department of
Informatics
5. Enterprise JavaBeans
5.1 Definitions
Composants: Motivation
ƒ
Programmation usuelle
"programming in the small"
Le programmeur prend tout
en charge (construction des
différents modules,
interconnexions,…)
ƒ Grandes compétences
techniques
ƒ Structure de l'application peu
visible (tout est dans le code)
ƒ
ƒ
Department of
Informatics
ƒ
Programmation constructive
(ou par composants)
ƒ
ƒ
"programming in the large"
Le programmeur réutilise des
modules logiciels existants
Focalise l'expertise sur les
problèmes du domaine
ƒ Description de la structure à
l'aide d'un langage déclaratif
ƒ
5. Enterprise JavaBeans
5.1 Definitions
Composants: Définition
ƒ
Définition usuelle
ƒ
ƒ
ƒ
ƒ
ƒ
module logiciel autonome pouvant
être installé sur différentes platesformes
qui exporte différents attributs,
propriétés ou méthodes
qui peut être configuré
capable de s’auto-décrire
(introspection)
Intérêt : être des briques de base
configurables pour permettre la
construction d’une application par
composition
Department of
Informatics
5. Enterprise JavaBeans
5.1 Definitions
Rôle des conteneurs
ƒ Encapsulation d’un composant
(techniquement par délégation)
ƒ
ƒ
Department of
Informatics
prise en charge (masque) des services
systèmes (nommage, sécurité, transaction,
persistance, ...)
prise en charge partielle des "connecteurs"
(composants ayant des relations avec
d'autres composants)
5. Enterprise JavaBeans
5.1 Definitions
Les modèles de composants: de
l'installation à l'introspection
ƒ
Installer les composants
ƒ
ƒ
Créer une instance
ƒ
ƒ
ƒ
services de nommage ou maisons ("home")
Utiliser
ƒ
ƒ
par des fabriques ("home")
configuration des valeurs initiales
Retrouver les composants
ƒ
ƒ
Packaging et déploiement dans un conteneur
invocation synchrone et événements
Introspection
ƒ
ƒ
Department of
Informatics
découvrir leurs APIs (fonctionnelle)
découvrir les connecteurs (structurelle)
5. Enterprise JavaBeans
5.1 Definitions
Enterprise JavaBeans
ƒ Définition de Sun Microsystems:
L'architecture des Enterprise JavaBeans (EJB) est une architecture de
composants pour le développement et le déploiement d'applications
d'entreprise distribuées basées sur des composants. Les applications
écrites en utilisant l'architecture des EJB sont évolutives,
transactionnelles et sûres. Ces applications peuvent être écrites une
fois, puis déployées sur toute plate-forme serveur qui supporte la
spécification des EJB.
ƒ Autre définition plus courte:
Les EJB sont un modèle de composants côté serveur, basés sur les
technologies à objets distribués, standard pour les CTM.
Department of
Informatics
5. Enterprise JavaBeans
5.1 Definitions
Enterprise Java Beans:
Components and Containers
An Enterprise Java Bean (EJB) is a component that provides
reusable business logic functionality and/or a representation of a
persistent business entity
ƒ An EJB Container executes an EJB due to a client request.
ƒ
ƒ
Provides the plumbing necessary to execute the EJB including
• non-business logic related functionality such as transactions, security,
concurrency, remote access, etc.
• life cycle functions, e.g., creating, destroying, etc.
ƒ
ƒ
Client uses an interface to access the Bean indirectly
A deployment descriptor describes the structure of the Bean and
how to execute the Bean as part of an application
Department of
Informatics
5. Enterprise JavaBeans
5.1 Definitions
J2EE and EJB
ƒ How does J2EE relate to Enterprise
JavaBeans technology?
Enterprise JavaBeans (EJB) technology is the basis of J2EE. EJB
technology provides the scalable architecture for executing
business logic in a distributed computing environment. J2EE
makes the life of an enterprise developer easier by combining
the EJB component architecture with other enterprise
technologies to solutions on the Java platform for seamless
development and deployment of server side applications.
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
EJB Contrats
ƒ
Fournir un modèle de
développement uniforme pour les
applications qui utilisent les
composants EB
ƒ
Contrat coté client
• fournir une vue uniforme du bean au
client. En particulier cette vue est
indépendante de la plate-forme de
déploiement
ƒ
Contrat coté conteneur
• permettre la portabilité des beans sur
différents serveurs EJB
ƒ
Contrat coté “packaging” (ejbjar/ear file)
• fournir un format de fichier standard
pour “packager” les beans. Ce format
doit être supporter par tous les outils
liés aux EJB
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
EJB: Le contrat côté client
ƒ Localiser le bean
ƒ
utilisation de JNDI
ƒ Utiliser le bean
ƒ
utilisation de l’interface standard fournie par l’EB
• Home Interface
– méthodes liées à la gestion du bean : create, remove, finder, ...
• Remote Interface (méthodes de l’application)
ƒ Le container implémente le mécanisme de délégation
permettant de “faire suivre” l’appel au bean
ƒ Le client ne communique pas directement avec le
bean mais avec le container
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
EJB: Le contrat "conteneur"
ƒ L’EJB conteneur permet
ƒ gestion du cycle de vie, gestion de l’état, sécurité,
transaction distribuée, concurrence, extensibilité
ƒ ces services appellent des méthodes fournies par
le bean (callback methods)
ƒ Les conteneurs gèrent 3 types de beans
ƒ Entity beans
ƒ Session beans
ƒ Message driven beans
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Cycle de vie d'un bean
ƒ Le conteneur gère le cycle de vie d’un bean
ƒ Il fournit
ƒ administration du bean ("Home implementation")
• permet aux clients de créer, détruire et rechercher un
objet EJB
• appelle les opérations correspondantes fournies par le
bean (callbacks)
ƒ
gestion de l’état
• Activation: le bean est chargé en mémoire
• Passivation (Désactivation ): le conteneur peut
sauvegarder l’état du bean
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Architecture
Client
Container
Method invocation
Client Interface
Method Delegation
TX support
Security
Persistence
...
Department of
Informatics
Bean Instance
5. Enterprise JavaBeans
5.2 Global View
Structure d'un EJB
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Création d'un EJB Objet
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Interaction avec un EJB
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
EJB Object / Proxy d'EJB
ƒ Client never directly access Bean
instance
ƒ Client finds home interface via JNDI
ƒ Client uses home interface to obtain a
reference to the Bean’s component
interface.
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Gestion des ressources
"Pool" d'instances
ƒ Le serveur EJB maintient un pool d'instance de bean
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Types of Beans
ƒ Entity Beans
ƒ Persistent data focus
ƒ Session Beans:
ƒ Client and application logic focus
ƒ Message Driven Beans
ƒ Asynchronous message processing
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Classes and Interfaces
1.
2.
3.
4.
5.
6.
Remote Interface
Remote Home Interface
Local Interface
Local Home Interface
Bean Class
Primary Key
See: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Remote Interface
«interface»
java.rmi.Remote
ƒ Define the bean's business
methods that can be accessed
from applications outside the EJB
container.
«interface»
javax.ejb.EJBObject
«interface»
RemoteInterface
Department of
Informatics
5. Enterprise JavaBeans
5.2 Global View
Remote Home Interface
ƒ Defines the bean's life-cycle
methods that can be accessed
from applications outside the EJB
container:
ƒ
ƒ
ƒ
Department of
Informatics
Creating beans
Removing beans
Finding beans
«interface»
java.rmi.Remote
«interface»
javax.ejb.EJBHome
«interface»
RemoteHomeInterface
5. Enterprise JavaBeans
5.2 Global View
Local Interface
ƒ Defines the bean's business
methods that can be used by
other bean co-located in the
same EJB container (same
address space)
ƒ Allow beans to interact
without the overhead of a
distributed object protocol,
which improves performance.
Department of
Informatics
«interface»
javax.ejb.EJBLocalObject
«interface»
LocalInterface
5. Enterprise JavaBeans
5.2 Global View
Local Home Interface
ƒ Defines the bean's life-cycle
methods that can be used by
other co-located in the same
EJB container (same address
space)
ƒ Allow beans to interact
without the overhead of a
distributed object protocol,
which improves performance.
Department of
Informatics
«interface»
javax.ejb.EJBLocalHome
«interface»
LocalHomeInterface
5. Enterprise JavaBeans
5.2 Global View
Bean Class
ƒ The session and entity bean
classes actually implement the
bean's business and life-cycle
methods.
ƒ Usually does not implement any
of the bean's component
interfaces directly. However, it
must have matching signatures of
the methods defined in the
remote and local interfaces and
must have methods corresponding
to some of the methods in both
the remote and local interfaces.
Department of
Informatics
«interface»
java.io.Serializable
«interface»
javax.ejb.EnterpriseBean
«interface»
javax.ejb.EntityBean
«interface»
javax.ejb.SessionBean
MyEntityBean
MySessionBean
5. Enterprise JavaBeans
5.2 Global View
Primary Key
ƒ The primary key is a very simple
class that provides a pointer
into the database.
ƒ Only entity beans need a
primary key.
Department of
Informatics
java.io.Serializable
MyPrimaryKey
5. Enterprise JavaBeans
5.2 Global View
Local vs. Remote Interfaces
ƒ
Entity and Session Beans can support local and remote interfaces
ƒ
ƒ
ƒ
Client is written to a specific interface
Interface(s) supported is not transparent to Bean provider
Local interface
ƒ
Not location independent
• Client and EJB run in the same JVM
– Example: A Bean always accessed by other Beans
ƒ
ƒ
ƒ
Parameter passing is by reference (same as standard Java)
Well adapted for fine grained access
Remote interface
ƒ
ƒ
ƒ
Department of
Informatics
Location independent
Parameters passed by value (RMI semantics)
Well adapted for coarse grain access
5. Enterprise JavaBeans
5.2 Global View
Local vs. Remote Interfaces (2)
ƒ Reasons for Choosing Local vs. Remote Access
ƒ Type of client
• If client is always a Web Component or another EJB,
choose local
ƒ
Coupling
• If tightly coupled, choose local
ƒ
Scalability requirements
• If strong scalability requirements, choose remote
Department of
Informatics