Вы находитесь на странице: 1из 9

Introduction

Enterprise JavaBeans
z EJB Container / Application server
– Manages beans
– Provides middleware services
z Part of J2EE, standard from Sun
Jens Gustavsson z Implementation by independent tool vendors
– IBM, Oracle, BEA, Borland, …
– Open source: JBoss (www.jboss.org)

Introduction EJB Architecture

z Enterprise JavaBeans ≠ JavaBeans


z Server side component architecture
z Separation of business logic from middleware Client
EJB EJB
services:
Client
– networking
EJB EJB
– transactions Client Database
– persistence
EJB Container
– logging
– resource pooling

1
Clients Distributed Objects

Client
Java
application
EJB EJB
Network
HTML- Servlet
client or JSP EJB EJB
Database
Web server EJB Container Distributed
Remote object
interface

Implicit Middleware Distributed Objects

z Explicit middleware (e.g. CORBA) :


Client Stub
– Write to API Remote
– Difficult to write, maintain and support interface

z Implicit middleware (e.g. EJB)


Network
– Write isolated business logic
– Declarative middleware service specifications
– Middleware services automatically Distributed
Limitations by architectural constraints Skeleton

Remote object
interface

2
Distributed Objects Enterprise JavaBeans

Client Stub Client Stub


Remote
interface

Request EJB
Network Interceptor Network Bean
Remote Object
interface

Distributed
Skeleton Skeleton
Remote object
interface EJB Container

Distributed Objects the EJB way EJB Home Object

Client Stub Client Stub


Remote
interface

EJB EJB
Network Object Network Bean
Remote Object
interface
EJB
Skeleton Bean Skeleton Home
Remote
interface EJB Container

3
EJB Architecture Deployment

z JavaBeans - for development


z Enterprise JavaBeans - for deployment
EJB z Deployment descriptor language is a
Bean
Object composition language
Client
EJB
z Deployment in practice
Home z EJB-jar file is verified by container
z Container generates stubs and skeletons
EJB Container

What does an EJB consist of? How to find a home object

z Enterprise Bean class z Java Naming and Directory Interface (JNDI)


z Supporting classes – Similar to CORBA naming service
z EJB Object – Mapping between resource names and physical
z Remote interface locations
Home object EJB-jar file
z z No machine address to home object hard
z Deployment descriptor (XML) coded
z Vendor-specific files – Address to JNDI server is needed
z (Local interface)

4
EJB Architecture So, what does the container do?

z Generate stubs and skeletons


EJB
z Create EJB instances as needed. Pooling
3
Bean instances.
Object
Client z Persisting entity beans.
2 EJB
Home
z Handles security and transactions via EJB
1 object
JNDI EJB Container

Different kinds of Beans How can container vendors compete?

z Session beans z Caching strategies


– Stateless z Development tool integration
– Stateful z Database access optimization
z Entity beans z Performance
z Message-Driven beans

5
XDoclet Local interfaces

z Remote interface, home interface, local z When beans calls beans locally
interface, local home interface, primary key z Optimization
class, deployment descriptor, vendor specific z Calls by value/reference problem
files
z Specification in comments in Bean class

How is Persistence Achieved?


Demonstration
z Bean managed persistence
z Container managed persistence:
– Object to relational database mapping (common)
– Object databases (uncommon)
Our first bean – Container generates persistence as subclass
– EJB-QL, query language
z An entity bean should be seen as a view into
the database

6
Façade design pattern for EJB
Demonstration

Session Entity
Bean Bean
Entity En entity bean
Bean
Session
Bean Entity
Bean

EJB Container

Security Message-Driven beans

z Authentication - JAAS z Don't have home, remote or local interfaces


z Authorization z Have a single business method:
z Deployment descriptor – onMessage
– Roles z No static type check
– Roles and methods z No return values
z No instance level based security z No exceptions
z Stateless

7
Point-to-Point Why Message-Driven Beans?

z Performance
z Reliability
z Support for multiple senders and receivers
z Easy integration to legacy systems
Queue

Publish - Subscribe Final thoughts

z Is it object-oriented?
– Separation of data and operations (entity beans
and session beans)
– No inheritance between beans

Topic
z Suitable for which tasks?
– One architecture. Anomalies if trying to do
anything else
z Component marketplace?
– Not today!

8
Resources

z Szyperski, chapter 14
z Sun EJB tutorial
http://java.sun.com/j2ee/learning/tutorial/index.html

z Ed Roman: Mastering EJB


http://www.theserverside.com/books/wiley/masteringEJB/index.jsp

z JBoss, Open source EJB Container


http://www.jboss.org

Вам также может понравиться