Académique Documents
Professionnel Documents
Culture Documents
Contents
Introduction
Technology Overview
EJB Architecture
EJB Specification
Sample Application
Sun’s Definition
EJB architecture is a component
architecture for the development and
deployment of component based
distributed business applications.
Applications written using EJB
architecture are scalable, transactional,
and multi-user secure.
These applications may be write once,
and then deployed on any server
platform that supports the EJB
specification.
Short Definition
EJB is a server-side component
architecture that simplifies the
process of building enterprise-class
distributed component applications
in Java.
EJB provides standard for
component architecture.
Enterprise Bean
Server side software components
that can be deployed in distributed
multi tier environment.
They encapsulate business logic of
an application.
Consists of one or more java
objects.
Types of Beans
Session Bean
Entity Bean
Message driven Bean
Session Bean
Session beans model business
processes.
They are like ‘verbs’ because they
are actions.
E.g. billing engine, catalog engine
etc:
Entity Bean
Entity Bean Models business data.
They are like ‘nouns’ because they
are data objects
E.g. product, an order, an
employee etc:
Session beans typically calls entity
beans to perform business goals.
Message Driven Bean
Message driven beans are similar
to session beans.
They are actions.
They are called only when they
receive some message.
E.g. : stock trade message.
EJB Architecture
HTML Business
Presentation Client Partner System
Tier HTTP SOAP,UDDI
Firewall
WSDL,ebXML
Distributed
Client
Object
Remote Interface
Remote Interface
Stub Skeleton
Network
We take a monolithic application
and break it into distributed
system with multiple clients
connecting to multiple servers and
databases over network.
What do we need to worry
about now?
Services
Remote Method Object life cycle
Invocation Caching
Load Balancing Security
Transparent Fail Resource Pooling
Over
Back end integration.
System
Management
Clustering
Message Oriented
Dynamic Re
deployment
Middleware
And many
Middleware
more…..
Explicit Middleware
Transaction API Transaction
Services
Distributed Security API
Client Security
Object
Services
Remote
Interface Database API
Remote Interface
Database
drivers
Stub Skeleton
Network
Example – Bank account
obj
Transfer(Acct acc1, Acct acc2,long amt)
//1.Call middleware API to perform
security check.
//2.Call middleware API to start a trans
//3.Call middleware API to load rows from
db.
//4.perform trans.
//5.Call middleware API to store rows in db
//6.Call middleware API to end the trans.
Explicit Middleware
Difficult to Write.
Difficult to Maintain.
Difficult to Support.
Implicit Middleware
Distributed
Client Object
Remote Transaction API Transaction
Interface Services
Request Security API
Interceptor Security
Services
Remote
Remote Interface Database API
Interface
Database
drivers
Stub Skeleton
Network
Example – Bank account
obj
Transfer(Acct acc1,Acct acc2,long
amt)
//1. Perform trans.(subtract bal from
one account and add to other).
Implicit Middleware
Easy to Write.
Easy to Maintain.
Easy to Support.
EJB Container
House enterprise bean and makes them
available to the client to invoke them
remotely.
It intercepts the client request and
delegates them to corresponding bean
class.
It automatically performs implicit
middleware that the distributed object
needs.
EJB object is the physical part of the
container.
EJB Component
Ingredients
Enterprise Bean Class
Interfaces
Remote and Home interface for
remote access.
Local and Local Home interface for
local access.
Deployment Descriptor.
Vendor Specific files.
Enterprise Bean Class
It conforms to a well defined
interface.
It contains business
implementation details of our
component.
Each bean type has more specific
interface that extends
javax.ejb.EnterpriseBean interface.
Bean class implements the
interface corresponding to the
EJB Object
Client request interceptor.
It duplicates all the business logic
methods that the corresponding
bean class exposes.
Proprietary and specific to each
EJB container.
Remote Interface
Interface to request interceptor.
Informs EJB Object auto generator
which methods to clone.
All remote interfaces must derive
from javax.ejb.EJBObject.
EJB remote interfaces must confirm
to RMI rules.
Home Object
EJB object factory.
Creates,finds and destroys EJB
objects.
Proprietary and specific to each
EJB container.
Home objects implements Home
Interface.
Home Interface
EJB Object factory interface.
They define methods for
creating,destroying and finding EJB
Objects.
All home interfaces must extend
javax.ejb.EJBHome.
EJB remote interfaces must confirm
to RMI rules.
Local Access
Local objects make enterprise bean calls
fast and efficient.
Local objects implements Local Interface.
Local home objects creates beans fast.
Local home object implemnts Local Home
interface.
Deployment Descriptor
Declare how the container should
perform middleware services for
the EJB component.
In EJB 2.0 deployment descriptor is
a XML file.
Key to implicit middleware.
Vendor Specific Files
All vendors have proprietary value
added features.
Include files specific to that
vendor.
Package
Remote Local
Interface Interface
Deployment Vendor
Descriptor Specific
Sample Application
My First Bean!
Session Bean : FirstBean
package example;
public class FirstBean implements javax.ejb.SessionBean
{
private SessionContext ctx;
import javax.naming.*;
Import java.util.*;
<<interface>>
javax.ejb.SessionBean
Comes with EJB Distribution
Written by developer
Naming
Service
Advantages of EJB
Helps to write scalable,reliable and
secure applications.
Provides distributed component
framework and hence supports rapid
application development.
Supports application portablility and
reusability across any vendor’s
enterprise middleware services.
It is agreed upon by industry.
References
Mastering Enterprise Java Beans
J2EE 1.4 Tutorials
Professional Java Server
Programming, J2EE Edition