What is EJB - School of Computing and Engineering

Download Report

Transcript What is EJB - School of Computing and Engineering

A Presentation About EJB
Basic concept of EJB
 EJB Design
 Persistence
 Transaction
 Concurrency/Security
 J2EE Environment

What is EJB

A simple definition
– EJB is a standard server-side component model
for Component Transaction Monitors

EJB denote Enterprise JavaBean based
Component Transaction Monitor
– the EJB container is like mini-server, which
provide runtime support for beans it contians.

Beyond CTM
– persistence, security, concurrency and source
management ( bean instance pool, connection
pool)
Need for EJB

It is difficult to group operations on distributed objects
into single transaction.
 Transaction Processing Monitor has been around for
30 years, but it is not object oriented (procedure).
The business logic in a TP monitor is not as flexible,
extensible, or reusable as business objects in a
distributed object system.
 ORB based distributed object system need to handle
concurrency, transaction, security, persistence and
everything else.
 With EJB, the only thing you focus on is the business
logic. It makes server developing simpler and faster
Component Model

A component model defines a set of interfaces and
classes in the form of Java Packages that must be
used in a particular way to isolate and encapsulate a
set of functionality.

Component is developed for a specific purpose but
not a specific application, can be used to any
business application which needs that component-reusable, portable

The component model is a contract that defines the
responsibilities of the CTM and the business objects

EJB is standard server-side component model
Benefit of Standard Component Model

The standard component model is one of the
keys for the future success of a distributed
system
 you can develop business objects using EJB
and expect them to work on any CTM which
support EJB specification--reusability, and
portability
 It can benefit from the third part products, the
add-on products and component library is
more attractive to software vendors
 EJB is the only standard server component
so far
EJB Design

Good Design Style
JSP &
SERVLETS
Session Bean
Presentation
layer
•Entity bean logically is representation
of database
•Easy for transaction management
Business Logic
Layer
•One business function could have
to access several beans
•Easy for programming
Entity Bean
& Database
Data layer
•Easy for modification and
extension
•Reduce network traffic and latency
XML Deployment Descriptor

deploy descriptor--ejb-jar.xml
 Tell the container how to manage the objects
– decsribe bean--entity or session
(stateless/stateful)
– Specifying the primary key -- <prim-key-class>
– set environment entries -- <env-entry>
– set the interaction of beans -- <ejb-ref>
– set transaction /secyrity property -- <containertransaction>

In JBOSS, you also have to write your own
– jboss.xml
– jbuild.xml
Persistence: BMP





BMP/CMP
EJB has strict specification on BMP, so your
implementation can be used for any vendor
the bean implementation class must
implement all SQL operations.
In EJB implementation you have to provide
implementation for all the methods which
involved in SQL operation.
Set persistence management as Bean in -ejb-jar.xml
Persistence: CMP






CMP is vendor specific, the EJB specification
does not say how CMP should work
You do not have to write any data access
code. do not have to provide any method
implementation.
dramatically different from version1.1 to
version2.0
set the persistence as container in ejb-jar.xml
specify data mapping in ejb-jar.xml
the beauty of CMP is freeing you from the
coding except business logic
Transaction

Transaction is an integral part of Database
application
 In distributed system, you have to implement a set of
operation over several distributed databases
 Transaction let you to group a set of distributed
operations into all-or-nothing operation
 CTM / BTM/ Client
 CTM -- Controlled by using the deployment descriptor
 set transaction property inside <containertransaction> tag
– Not supported, supported, required, requiresNew,
Mandatory, Never
– method/bean
Transaction -- BMT







An entity bean is not allowed to control its
transaction scope at all wherever in CTM or
BTM
Java Transaction Service (JTS)
Java Transaction API ( JTA ) to control JTS
Only session bean can call the
getUserTransaction method in the
SessionContext object
context.getUserTransaction().begin()
context.getUserTransaction().commit()
CMT and BMT can not mixed
Distributed Objects Communication

Three main distributed object services
available
– CORBA, platform and language independent
– DCOM, only use in Microsoft platform
– Java RMI, limited to the Java Remote Method
Protocol

EJB use Java RMI-IIOP
– am implementation of the Java RMI over IIOP,
which combine the simplicity of the Java RMI and
platform and language independence of IIOP
– Sun also provides API for EJB to communicate
with CORBA based distributed objects
– all communications are remote based
Concurrency

Session bean do not support concurrent
access
– stateless, no state need to maintain
– stateful, extension of one client, only serve that
client

Entity beans are shared component that need
to implement concurrency
– EJB automatically support
– normally no coding needed

reentrant/loopback
– a thread of control try to reenter a bean instance
– non reentrant by default
Security/Naming

Security issue
– Authentication
– access control
– secure communication
• EJB1.1 only specify the access control
• EJB 2.0 have specification on Authentication too

Naming service must provide
– object binding
– lookup API

EJB use JNDI to locate the beans and
sources
Web Interface

Web application uses a combination of servlet
and Java server page, we can use servlet to
access the session bean directly, but. . . . . .
 The client -side stubs have no awareness of
the HttpSession class
 when session goes away, the session bean
can continue to exist for some period of time
before EJB container figure out that the client
is gone. It is waste of resource.
 the Access bean will take care of the problem
by using HttpSessionBindingListener
interface
J2EE Environment

Basically, when you use EJB, you are not
only working with EJB, you are working with
J2EE Environment.
 A typical j2ee server typically include JSP,
Servlet, EJB, JNDI, JMS, JDBC, XML, RMI,
and CORBA. JBOSS as well.
 EJB is the core part of J2EE environment
 A typical J2ee server is typical 3-tier server
system
– Web server
– EJB server
– Database
Typical J2EE Server
Browser
Web Container
JSP Pool
Servlet
Web interface
Session Bean
EJB container
Bean pool
Database
Limitation/Improvement

the most common knocks against EJB is its
performance
– all Communication among beans must be through
Remote interface--data marshalling
– Even local method call is more expensive in EJB
– Transaction overhead
– database access

Improve EJB performance
–
–
–
–
–
minimize the remote method call
increased entity and session caching
Data connection pool
An optimized local call mechanism
Data caching