Enterprise JavaBeans Introduction

advertisement
Enterprise JavaBeans
Introduction
z
EJB Container / Application server
–
–
z
Jens Gustavsson
z
Part of J2EE, standard from Sun
Implementation by independent tool vendors
–
–
Introduction
z
z
z
Enterprise JavaBeans ≠ JavaBeans
Server side component architecture
Separation of business logic from middleware
services:
–
–
–
–
–
networking
transactions
persistence
logging
resource pooling
Manages beans
Provides middleware services
IBM, Oracle, BEA, Borland, …
Open source: JBoss (www.jboss.org)
EJB Architecture
Client
EJB
EJB
Client
Client
EJB
EJB
Database
EJB Container
1
Clients
Distributed Objects
Client
Java
application
EJB
HTMLclient
Servlet
or JSP
Web server
EJB
EJB
Network
EJB
Database
EJB Container
Remote
interface
Implicit Middleware
z
Explicit middleware (e.g. CORBA) :
–
–
z
Write to API
Difficult to write, maintain and support
Implicit middleware (e.g. EJB)
–
–
–
–
Write isolated business logic
Declarative middleware service specifications
Middleware services automatically
Limitations by architectural constraints
Distributed
object
Distributed Objects
Client
Remote
interface
Stub
Network
Skeleton
Remote
interface
Distributed
object
2
Distributed Objects
Client
Remote
interface
Enterprise JavaBeans
Client
Stub
Network
Skeleton
Remote
interface
Remote
interface
Request
Interceptor
Remote
interface
Skeleton
Remote
interface
Bean
Skeleton
EJB Home Object
Client
Remote
interface
EJB
Object
EJB Container
Stub
Network
Network
Distributed
object
Distributed Objects the EJB way
Client
Stub
EJB
Object
Bean
Stub
Network
Skeleton
EJB
Object
Bean
EJB
Home
EJB Container
3
EJB Architecture
Deployment
z
z
Client
EJB
Object
Bean
z
EJB
Home
z
EJB Container
What does an EJB consist of?
z
z
z
z
z
z
z
z
Enterprise Bean class
Supporting classes
EJB Object
Remote interface
Home object
Deployment descriptor (XML)
Vendor-specific files
(Local interface)
z
z
JavaBeans - for development
Enterprise JavaBeans - for deployment
Deployment descriptor language is a
composition language
Deployment in practice
EJB-jar file is verified by container
Container generates stubs and skeletons
How to find a home object
z
Java Naming and Directory Interface (JNDI)
–
–
EJB-jar file
z
Similar to CORBA naming service
Mapping between resource names and physical
locations
No machine address to home object hard
coded
–
Address to JNDI server is needed
4
EJB Architecture
So, what does the container do?
z
3
Client
2
1
z
EJB
Object
Bean
z
EJB
Home
JNDI
z
EJB Container
Different kinds of Beans
z
Session beans
–
–
z
z
Stateless
Stateful
Entity beans
Message-Driven beans
Generate stubs and skeletons
Create EJB instances as needed. Pooling
instances.
Persisting entity beans.
Handles security and transactions via EJB
object
How can container vendors compete?
z
z
z
z
Caching strategies
Development tool integration
Database access optimization
Performance
5
XDoclet
z
z
Local interfaces
Remote interface, home interface, local
interface, local home interface, primary key
class, deployment descriptor, vendor specific
files
Specification in comments in Bean class
Demonstration
z
z
z
When beans calls beans locally
Optimization
Calls by value/reference problem
How is Persistence Achieved?
z
z
Bean managed persistence
Container managed persistence:
–
–
Our first bean
–
–
z
Object to relational database mapping (common)
Object databases (uncommon)
Container generates persistence as subclass
EJB-QL, query language
An entity bean should be seen as a view into
the database
6
Façade design pattern for EJB
Session
Bean
Session
Bean
Demonstration
Entity
Bean
Entity
Bean
En entity bean
Entity
Bean
EJB Container
Security
z
z
z
Authentication - JAAS
Authorization
Deployment descriptor
z
Roles
Roles and methods
z
–
–
z
Message-Driven beans
No instance level based security
z
Don't have home, remote or local interfaces
Have a single business method:
–
z
z
z
onMessage
No static type check
No return values
No exceptions
Stateless
7
Point-to-Point
Why Message-Driven Beans?
z
z
z
Queue
Publish - Subscribe
z
Performance
Reliability
Support for multiple senders and receivers
Easy integration to legacy systems
Final thoughts
z
Is it object-oriented?
–
–
Topic
z
Suitable for which tasks?
–
z
Separation of data and operations (entity beans
and session beans)
No inheritance between beans
One architecture. Anomalies if trying to do
anything else
Component marketplace?
–
Not today!
8
Resources
z
Szyperski, chapter 14
Sun EJB tutorial
z
Ed Roman: Mastering EJB
z
JBoss, Open source EJB Container
z
http://java.sun.com/j2ee/learning/tutorial/index.html
http://www.theserverside.com/books/wiley/masteringEJB/index.jsp
http://www.jboss.org
9
Download