Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
-
Upload
oswald-hunt -
Category
Documents
-
view
240 -
download
5
Transcript of Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Enterprise Java Bean
Matt
2
J2EE
3
J2EE Overview
4
J2EE 1.4 API
5
Distributable Components • Components should provide services to clients running locally or remotely
• SelfContained Components Components should only contain the code necessary to implement their services Infrastructure services should be injected by the execution environment
• Standard infrastructure services include Directory Services Distributed transaction management Security management Concurrent access management Persistence management Resource pooling (e.g. DB connections) Administration interface Load Balancing Fault tolerance
An application server provides the infrastructure and services to run components/applications An application server provides the infrastructure and services to run components/applications
6
Object Pooling • An application server may create a pool of bare obj
ects that may be used as EJBs when requests are made
7
Container
• A Container provides the environment in which a bean executes generates Home Object generates EJB Object manages individual bean instances
8
EJB
9
EJB• Enterprise Java Bean包括了
Session Bean: Session beans are essentially service providers Stateless Stateful
Entity Bean: Entity beans are used to represent data in a database. BMP CMP
Message-Driven Bean: Message driven beans are capable of responding to JMS messages
10
EJB Overview
• EJB simplified distributed developmentDevelop EJB implementation logic Define Home/Local Remote/Local interfaces Container delegates client calls Container manages resources/lifecycle/callbacks
11
EJB
12
EJB Design Approaches • Remote interface• Home interface• Bean class
13
EJB Architecture
14
EJB Flow Chart
15
Client View of EJB
16
EJB• EJB clients
utilizes the Java Naming and Directory Interface (JNDI) to look up for the references to home interfaces
use home and remote EJB interfaces to utilize all EJB-based functionality
• EJB Home interface create EJBs remove EJBs find handles to EJB remote interface
objects
• EJB remote interfaces provide business-specific functionalit
y of an EJB are similar to RMI Remote interface
• EJB implementation (Bean Class) business method invocation database loading logic passivation, database storage
Session Context• The Container has already reference
to the bean The bean interacts with the Container through SessionContext and retrieves home interfaces gets and sets transactions attributes obtains security attribute
• The setSessionContext method is used to inform the bean about the session context
17
Steps to Develop an EJB
18
Hello World Object Model using RMI
19
Session Bean
20
Session EJBs View • Stateless
• Stateful
21
Life Cycle of Stateless Session Bean
22
Life Cycle of Stateful Session Bean
23
Stateful vs Stateless Stateful Bean
• A stateful bean contains a conversational state that is retained across method calls and transactions. The create method takes argumentse.g. create(String id) , create(int I , String id) There can be one or more arguments in a create method
• e.gAn EJB that unzips 100 bytes of data An EJB that checks to see if a stock symbol is valid
Stateless Bean
• A stateless bean does not have any state between calls to its methods The create method does not take argumentse.g create() There can be no arguments in a create method
• e.gAn EJB that books a flight and rents a car at a travel agent’sweb site.
24
25
Entity Bean
26
27
Message-Driven Bean
28
29