Enterprise Java Beans (EJB)

19
Enterprise Java Beans (EJB)

description

Enterprise Java Beans (EJB). Enterprise Java Beans EJB Architecture Types of EJB. Where they fit in a system. Using EJB’s. Clients. Enterprise JavaBeans Architecture. The EJB architecture specifies the responsibilities and interactions among EJB entities. EJB Servers. EJB Containers. - PowerPoint PPT Presentation

Transcript of Enterprise Java Beans (EJB)

Page 1: Enterprise Java Beans  (EJB)

Enterprise Java Beans (EJB)

Page 2: Enterprise Java Beans  (EJB)

• Enterprise Java Beans

• EJB Architecture

• Types of EJB.

Page 3: Enterprise Java Beans  (EJB)

Where they fit in a system

Page 4: Enterprise Java Beans  (EJB)

Using EJB’s

Page 5: Enterprise Java Beans  (EJB)

Enterprise JavaBeans Architecture

The EJB architecture specifies the responsibilities and interactions among EJB entities

EJB Servers

Enterprise Beans EJB Clients

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

EJB Containers

Clients

Page 6: Enterprise Java Beans  (EJB)

EJB ServerEJB Server

EJB Server

The EJB Server provides system services and manages resources

– Process and thread management

– System resources management

– Database connection pooling

– Management API

Provides a Runtime EnvironmentProvides a Runtime Environment

Page 7: Enterprise Java Beans  (EJB)

EJB ServerEJB Server

EJB Container

EJB Container

Hosts the Enterprise JavaBeans Provides services to Enterprise JavaBeans

– Naming

– Life cycle management

– Persistence (state management)

– Transaction Management

– Security

Provides a Run-time Environment for an Enterprise Bean

Provides a Run-time Environment for an Enterprise Bean

Page 8: Enterprise Java Beans  (EJB)

Enterprise Beans A specialized Java class where the real business logic lives

– May be developer-written or tool-generated Distributed over a network Transactional Secure Server vendors provide tools that automatically generate

distribution, transaction and security behavior

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

Page 9: Enterprise Java Beans  (EJB)

EJB Clients

Client access is controlled by the container in which the enterprise Bean is deployed

Clients locates an Enterprise JavaBean through Java Naming and Directory Interface (JNDI)

RMI is the standard method for accessing a bean over a network

EJB ServerEJB Server

EJB Container

Enterprise Bean

Enterprise Bean

Clients

Page 10: Enterprise Java Beans  (EJB)

JavaBeans vs EJB

Enterprise JavaBeans is a framework for building and deploying server-side Java components

JavaBeans is a framework for client-side Java components

Conceptually related because both are components The specifications do not build on each other.

Page 11: Enterprise Java Beans  (EJB)

Three kinds of EJB’s

• Session– associate client information with a specific

client– both stateless and stateful versions

• Entity– groups associated information in an abstraction

that provides transaction support• Message Bean - rarely used, hardly supported

Page 12: Enterprise Java Beans  (EJB)

What is a Session Bean?

• Represents a single Client inside the J2EE server

• one client at a time/ not persistent

• when the client terminates, the session bean is disassociated from the client

• There are two types: Stateful and Stateless...

Page 13: Enterprise Java Beans  (EJB)

Stateful

• These represent a set of interactions between client and server.– Example: shopping cart

• Saves information over several method invocations.

• There is a lot of overhead associated with using stateful beans

Page 14: Enterprise Java Beans  (EJB)

Stateless

• A stateless bean does not save information between method calls.

• Limited application• Little overhead

– multiple clients can use the same bean instance without alteration

• Example: fetch from a read-only database or send a confirmation email for an order

Page 15: Enterprise Java Beans  (EJB)

Entity Beans

• Associates pieces of information in a group

• Accessed by multiple clients at a time

• Persistent and Serializable

• The container loads and stores the entity beans in the database

• These are more similar to regular beans

Page 16: Enterprise Java Beans  (EJB)

Persistence in Entity Beans

• Container Managed Persistence (CMP)– the container controls when the bean is read

from or written to the database• Bean Managed Persistence (BMP)

– the bean’s implementation performs all of the SQL operations that loads, stores, and updates the bean’s data to or from the database.

– Bean is responsible for connection allocation to the database

Page 17: Enterprise Java Beans  (EJB)

Comparing Session and Entity Beans

Mandatory for EJB 1.0 Represents a specific

client(1 instance per client)

Short-lived Transient Can be any Java class May be transactional Business Logic Beans

Optional for EJB 1.0 Represents underlying data

object or context

(clients share instance)

Long-lived Persistent Can be a class that maps to

persistent data (e.g., database)

Always transactional

Beans which represent data

Session BeansSession Beans Entity BeansEntity Beans

Page 18: Enterprise Java Beans  (EJB)

Message Beans

• A message bean is an enterprise bean that allows J2EE applications to process messages asynchronously. It acts as a JMS(Java Messaging Services) message listener, which is similar to an event listener except that it receives messages instead of events.

• Many systems do not yet support JMS, message bean use is currently not widespread

Page 19: Enterprise Java Beans  (EJB)

THANKS