EJB and Types
By: Faisal hameed
Introduction to EJB
Enterprise Java Beans (EJB) is a development architecture for
building highly scalable and robust enterprise level
applications to be deployed on J2EE.
EJB is a server-side software component
that encapsulates business logic of an application.
2
Introduction to EJB
EJB application is deployed on the server, so it is called server
side component also.
EJB is like COM (Component Object Model) provided
by Microsoft.
Presented by Sun in the 1999.
EJBapplication runs in a J2EE Server or Application Server.
3
EJB Container
JBOSS
GlassFish
Web-Logic
Websphere
4
EJB Version
> EJB 3.2, final release (2013-05-28)
> EJB 3.1, final release (2009-12-10)
> EJB 3.0, final release (2006-05-11)
> EJB 2.1, final release (2003-11-24)
> EJB 2.0, final release (2001-08-22)
> EJB 1.1, final release (1999-12-17)
> EJB 1.0 (1998-03-24)
5
Requirements
> JDK Oracle JDK 8 Update 20
> NetBeans IDE 8.2
> GlassFish 4.1.2
6
To run EJB application, you need an application
server (EJB Container) such as
Jboss,Glassfish, Weblogic, Websphere etc. It
performs:
life cycle management,
security,
transaction management, and
object pooling.
Life Cycle Management:
The various stages through which
an enterprise bean go through its
lifetime is known as the life cycle
of EJB such as:
Does not exist
Ready
Passive
8
Security:
An EJB container/server vendor
must provide support for
numerous operations, including
authentication, identity
propagation, and identity
delegation. At the same time, the
vendor must support secure
communication between an EJB
client and server and must provide
a means for security auditing.
9
Object pooling:
"Object pooling" (sometimes
called "resource pooling") is a
term used to describe a
mechanism for reusing
temporary objects, thus,
reducing the number
of objects that are created,
optimizing instantiation time
and reducing garbage collection
10
Transaction Management:
A transaction is a single unit of work items, which follows the ACID
properties. ACID stands for Atomic, Consistent, Isolated, and Durable.
> Atomic − If any of the work item fails, the whole unit will be
considered failed. Success meant, all items execute successfully.
> Consistent − A transaction must keep the system in consistent state.
> Isolated − Each transaction executes independent of any other
transaction.
> Durable − Transaction should survive system failure if it has been
executed or committed.
11
When to use EJB?
> Application needs Remote Access. In other words, it is
distributed.
> Application needs to be scalable. EJB applications
supports load balancing, clustering and fail-over.
> Application needs encapsulated business logic. EJB
application is separated from presentation and persistent
layer.
12
Features
13
Multi-tiered
EJB applications Distributed
supports load System
balancing, Highly
transactional
clustering and Environment
fail-over Robustness
Scalability
14
Disadvantages of EJB
> Requires application server
> Requires only java client.
For other language client,
you need to go for
webservice.
> Complex to understand and
develop ejb applications.
15
Difference between Web server
and Application Server ?
A Web server contains only a web container but an
Application Server contains both a Web Container
and a EJB Container.
A Web Server does not follows Clustering but an
Application Server follows Clustering.
16
EJB Container & EJB Object
An EJB component runs on the server in an EJB container
and implements the business logic.
The EJB object runs on the client and remotely executes the
EJB component's methods.
17
How EJB WORKS?
18
Who can access EJB
EJB Component runs inside a server and it can be accessible by
the Following Types of Clients.
> A Desktop application can access EJB
> An applet can access EJB
> A web client Using Servelt or Jsp can accessEJB.
> One EJB can access another EJB.
> A CORBA client can access EJB.
19
Elements of EJB
Elements of EJB components are
> Naming Services
> Home Interface
> Remote Interface
> Bean Class.
20
Requirements
21
Naming Services (JNDI)
> The Java Naming and Directory Interface™ (JNDI) is an
application programming interface (API) that
provides naming and directory functionality to applications
written using the Java™ programming language.
> It allows Java software clients to discover and look up data and
resources (in the form of Java objects) via a name.
> It is defined to be independent of any specific directory
service implementation.
22
Naming Services (JNDI) (continue..)
Thus a variety of directories -new, emerging, and already deployed
can be accessed in a common way.
It performs these tasks:
> connecting a Java application to an external directory service
> allowing a Java Servlet to look up configuration information
provided by the hosting web container.
23
Naming Services (JNDI) Architecture
The JNDI architecture consists of an API and a service provider
interface (SPI).
Java applications use the JNDI API to access a variety of naming
and directory services.
The SPI enables a variety of naming and directory services to be
plugged in transparently, thereby allowing the Java application
using the JNDI API to access their services.
24
25
Naming Services (JNDI) Packaging
JNDI is included in the Java SE Platform.
The JDK includes service providers for the following
naming/directory services:
> Lightweight Directory Access Protocol (LDAP)
> Common Object Request Broker Architecture (CORBA)
Common Object Services (COS) name service
> Java Remote Method Invocation (RMI) Registry
> Domain Name Service (DNS)
26
Home Interface
> Home Interface is a factory for creating EJB Objects.
> Home Interface Extends EJB Home interface and it is given in
Javax.ejb.*;
> The Home Interface contains Life Cycle methods like Create(),
Remove(), findXxx(), etc..
> Each method in Home Interface returns the Remote Object or
EJBObject.
> Each method in Home Interface throws “Remote Exception”.
27
Features
28
Remote Interface:
> It Contains Business logic methods.
> In order to create a Remote Interface ,Our Interface must be
extend EJBObject interface.
> Remote Interface is given in Javax.ejb.*;Package.
> Each Business method in this interface throws “Remote
Exception”.
> The return values of these methods can be void or primitives
or Objects.
29
Features
30
The Bean Class
> The Bean Class contains both Life cycle methods
Implementation + Business Logic Methods given in Home
Interface and Remote Interface and also it contains Container
Call back methods.
> The Bean Class must be implemented either Session Bean or
Entity Bean or Message Driven Bean Interfaces.
31
Requirements
32
Take Rest & Enjoy Meal
I Know You Are Tired!
Thanks!
34