View
218
Download
0
Category
Preview:
Citation preview
7/31/2019 EJB - Part-1
1/44
EJB Overview
7/31/2019 EJB - Part-1
2/44
Agenda
What is and why EJB?
EJB Architecture
Component and Container ArchitectureTypes of Beans
Roles
Anatomy of EJB Module
How client invokes methods of EJB
RMI Communication model
Deployment Descriptor & Packaging
7/31/2019 EJB - Part-1
3/44
What is EJB(From Specification)
The Enterprise Java Beans architecture is a componentarchitecture for the development and deployment of
component-based distributed business applications.
Applications written using Enterprise Java Beans
Architecture are scalable, transactional, and multi-usersecure.
These Applications may be written once, then deployedon any server platform that supports the Enterprise JavaBeans Specification.
7/31/2019 EJB - Part-1
4/44
EJB Design Principles
EJB applications are loosely coupled
EJB behavior is specified by interfaces
EJB applications do not manage resourcesThe container supports the application developer
EJB applications are tiered
The session tier is the API to the applicationThe entity tier is the API to the data sources
7/31/2019 EJB - Part-1
5/44
EJB applications are Loosely
CoupledSupports the integration of components from different
vendors
EJBs refer to other components and services to whichthey have access by arbitrary names
EJB can be authored without a detailed knowledge of
the environmentApplications can be assembled from separatecomponents
7/31/2019 EJB - Part-1
6/44
EJB Architecture
7/31/2019 EJB - Part-1
7/44
EJB behavior is specified
by Java Interfaces
An EJBs interaction with its clients is specified entirelyin terms of java interfaces
- Interfaces expose the methods that clients cancall, and thereby set out a contract between client
and EJB- Implementation is hidden from client
- supports portability and modularity
7/31/2019 EJB - Part-1
8/44
EJB applications do not
manage Resources
EJBs get access to external resources (databases,legacy systems) through their container
- Programmer does not have to worry aboutresource allocation and de-allocation
It is the containers job to manage these resources, andmake the access as efficient as possible
- Container is configured by System Admin not
through programming APIs
7/31/2019 EJB - Part-1
9/44
Container supports
application developer
Container provides System services
- Persistence- Security
- Transaction
- Connection Pooling- Component Life Cycle Management
- Threading
Application developer and deployer specifies his/herrequirements in declarative fashion (in deploymentdescriptor)
7/31/2019 EJB - Part-1
10/44
EJB in a
Big picture of J2EE
7/31/2019 EJB - Part-1
11/44
Where is EJB?
7/31/2019 EJB - Part-1
12/44
EJB, EJB Server, EJB Client
7/31/2019 EJB - Part-1
13/44
Why EJB Technology?
Leverages the benefits component-model on the serverside
Separates business logic from System codeProvides framework for portable components
- Over different J2EE-compliant servers
- Over different operational environmentsEnables deployment time configuration
- Deployment Descriptor
7/31/2019 EJB - Part-1
14/44
Enterprise Java Beans
Defined as business Logic ONLY
No low level plumbing
Reusable across multiple EJB Servers
Implements interfaces that allow container to managethem
7/31/2019 EJB - Part-1
15/44
EJB Architecture
7/31/2019 EJB - Part-1
16/44
EJB Architecture Contracts
Contracts are specified in EJB specification
Client View Contract- Contract between client and container
Component Contract- Contract between an Enterprise Bean and itsContainer
7/31/2019 EJB - Part-1
17/44
Client View Contract
7/31/2019 EJB - Part-1
18/44
Client View Contract
Client of an EJB can be- Web tier components: Servlet and JSP
- Standalone Java application or Applet
- Another EJB in same or different container- Web services client (in EJB 2.1)
Provides development model for clients using EJB
ServicesClient view contract is comprised of
- Home Interface
- Logic (also called Remote) Interface- Object Identity
- Metadata Interface and Handle
7/31/2019 EJB - Part-1
19/44
Component Contract : What
container does(for Beans)
Enables EJB method invocations from EJB instances
Manages the life cycle of EJB Bean InstancesImplements Home and Remote Interfaces
Provide persistence for CMP entity beans
Provide runtime context information to beansManage transactions, security, exceptions etc..
Implements callbacks
7/31/2019 EJB - Part-1
20/44
EJB Contracts
7/31/2019 EJB - Part-1
21/44
J2EE
Component & Container
Architecture
7/31/2019 EJB - Part-1
22/44
J2EE containers & components
7/31/2019 EJB - Part-1
23/44
Containers & Components
7/31/2019 EJB - Part-1
24/44
What the EJB Container does
Generate concrete class for
- Remote (or Local) Home Interface- Remote (or Local) Logic Interface
Binds home object to Naming service
- clients can lookup the home object using JNDICreates free beans pool
Caches recently accessed beans
Provides JDBC connection poolingBinds external resources to Naming service
7/31/2019 EJB - Part-1
25/44
Types of Beans
Session Beans
Stateful session beans
Stateless session beans
Entity Beans
Bean Managed Persistence (BMP) Container Managed Persistence (CMP)
Message Driven Beans
7/31/2019 EJB - Part-1
26/44
Roles
Distinct Roles in the application development anddeployment Life Cycle
- EJB Bean Provider
- Application Assembler- Deployer
- EJB Server Provider
- System Administrator- Tool Provider
7/31/2019 EJB - Part-1
27/44
Life Cycle Illustration
7/31/2019 EJB - Part-1
28/44
Anatomy of EJB Module
(EJB-JAR file)
7/31/2019 EJB - Part-1
29/44
Home Interface
Defines methods for creating, finding, and removingbeans
- Factory Interface
Implemented by container- EJB home object
Client gets reference to stub object of the EJB home
object via JNDICan be remote or local
7/31/2019 EJB - Part-1
30/44
Remote Interface
Defines business methodsImplemented by container
- EJB Object
Client gets reference to stub object of the EJB objectthrough create() or find() of home interface
Can be remote or local
7/31/2019 EJB - Part-1
31/44
Steps for client to invoke
methods of EJB
Get EJB home object (actually a stub object of the EJB
home object) via JNDI- Get Initial Context
- Perform Lookup
- Perform narrowingFrom EJB home object, get a EJB object (actually a stubobject of the EJB object)
Invoke business methods from EJB object
Clean up
7/31/2019 EJB - Part-1
32/44
Example
7/31/2019 EJB - Part-1
33/44
RMI CommunicationModel
7/31/2019 EJB - Part-1
34/44
Distributed Objects
Collaborating objects reside in different computers(different VMs)
- client objects invoke methods of server objects
There have to be some mechanisms
- passing method signature from client to server
- marshalling parameters from client to server
- unmarshalling received parameters at the server- marshalling return values from server to client
- unmarshalling received results at the client
7/31/2019 EJB - Part-1
35/44
RMI Communication Model
l l
7/31/2019 EJB - Part-1
36/44
RMI Control Flow
Client Object
1.Calls methods on
stub
2.Receives results
from stub
Stub implements Interface
2.Marshalls arguments
3.passes call to remote
object
8.receives and unmarshall
results
Remote Object(Server)
Implements interface
4.receives calls and
arguments
5.processes call
6.returns results
3
7
Interface Definition
Declares
Methods
Where does RMI Communication
7/31/2019 EJB - Part-1
37/44
Where does RMI Communication
Occur
RMI Over IIOP
7/31/2019 EJB - Part-1
38/44
RMI Over IIOP
7/31/2019 EJB - Part-1
39/44
RMI over IIOP
RMI mechanism used between EJB client and EJB server- Before EJB 2.0, RMI over IIOP has to be usedeven if EJB client and EJB server reside in the
same VM, which results in unnecessary overhead- Vendor products provide some optimizedcommunication if client and server reside in singleVM
RMI operations in general are expensive
- Reason why local interface are introduced in EJB2.0 (J2EE 1.3)
EJB-JAR Deployment
7/31/2019 EJB - Part-1
40/44
EJB JAR Deployment
DescriptorGives the container instructions on how to manage theenterprise bean
Allows declarative customization
Control behaviors for:- Transactions
- Security
- Life Cycle- State Management
- Persistence
Deployment Descriptor
7/31/2019 EJB - Part-1
41/44
Deployment Descriptor
Example
7/31/2019 EJB - Part-1
42/44
EJB 2.0 New Features
Integrated support for JMS
Support for local interfaces
Improved Architecture for CMP
- Support for container managed relationships forentity beans
Enterprise Java Beans Query Language (EJB QL)
Home methods for entity BeansNetwork interoperability
7/31/2019 EJB - Part-1
43/44
Thank You..
R f c s
7/31/2019 EJB - Part-1
44/44
References
J2EE Specifications by SUN
J2EE Passion Web Site j2eepassion.comA Practical Introduction to EJBs
http://www.comptechdoc.org/docs/kanti/ejb/index.html
Enterprise Java Beans - http://my.execpc.com/~gopalanhttp://www.theserverside.com/articles/article.tss
Recommended