Escolar Documentos
Profissional Documentos
Cultura Documentos
Ph.D.
Contents
EJB Overview Session Bean
Stateless Session Bean Stateful Seesion Bean
Entity Bean
Bean-managed persistence Container-managed persistence
Transaction
2000 Soo Dong Kim EJB Key Concept
Terminology
Enterprise JavaBeans
Is an architecture for component-based distributed computing.
Enterprise Beans
Are components of distributed transactionoriented enterprise application.
Enterprise JavaBeans
A server-side component architecture
Allows developers to quickly create scalable enterprise applications using java Provides complex middleware enterprise features at no cost
Transactions, persistence, security, state management, threading
Cross-platform, cross-vendor
2000 Soo Dong Kim
There is one standard, allowing the vendors to focus on the quality of their EJB products.
Enterprise Beans
Essential characteristics :
An enterprise Bean contains business logic. An enterprise Beans instances are created and managed at runtime by a container. An enterprise Bean can be customized at deployment time by editing its environment properties. Various metadata, such as a transaction mode and security attributes, are separated out from the enterprise Bean class.
Enterprise Beans
Client access is mediated by the container and the EJB server. If an enterprise Bean uses only the standard container services, the enterprise Bean can be deployed in any EJB container. Specialized containers can provide additional services. An enterprise Bean can be included in a composite application without source code changes or recompilation.
Roles
Enterprise JavaBeans architecture
Defines six distinct roles in the application development and deployment life cycle.
Enterprise Bean Provider
An application domain expert Develops reusable components called enterprise Beans.
Application Assembler
Combines enterprise beans into larger deployable application units. Output is one or more ejb-jar files that contain the enterprise beans with their application assembly instruction.
Roles
Deployer
An expert at a specific operational environment. Is responsible for the deployment of enterprise Beans and their containers.
System Administrator
The role of a system administrator is to oversee the wellbeing of a running system.
EJB Key Concept
Roles Map
Container Provider Deployer Tool
Assembly Instructions
Application assembler
10
EJB Contracts
Clients view contract
Contract between a client and a container. Includes
Home interface
Defines the methods for the client to create, remove, and find EJB Objects. Client locates an home interface through the JNDI API.
Remote Interface
Defines the business methods callable by the client.
Object identity
Container must generating a new unique identifier for each Session Object. The identifier is not exposed to the client. Bean Provider must supply a primary key at Entity Object creation time
11
EJB Contracts
Component contract
An enterprise Bean class instances view of its life cycle. javax.ejb.SessionContext interface that a container passes to a session enterprise Bean instance at instance creation. Environment java.util.Properties that a container makes available to an enterprise Bean. List of services that every container must provide for its enterprise Beans.
EJB Key Concept
12
EJB Contracts
Client
Enterprise Bean
Container Contract
Container
2000 Soo Dong Kim EJB Key Concept
EJB Server
13
Enterprise Beans
Types of Enterprise Beans
Session Bean
Stateless session bean Stateful session bean
Entity Bean
Bean-managed persistent Container-managed persistent
14
Lifetime
Might live for minutes or hours
but probably not weeks, months, or years. Not saved to permanent storage.
EJB Key Concept 2000 Soo Dong Kim
15
16
17
EJB Container
Is a system that functions as the container for enterprise Beans. Client look up the home interface for the EJB class using JNDI.
By the container
18
Multiple EJB classes can be installed in a container. Container allows the clients to look up the home interfaces via JNDI. Home interface provides methods to create and remove the EJB objects.
EJB Container
Container
EJB objects
EJB class 1
EJB Home
Client
EJB objects
EJB class 2
2000 Soo Dong Kim EJB Key Concept
EJB Home
19
Home Interface
EJB Container implements the home interface of each enterprise Bean.
The container makes the home interface available to the client through JNDI.
20
EJB object
A client never accesses instances of the enterprise Beans class directly.
Uses the enterprise Beans remote interface.
21
java.lang.RuntimeException
When the EJBMetaData.getPrimaryKeyClass() is invoked on a meta-data object for a Session Bean.
2000 Soo Dong Kim EJB Key Concept
22
Session EJB object handle can be held beyond the life of a client process
By serializing the handle to persistent store.
2000 Soo Dong Kim EJB Key Concept
23
Release reference
Release reference
24
Handle.getEJBObject( )
Object identity
Stateful Session Beans
has a unique identity that is assigned by the container at create time. isIdentical(Object otherObject)
Type narrowing
25
Reassigned at any time to another EJB object. Important to know when debugging EJB applications.
EJB Key Concept
26
27
Activation - Swap in
28
.
2000 Soo Dong Kim
To activate beans
Most containers will use a just-in-time algorithm.
Beans should be activated on demand, as client requests come in.
EJB Key Concept
29
EJB Object
Remote Interface
Enterprise Bean
30
Storage
EJB Object
Remote Interface
Enterprise Bean
31
Lifetime
2000 Soo Dong Kim
Longer than a clients session Depending on how long the data sits in the database.
EJB Key Concept
32
Storage
33
ejbStore( )
Saves your bean instances current fields to the underlying data storage.
34
Can be Pool
Entity bean may be holding resources
Socket connections.
ejbActivate( )
When transitioning your bean out of a generic instance pool.
Callback that your container will invoke on your bean instance.
ejbPassivate( )
2000 Soo Dong Kim
35
Bean Instance
Passivation entails a state save.
1:ejbActivate() 2:ejbLoad()
36
37
Client Code
6:return EJB object
Home Object
2:ejbCreate()
Enterprise Bean
EJB Object
3:Create database data
38
Entity Beans
ejbFind( )
Uses to find an existing entity bean in storage. Finder methods do not create any new database data.
ejbRemove()
To destroy an entity beans data in a database. Does not mean the in-memory entity bean instance is going to be destroyed. There is only one form of ejbRemove(). Is not called if the client times out.
EJB Key Concept
39
pooled
ejbCreate(args) ejbActivate() ejbPostCreate(args)
ejbPassivate()
ejbRemove()
Business method
EJB Key Concept
40
ejbLoad()
ready
ejbStore()
Bean-managed persistence
Characteristic :
Entity bean that must be persisted by hand. Hard-code database access with in class.
You must write to a persistence API.
Not automated, developer manually creates mapping through JDBC calls. Entitity bean provider implement the entity beans persistence directly
Object Persistence
2000 Soo Dong Kim
Data access protocol for transferring the state of entity between the entity bean instances and the underlying database
EJB Key Concept
41
Container-managed persistence
Characteristic :
Automatic persistence for your entity beans The container/server performs every function of your components data access layer. Theoretical database independence The container provides tools that generate code in the EJB class. The bean provider must specify in the deployment descriptor the list of the instance fields for which the container provider tools must generate access calls.
EJB Key Concept
42
Container-managed fields
Container-managed persistent entity bean
Allows the container to handle some or all of its data access logic.
Container implicitly perform all database operations behind the scenes.
43
Entity Bean
Existing App
O/R Mapping
44
Transactions
Concept
Appear to execute as one large, atomic operation Guarantee an all-or-nothing value proposition
All of your operations will succeed, or none of them will.
Allow multiple users to share the same data Guarantee that any set of data they update will be completely .
2000 Soo Dong Kim EJB Key Concept
45
46
Consistency
Effects of a transaction preserve invariant properties. A transaction will leave the systems state to be consistent after a transaction completes.
47
Durability
2000 Soo Dong Kim EJB Key Concept
Effects of a transaction are persistent. Updates to managed resources, such as database records, survive failures.
48
Transactional Models
Flat Transactions
Performed atomically as a single unit of work. Decide to end the transaction
Successful transaction is committed.
All of the persistent operations become permanent changes.
49
Transactional Models
The Flat Transaction Process
Final State (Transaction Succeeded)
Transaction Occurring
If problem occurs, Abort transaction
2000 Soo Dong Kim
50
Your application may have performed are automatically undone by the underlying system.
Transactional Models
Nested Transactions
Allows you to embed atomic units of work within other units of work.
The unit of work is nested within another unit of work can roll back without forcing the entire transaction to roll back.
51
Transactional Models
The Nested Transaction Process State Final
(Transaction Succeeded) If all goes well, commit transaction
Transaction Occurring
If problem occurs, Abort transaction Perform one or more smaller-grained transactions Final State (Transaction Rolled Back)
EJB Key Concept
52
53
bean
Client(bean or app)
TX_REQUIRED
bean
2000 Soo Dong Kim
54
bean
Client(bean or app)
TX_REQUIRES_NEW
bean
2000 Soo Dong Kim
55
Transactional Isolation
Four transaction Isolation levels in EJB
TRANSACTION_READ_UNCOMMITTED Not offer any isolation guarantees. But offers the highest performance. TRANSACTION_READ_COMMITTED Solves the dirty read problem. TRANSACTION_REPEATABLE_READ Solves the previous problems as well as the unrepeatable read problem. TRANSACTION_SERIALIZABLE Solves the previous problems as well as the phantom problem.
EJB Key Concept
56
Two-Phase Commit
The Two phase commit protocol
The two-phase commit protocol is useful
Allows for many transaction managers and resource managers to participate in a transaction across a deployment. If any participant votes that the transaction should abort, all participants must roll back.
57
Two-Phase Commit
Transaction Participants
Transaction Manager
1:prepare to commit 2:return
Transaction Coordinator
4:commit 5:return
Transaction Manager
Resource manager
Transaction Manager
3:log result The commit operation is logged in case of a crash.
Resource manager
2000 Soo Dong Kim EJB Key Concept
58
- End -
59