Ejb 1
Ejb 1
19.2
Enterprise JavaBeans
Lecture 1 Tuomas Mikkola Solita Oy
26.2
Entity Beans Message-Driven Beans EJB Clients
19.2.2003
Tuomas Mikkola
19.2.2003
Tuomas Mikkola
Lectures
5.3
Transactions Security J2EE Design Patterns
History of EJBs
At first Java was focused on the client-side features (Java Applets) Today the focus is in the server-side features, Java is a platform for building enterprise applications. Java provides several vendor-independent interfaces, first example of this is JDBC.
Other similar examples nowadays JNDI, JTA and JMS
19.2.2003
Tuomas Mikkola
19.2.2003
Tuomas Mikkola
History of EJBs
First draft of EJB specification was introduced in 1997 EJB 1.0 spec was finalized in 1998 First update, EJB 1.1 in 1999 The latest version EJB 2.0 in 2001 EJB 2.1 specification in the proposed final draft state
EJBs in a nutshell
Combination of transaction-processing monitors and distributed object services. Server-side component model Provides a simple programming model, the developers can focus on the business purpose. Platform independent, allows objects to be run in different EJB containers
19.2.2003
Tuomas Mikkola
19.2.2003
Tuomas Mikkola
EJBs in a nutshell
Provides an environment for simplifying complex aspects of enterprise computing :
Object broking Transaction management Security Persistence Concurrency
EJBs in a nutshell
When an EJB is installed in an EJB server, it automatically becomes
Transactional
EJB services can run inside of a distributed transaction, and can be committed or rolled back.
Thread-safe
Many services can be executed at the same time by different clients.
19.2.2003
Tuomas Mikkola
19.2.2003
Tuomas Mikkola
EJBs in a nutshell
Secure
Authentication Authorization Secure communication
Written by SUN with Oracle, IBM, BEA... Specifies the interface between:
A client and an EJB An EJB and the EJB container
Persistent
The Entity EJB may come from a database or another application. EJB server automatically adds persistence to EJB.... ... or the persistence can be directly managed by the EJB through JDBC
19.2.2003
Tuomas Mikkola
19.2.2003
Tuomas Mikkola
10
J2EE
Enterprise JavaBeans (EJB) Java Naming and Directory Interface (JNDI) JDBC data access API Java Servlets JavaServer Pages (JSP) Java Transaction API (JTA) Java Transaction Service (JTS) Java Messaging Service (JMS) Remote Method Invocation (RMI) CORBA
Tuomas Mikkola 11
Terms
Enterprise JavaBeans (EJB) is an architecture for component based distributed computing Enterprise Beans (EB) are components of distributed transaction-oriented enterprise applications
19.2.2003
19.2.2003
Tuomas Mikkola
12
Application Logic
Data
As an Application Server
Application Server
19.2.2003
Tuomas Mikkola
13
19.2.2003
Tuomas Mikkola
14
A container
Intercepts communication between the client and the component to allow automation of infrastructure code Communicates with the component using direct function calls. The container controls the component
19.2.2003 Tuomas Mikkola 15
Client
stub
Server
network
Server-Side Component
business logic implementation
19.2.2003
Tuomas Mikkola
16
Application Assembler
Composes the application from EJB JARs and other non-bean applications, for example applets or servlets. Provides an EAR package
19.2.2003
Tuomas Mikkola
17
19.2.2003
Tuomas Mikkola
18
System Administrator
Configuration and administration Runtime monitoring of the deployed applications
These two are typically same vendors (IBM, BEA, Oracle etc.)
The usage of MBeans can change this.
19.2.2003
Tuomas Mikkola
19
19.2.2003
Tuomas Mikkola
20
EJB Types
Three types of EJB components:
Entity EJB: persistent and shared. Typically a business object Session EJB: manages a client session Message-Driven EJB: Acts as a listener for the Java Message Service API, processing messages asynchronously.
Session Beans
Session EJB is responsible for managing processes or tasks A Session EJB is an extension of the client code on the server side An EJB server can manage many Session EJB simultaneously. Two types of session beans : stateful and stateless
19.2.2003
Tuomas Mikkola
21
19.2.2003
Tuomas Mikkola
22
Stateless - Stateful
A stateless Session EJB doesnt store any information relative to the sessions state. A stateful EJB stores conversational information, i.e. dependent of the session state (conversational state)
Entity Beans
Entity lifetime in not dependent on the client connection Persistent: stored in a database or come from another source. Shared data between clients. An EJB server cached entity objects in memory The EJB client may be another EJB Entity Persistence can be managed:
By the EJB itself through JDBC Automatically by the EJB container
19.2.2003
Tuomas Mikkola
23
19.2.2003
Tuomas Mikkola
24
Parts of EJB
EJB Container
Home Interface
Definition of the creation method
Home Interface
Home Interface
EJB Home
Remote Interface
EJB Client
EJB Object
Bean instance
Interface to factory class (EJB Home), which creates new instances, find existing and destroying
19.2.2003 Tuomas Mikkola 26
19.2.2003
Tuomas Mikkola
25
19.2.2003
Tuomas Mikkola
28
Remote Interface
Defines Business Interface
Remote Interface
{{
EJB Object
}}
19.2.2003
Tuomas Mikkola
29
19.2.2003
Tuomas Mikkola
30
Remote Interface
Must follow a naming convention public interface <BeanName> extends javax.ejb.EJBObject { public <rmiRV> <businessMethod> (<rmiParams>) throws [<businessException>,...] javax.rmi.RemoteException ; } Must extend the javax.ejb.EJBObject interface (if using remote interfaces) Must define the signature of all business methods All business methods must have the specified throws clause
May include business exceptions Must include RemoteException
{{
}}
19.2.2003
Local Interfaces
New concept added to EJB 2.0 specification Local interfaces are used for communicating with beans efficiently inside same JVM.
This means that the local interfaces can be used for example in a servlet running in the same JVM.
Calls to local interface do not involve RMI Beans can provide either local or remote interface, or both of them Taken in to use by adding interfaces implementing EJBLocalObject (local interface) and EJBLocalHome (local home interface)
19.2.2003 Tuomas Mikkola 33