a presentation about ejb

18
A Presentation About EJB Basic concept of EJB EJB Design Persistence Transaction Concurrency/Security J2EE Environment

Upload: moeshe

Post on 04-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A Presentation About EJB

A Presentation About EJB

Basic concept of EJB EJB Design Persistence Transaction

Concurrency/Security J2EE Environment

Page 2: A Presentation About EJB

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)

Page 3: A Presentation About EJB

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

Page 4: A Presentation About EJB

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

Page 5: A Presentation About EJB

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

Page 6: A Presentation About EJB

EJB Design

Good Design Style

JSP & SERVLETS

Session Bean

Entity Bean & Database

Presentation layer

Business Logic Layer

Data layer

•Entity bean logically is representation of database

•Easy for transaction management

•One business function could have to access several beans

•Easy for programming

•Easy for modification and extension

•Reduce network traffic and latency

Page 7: A Presentation About EJB

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 -- <container-

transaction> In JBOSS, you also have to write your own

– jboss.xml– jbuild.xml

Page 8: A Presentation About EJB

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

Page 9: A Presentation About EJB

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

Page 10: A Presentation About EJB

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 <container-

transaction> tag– Not supported, supported, required, requiresNew,

Mandatory, Never– method/bean

Page 11: A Presentation About EJB

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

Page 12: A Presentation About EJB

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

Page 13: A Presentation About EJB

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

Page 14: A Presentation About EJB

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

Page 15: A Presentation About EJB

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

Page 16: A Presentation About EJB

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

Page 17: A Presentation About EJB

Typical J2EE Server

Browser

ServletJSP Pool

Web interface

Session Bean

Bean pool

EJB container

Web Container

Database

Page 18: A Presentation About EJB

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