0% found this document useful (0 votes)
44 views9 pages

Ejb 1

The document discusses Enterprise JavaBeans (EJB), including: - EJB basics, history, types (session, entity, message-driven beans) - The EJB specification and architecture (home and remote interfaces, containers) - Roles in EJB development (provider, assembler, deployer, administrator) - Features provided by EJBs like transactions, security, persistence

Uploaded by

minha10pk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views9 pages

Ejb 1

The document discusses Enterprise JavaBeans (EJB), including: - EJB basics, history, types (session, entity, message-driven beans) - The EJB specification and architecture (home and remote interfaces, containers) - Roles in EJB development (provider, assembler, deployer, administrator) - Features provided by EJBs like transactions, security, persistence

Uploaded by

minha10pk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lectures

19.2

Enterprise JavaBeans
Lecture 1 Tuomas Mikkola Solita Oy

Background EJB basics Session Beans

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

The EJB Specification


EJB is a specification, not a product
Current release is 2.0

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

The EJB specification is based on the Java API:


JNDI - Java Naming and Directory Interface : naming service JTS - Java Transaction Service: transactional service JMS - Java Message Service: messaging service JDBC - Java Database Connectivity: SQL interface

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

J2EE Application Servers


Software system that provides a run-time environment for executing components written in Java Well-written component can be deployed without additional development work in all Java J2EE compliant application servers.
Client
HTML

J2EE Application Servers


As a Web Server

Application Logic

Data

As an Application Server

Application Server

19.2.2003

Tuomas Mikkola

13

19.2.2003

Tuomas Mikkola

14

Components and Containers


A component
Has a separate interface and implementation Is instantiated within a server container

Components and Containers


Component Server and Container
infrastructure implementation

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

Container acts as a distributed object server

Server-Side Component
business logic implementation

19.2.2003

Tuomas Mikkola

16

J2EE Server and Containers

EJB Developer Roles


Enterprise Bean Provider
Provides a JAR package containing all the classes and interfaces required and the deployment descriptor

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

EJB Developer Roles


Deployer
Adapts EJBs to specific operating environment
Modifies environment properties, for example database configuration

EJB Developer Roles


EJB Server Provider
Delivers the server

EJB Container Provider


Deployment Tools Tools for runtime administration

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 Create

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

Home Interface of SessionBean


Must follow a naming convention public interface <BeanName>Home extends javax.ejb.EJBHome { public <BeanName> create () throws javax.ejb.CreateException, javax.rmi.RemoteException ; } Must extend the javax.ejb.EJBHome interface (if using remote interfaces) Must define one parameterless creation method The creation method must return a Remote Object reference It must have the specified << throws >> clause
Tuomas Mikkola 27 19.2.2003

Home Interface of EntityBean


Differences to the home interface of SessionBean : Must define at least one creation method, which may contain parameters Must define method findByPrimaryKey, with parameter of primary key. May contain also other finder methods

19.2.2003

Tuomas Mikkola

28

A Home Interface Sample


import javax.ejb.* ;; import javax.ejb.* import java.rmi.* ;; import java.rmi.* public interface FaqHome public interface FaqHome extends EJBHome extends EJBHome public Faq create () public Faq create () throws CreateException, throws CreateException, RemoteException ;; RemoteException

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

A Remote Interface Sample


import javax.ejb.* ;; import javax.ejb.* import java.rmi.* ;; import java.rmi.* public interface Faq public interface Faq extends EJBObject extends EJBObject public Faq createGroup (String group) public Faq createGroup (String group) throws RemoteException ;; throws RemoteException

{{

}}

Their signature must only use RMI-compliant parameters


Tuomas Mikkola 31 19.2.2003 Tuomas Mikkola 32

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

You might also like