Académique Documents
Professionnel Documents
Culture Documents
September 3, 2009
EJB Defined
•The Enterprise JavaBeans architecture is a
component architecture for the development
and deployment of object-oriented
distributed enterprise-level applications.
Applications written using the Enterprise
JavaBeans architecture is scalable,
transactional and multi-user secure. These
applications may be written once, and
deployed on any server platform that
supports the Enterprise JavaBeans
specification
– Sun Microsystems Enterprise JavaBeans™
Specification, v1.1, Copyright 1999 by Sun
TCS Internal September 3, 2009 2
Enterprise Java Beans
•Enterprise Java Beans are components which
are deployed within a container.
•EJB component is a set of classes and
interfaces.
•The advantage of components over objects
is that only the business logic has to be
addressed and underlying middleware
services are taken care by containers.
•Containers are executables within server
environment which hold the beans.
Server
RMI
Client
RMI
Remote EJB Object
Interface (Wrapper)
Enterprise
You write this
Java Bean
Implements (Biz Logic)
Invokes
Creates / uses
•Home Interface:
package simpleBean;
public interface SalaryHome extends
javax.ejb.EJBHome {
Salary create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
Life
Cycle
Method
•Deployment Descriptor:
<?xml version=“1.0”?>
<!DOCTYPE ejb-jar PUBLIC ‘-//Sun Microsystems, Inc.
//DTD Enterprise Java Beans 1.1//EN’
http://java.sun.com/dtd/ejb-jar_2_0.dtd>
<ejb-jar>
<description>
Single stateless bean to calculate salary
</description>
<display-name>Salary Bean</display-name>
•Directory Structure:
simpleBean
|---- Salary.class
|---- SalaryHome.class
|---- SalaryEJB.class
META-INF
|---- ejb-jar.xml
Container
Needs Instance created
a new session using no-args constructor
bean
setSessionContext
Method called
ejbCreate
Method called
Many clients
Component
Use
Added to the pool The bean
ejbRemove
called
ejbRemove 1.setSessionContext
2.ejbCreate
Ready
setSessionContext
Method called
Container
Calls
ejbRemove ejbCreate
Method called
Timeout
One client
Container calls Component
Use
ejbPassivate Is ready The bean
1.create
1.remove 2.setSessionContext
2.ejbRemove 3.ejbCreate
ejbActivate
Ready Passive
ejbPassivate
OrderEJB
ONE MANY
MANY ONE
LineItemEJB CustomerEJB
MANY
ONE
ProductEJB
unsetEntityContext setEntityContext
1. remove
2.ejbRemove
ejbActivate
Ready Pooled
ejbPassivate
1.create
2.ejbCreate
3.ejbPostCreate
ejbRemove 1.setMessageDrivenContext
2.ejbCreate
onMessage
Ready