Transcript EJB
EJB
By: Sirisha
Panchagnula
Dt:11/04/03
Index
Introduction
Why EJB?
When To Use EJB?
Where does EJB Run?
Differences between Java
beans &EJB
Basic EJB Architecture
What Does EJB Consist?
EJB Architecture Revisited
EJB Components
EJB Container for Session N
Entity Beans
Types of EJB’s
EJB With Session & Entity
Beans
What is Entity Bean?
Persistence in Entity Bean
What is Session Bean?
Stateful & Stateless Beans
Entity Bean Vs Session Bean
Life Cycle Of EJB
Roles In EJB Cycle
Introduction
Enterprise Java Beans is a specification for creating serverside scalable, transactional, multi-user secure
enterprise-level applications.
It provides a consistent component architecture framework for
creating distributed n-tier middleware.
EJB enables rapid and simplified development of distributed,
transactional, secure and portable Java applications.
Why Enterprise Java Beans?
Architectural Independence for developers
WORA (Write Once, Run Anywhere) for server side components
(Portable Components)
Establishes roles for application development
Takes care of Transaction Management
Provides Distributed Transaction support
Helps create Portable & Scalable solutions
Integrates seamlessly with CORBA
Provides vendor specific enhancements.
Location Transparent
When To Use EJB?
Applications should be scalable
Applications that contain business logic that operates on
Enterprise’s data.
Transactions should ensure data integrity
Applications should have variety of clients.
Clients can be thin & numerous.
Where Does EJB Run?
Differences Between Java
Beans & EJB’s
Can be either visible or nonvisible
Are decidedly Non-Visible, remote
objects
Intended to be local to a single
process on the client side
Remotely executable components
deployed on the server
Uses the BeanInfo classes,
Property Editors & Customizers
to describe itself
Uses the Deployment Descriptor to
Can also be deployed as an
Cannot be deployed as an ActiveX control
since OCXs run on the desktop
ActiveX control
describe itself.
BASIC EJB ARCHITECTURE
What Does EJB Consist
• A typical EJB Architecture consists of
* An EJB server,
* EJB containers that runs on these servers,
* EJBs that run in these containers,
* EJB clients and other auxiliary systems like
the Java Naming and Directory Interface
(JNDI),Java Transaction Server(JTS)
* The EJB Home interface and Home object
* The Remote interface and EJBObject
EJB Architecture Revisited
EJB Components
EJB Servers :
Analogous to the CORBA ORB.
Provides the system services like ( raw execution environment),
( multiprocessing), ( load-balancing ) , ( device access )
Provides naming transaction services
Makes containers visible.
EJB Clients :
Use EJB Beans for their operations.
Find the EJB container that contains the bean through the Java
Naming and Directory (JNDI) interface.
Use the EJB Container to invoke EJB Bean methods.
EJB Containers :
Act as the interface between an Enterprise Java Bean and the
outside world.
EJB client never accesses a bean directly.
Components Con’t
Any bean access is done through container-generated methods
which in turn invoke the bean's methods.
The EJB Home interface and Home object :
Factory methods for (locating) (creating) (removing instances of
EJB classes) are defined here.
The Home object is the implementation of the Home
interface
The Remote interface and EJBObject:
Lists the business methods available for the enterprise Bean.
The EJBObject is the client’s view of the enterprise Bean
It implements the remote interface.
The Enterprise Java Bean:The real EJB Bean itself is
contained within an EJB container, and should never be directly
accessed other than the container.
EJB Container For Session &
Entity Beans
Types Of EJB’s
Enterprise Bean
Type
Purpose
Session
Performs a task for a client
Entity
Represents a business entity object that
exists in persistent storage
Message-Driven
Acts as a listener for the Java Message
Service API, processing messages
asynchronously
EJB Environment With
Session & Entity Beans
What is Entity Bean
Entity Beans always have states.
Can be shared by multiple EJB Clients.
Their states can be persisted and stored across multiple
invocations.
Hence they can survive System Shutdowns.
EJB servers have a right to manage their working set.
Passivation is the process by which the state of a Bean is
saved to persistent storage and then is swapped out.
Activation is the process by which the state of a Bean is
restored by swapping it in from persistent storage.
Passivation and Activation apply to both Session and Entity
Beans
Persistance in Entity Beans
Persistence in Entity Beans is of two types. They are:
Container-managed persistence:
Here, the EJB container is responsible for saving the Bean's state.
Hence the implementation is independent of the data source.
Bean-managed persistence:
Entity bean directly responsible for saving its own state.
Implementation less adaptable than the previous one.
What Is Session Bean?
As its name suggests, a session bean is similar to an interactive
session. A session bean is not shared Like an interactive session,
a session bean is not persistent
There are two types of session beans: stateful and stateless.
Stateless Session Beans:
These types of EJBs have no internal state. Since they do not
have any states, they need not be passivated
Because of the fact that they are stateless, they can be
pooled to
service multiple
clients
Stateful Session Beans
These have internal states. Hence need to handle Activation and
Passivation. Also called Persistent Session Beans.
These types of EJBs can be saved and restored across client
sessions.
To save, a call to the bean's getHandle() method returns a
handle object. To restore call getEJBObject() method
Entity Bean Vs Session Bean
Session Bean
Entity Bean
The data members of the session bean
contain conversational state.
The data members of the entity bean
represent actual data in the domain model.
A session bean may handle database access
for a single client.
Entity beans share database access for
multiple clients.
Because session beans are about a
conversation with a single client, session
beans are allowed to store per-client state
information..
The relationship between a session bean and
its client is one-to-one.
Because entity beans are shared between
multiple clients, they do not allow storage of
per-client state information.
The life of the session bean is limited to the
life of its client.
An entity bean persists as long as the data
exists in the database.
Session beans can be transaction aware.
Entity beans are transactional.
Session beans do not survive server crashes.
Entity beans survive server crashes.
The relationship between an entity bean and a
row in the domain model is one-to-one.
Life Cycle Of EJB
Roles in EJB Cycle
EJB Bean Provider –Developers who create enterprise beans
Application Assembler - uses the EJB
EJB Deployer - deploys the EJBs on a Server
EJB Server Provider - creates EJB Servers
EJB Container Provider - creates EJB containers and tools
System Admin : Ensures server is available to other network
services
Ensures the servers are configured correctly to handle user
loads.
References
http://my.execpc.com/~gopalan/
Java FAQ
Ejb Concepts by Sun