Download TDDC18 EJB Intro An EJB is a

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
EJB Intro
An EJB is a distributed server-side non-visual
component
-
EJB is a part of the J2EE standard
-
TDDC18
-
Mikhail Chalabine
[email protected]
-
Multiple address spaces
Distributed objects
Transactional access to remote objects
javax.ejb package
Component specification
Programmer implements a set of interfaces from the EJB API
Implementation by independent vendors
•
Tools and Containers
-
-
Proprietory: IBM (WebSphere), BEA (WebLogic),
Netscape (iPlanet), Oracle, Borland
Open source: JBoss (www.jboss.org)
Mikhail Chalabine [email protected]
Sun and
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
1
2
EJB Intro cont.
Separate business logic from middleware services:
-
networking
transactions
persistence
logging
resource pooling
Client
EJB
-
EJB
Client
EJB Container / Application server
-
EJB Architecture
Client
Manages beans
Provides middleware services
EJB
EJB
Database
EJB Container
Clients: JSPs, Servlets, Java applications, and
other EJBs
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
3
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
4
Clients (typical use cases)
Middleware
•
Java
application
•
EJB
HTMLclient
EJB
EJB
EJB
•
Database
Web server
•
EJB Container
•
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Write to API
Difficult to write, maintain and support
Implicit middleware (e.g. EJB)
•
Servlet
or JSP
Mikhail Chalabine [email protected]
Explicit middleware (e.g. CORBA) :
Write isolated business logic
Declarative middleware service specifications
Middleware services automatically
Tool support
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
5
6
Distributed Objects
Distributed Objects
Client
Client
Stub
Remote
interface
Network
Network
Remote
interface
Mikhail Chalabine [email protected]
Distributed
object
Skeleton
Remote
interface
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
7
Distributed
object
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
8
Distributed Objects
Client
Distributed Objects using EJBs
Client
Stub
Remote
interface
Network
Remote
interface
Skeleton
Remote
interface
Mikhail Chalabine [email protected]
Stub
Remote
interface
Request
Interceptor
Network
Distributed
object
Skeleton
Remote
interface
EJB
Object
Bean
Remote
interface
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
9
10
Execution flow
EJB 2.0
Client calls a method on the EJB object
EJB object delegates the call to a bean
EJB receives the result
EJB passes the result to the caller
Home interface
•
Remote interface
•
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Defines the business methods of the bean
Bean class
•
Mikhail Chalabine [email protected]
Defines the life cycle methods of the bean
Business logic
Mikhail Chalabine [email protected]
11
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
12
Enterprise JavaBeans
Client
EJB Object (Remote Interface)
Client
Stub
EJB
Object
Network
Stub
Network
Bean
Skeleton
EJB
Object
Skeleton
EJB Container
Mikhail Chalabine [email protected]
Bean
EJB Container
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
13
EJB Object (Remote Interface)
14
EJB Home Object (Home Interface)
Extends javax.ejb.EJBObject
Defines business methods clients call
Acts as a proxy
Client
Stub
Network
package ejbExample.interfaces
/* This is a remote interface for HelloBean */
public interface Hello extends javax.ejb.EJBObject {
public String Hello() throws java.rmi.RemoteException;
}
Skeleton
EJB
Object
Bean
EJB
Home
EJB Container
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
15
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
16
EJB Home Object Characteristics
Summary: EJB Architecture
Extends javax.ejb.EJBHome
Acts as a factory to create EJB instances
Allows clients to create/remove/find EJBs
EJB
Object
Client
package ejbExample.interfaces
EJB
Home
/* HelloBean's home interface */
public interface HelloHome extends javax.ejb.EJBHome {
Hello create() throws java.rmi.RemoteException,
javax.ejb.CreateException;
}
Mikhail Chalabine [email protected]
Bean
EJB Container
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
17
18
Summary: an EJB consist of
Enterprise Bean class
Supporting classes
EJB Object
Remote interface
Home object
Deployment descriptor (XML)
Vendor-specific files
(Local interface)
Mikhail Chalabine [email protected]
Deployment
EJB-jar file
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
EJB deployment descriptor (XML)
ejb-jar.xml
Attributes of the beans specified declaratively
Deployment descriptor language is a
composition language
EJB-jar file is verified by container
Container generates stubs and skeletons
Mikhail Chalabine [email protected]
19
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
20
How clients find the Home object
Java Naming and Directory Interface (JNDI)
-
EJB Architecture
Similar to CORBA naming service
Mapping between resource names and physical locations
3
No machine address to home object hard
coded
-
EJB
Object
Bean
Client
2
Address to JNDI server is needed
Kept in the initial context
Use initial context factory to acquire an initial context (is
the JNDI driver)
Vendor specific, bound to J2EE server implementation
1
JNDI
EJB
Home
EJB Container
Context ctx = new InitialContext();
HelloWorldHome home = (HelloWorldHome)
PortableRemoteObject.narrow(ctx.lookup("HelloWorld"),
HelloWorldHome.class);
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
21
22
Types of Beans
•
Session beans
•
So, what does the container do?
Stateless
Stateful
Entity beans
Message-Driven beans
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Generates stubs and skeletons
Creates EJB instances as needed.
Persists entity beans.
Handles security and transactions
Mikhail Chalabine [email protected]
23
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
24
XDoclet
How can container vendors compete?
Caching strategies
Development tool integration
Database access optimization
Performance
Deployment descriptor
Generate from declarative specification
•
•
•
•
•
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Remote interface
home interface
local interface
local home interface
primary key class
Specification as comments in the
Bean class
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
25
26
Local interfaces
When beans call beans locally
Optimization
Call by value/reference problem
TDDC18
Mikhail Chalabine
[email protected]
Mikhail Chalabine [email protected]
27
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
28
Entity Beans
How is Persistence Achieved?
Represent business data stored in database
Database types converted to Java types
Change of values in the Entity Bean is
propagated to the DB
Bean managed persistence (BMP)
Container managed persistence (CMP):
•
•
•
•
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Object to relational database mapping (common)
Object databases (uncommon)
Container generates persistence as subclass
EJB-QL, query language
An entity bean is a view into a data source,
e.g., a database
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
29
30
Façade design pattern for EJB
Security
Session
Bean
Entity
Bean
Authentication - JAAS
Authorization
Deployment descriptor
•
Entity
Bean
Session
Bean
•
Roles
Roles and methods
No instance level based security
Entity
Bean
EJB Container
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
Mikhail Chalabine [email protected]
31
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
32
Message-Driven beans
Don't have home, remote or local interfaces
Have a single business method:
•
TDDC18
Mikhail Chalabine
[email protected]
onMessage
No static type check
No return values
No exceptions
Stateless
Mikhail Chalabine [email protected]
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
33
34
Why Message-Driven Beans?
Final thoughts
Performance
Reliability
Support for multiple senders and receivers
Easy integration to legacy systems
Is it object-oriented?
•
•
Suitable for which tasks?
•
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
One architecture. Anomalies if trying to do anything
else
Component marketplace?
•
Mikhail Chalabine [email protected]
Separation of data and operations (entity beans and
session beans)
No inheritance between beans
Not today!
Mikhail Chalabine [email protected]
35
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
36
Against
Remotability
•
Resources
Pramatics: stay away from large distributed systems
Security
Persistence
Caching
Scalability
Messaging
Transactions
Mikhail Chalabine [email protected]
Szyperski, chapter 14
Sun EJB tutorial
•
Ed Roman: Mastering EJB
•
http://www.theserverside.com/books/wiley/
masteringEJB/index.jsp
JBoss, Open source EJB Container
•
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
http://java.sun.com/j2ee/learning/tutorial/index.html
http://www.jboss.org
Mikhail Chalabine [email protected]
37
TDDC18: Lesson 1: Dynamic Metaprogramming, Java Reflection
38
Related documents