Tải bản đầy đủ (.ppt) (60 trang)

Enterprise Java Beans

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.13 MB, 60 trang )



Enterprise Java
Beans,
an Introduction
Barbara Dellen
Jeff Thomson


Contents

Overview: What are EJB’s?

EJB Fundamentals

EJB’s and Gemstone


The Model

Enterprise JavaBeans are Java
components that fit together in a standard
way.

The container provides a portability layer
that lets anyone’s beans operate in
anyone else’s container.


Containers


Containers are software receptacles that
know how to communicate with and
manage the beans.

The container places itself between the
client and the bean. This gives it the
opportunity to implement services many
developers don’t want to worry about.


Container Services

Some services that can be provided by
the container include:

Persistence management

Transactions

Concurrency

Thread management

Security


Container Vendors

Many vendors have already supplied
containers for EJB and their products.

Among them are:

IBM

WebLogic

Sybase

Oracle

CORBA Object Request Brokers such as
Inprise (Borland)


Infoworld’s Example

Infoworld developed a sample
application for EJB using:

WebLogic’s Tengah Java application server
as the container

IBM as the server

Oracle as the database

The application’s use of servlets to act as
clients to the EJB’s allows for browsers
that don’t support Java.



Example continued

The sample application was a J-Store that
simulated an online-shopping service

EJB handled the business objects

Java servlets and JavaPages take care of the
page transmission and display logic

Application authenticates users and lets
them browse GIF images, load them into a
shopping cart

and tallies up the sale.


Behind the scenes

The container interposes itself between
the client and the bean.

Beans that a client creates do not expose
their functions directly to the client

The container exposes the methods of the
remote interface

Which is assembled ahead of time by the

container vendor.
This is known as “wrapping” the object.


The Container

You can specify to the container at
deployment time how to treat your
components

This is called Declarative programming.


Unwrapping

To find the bean’s home interface, the
client must appeal to the container via
JNDI - Java Naming and Directory
Interface.


Back to the Example

The application’s server bean runs alone
inside the Tengah container

But EJB lets multiple beans run side by
side in the container.

EJB also allows multiple instance of the

same bean.

Also, EJB allows multiple containers to
run on a server.
Bean programmers don’t have to worry about
the number of clients activating a bean.


Session Beans

Session beans are used by one client
only, two clients may not access the
same instance of a session bean.

Session beans are lost in a server crash.


Two Session Beans

Stateless Beans

A stateless bean looks the same to a client
before and after operation.

Stateful Beans.

A stateful bean is semipersistent

The developer can have them swap their
parameters to disk, passivate the bean, then

later reactivate it.


Entity Beans

Entity beans survive if the server crashes.

Multiple clients can access a single entity
bean via multiple instances.

The container makes sure each instance
is bound to the current data and passes
info to the proper client.


References
Tom Young and Yun Wang,
Mixing Sun’s Magic Beans,
Infoworld Publishing Company,
June 29, 1998.
www.infoworld.com/cgi-bin/displayTC.pl?/980629analysis.html


EJB Architecture
Client
EJB Server
Container
Home Object
EJB Object
EJB Object

enterprise Bean
enterprise Bean
Remote Interface
Remote Interface
Home Interface


Enterprise Bean Types

Session Beans

Executes on behalf of a single client (not
shared)

Updates shared data in an underlying
database

Does not represent directly shared data in
the database

Is removed when the EJB server crashes


Once again: EJB Types

Entity Beans

Represents data in the database

Is transactional


Allows shared access from multiple users

Long-lived

Survives crash of the EJB server


Roles in EJB Development

Client

Enterprise Bean Provider

Container Provider


Session Beans: client view
Client
Container
BankBeanHome
:BankBeanRemote
:BankBean Remote
:BankBeanRemote
AirlineBeanHome
:AirlineBeanRemote
:AirlineBeanRemote
BankBean class
AirlineBean class



Client view on a session Bean

Non-persistent object that implements some business
logic running on the server

Access it through the session Bean’s remote interface

EJB object is RMI-object & implements session
Bean’s remote interface

EJB object lives in container

Container provides security, transactions, swapping
etc. transparent to the client

Container may handle multiple EJB classes

Client does never communicate with the actual session
Bean object but with the corresponding EJB object


The EJB object

Provided by the container

Supports enterprise Bean’s remote
interface

Delegates invocation of a business

method to the enterprise Bean instance

Supports methods of
javax.ejb.EJBObject interface (getting
the object’s container, etc.)


Class Diagram for a session Bean
BankBean
BankBeanRemote
<<Interface>>
javax.ejb.EJBObject
<<Interface>>
BankBean implements the
business methods of the
BankBeanRemote interface.
javax.ejb.EJBHome
<<Interface>>
BankBeanHome
<<Interface>>
javax.ejb.SessionBean
activate()
passivate()
remove()
setSessionContext(SessionContext)


Session Bean

Implements business methods of the

Bean’s remote interface

Implements the javax.ejb.SessionBean
interface

activate()/passivate() signals when the Bean
is about to be activated/passivated by the
container

Implements ejbCreate(…) methods

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×