Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

29
Enterprise Java Bean Matt

Transcript of Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

Page 1: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

Enterprise Java Bean

Matt

Page 2: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

2

J2EE

Page 3: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

3

J2EE Overview

Page 4: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

4

J2EE 1.4 API

Page 5: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

5

Distributable Components • Components should provide services to clients running locally or remotely

• SelfContained Components Components should only contain the code necessary to implement their services Infrastructure services should be injected by the execution environment

• Standard infrastructure services include Directory Services Distributed transaction management Security management Concurrent access management Persistence management Resource pooling (e.g. DB connections) Administration interface Load Balancing Fault tolerance

An application server provides the infrastructure and services to run components/applications An application server provides the infrastructure and services to run components/applications

Page 6: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

6

Object Pooling • An application server may create a pool of bare obj

ects that may be used as EJBs when requests are made

Page 7: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

7

Container

• A Container provides the environment in which a bean executes generates Home Object generates EJB Object manages individual bean instances

Page 8: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

8

EJB

Page 9: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

9

EJB• Enterprise Java Bean包括了

Session Bean: Session beans are essentially service providers Stateless Stateful

Entity Bean: Entity beans are used to represent data in a database. BMP CMP

Message-Driven Bean: Message driven beans are capable of responding to JMS messages

Page 10: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

10

EJB Overview

• EJB simplified distributed developmentDevelop EJB implementation logic Define Home/Local Remote/Local interfaces Container delegates client calls Container manages resources/lifecycle/callbacks

Page 11: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

11

EJB

Page 12: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

12

EJB Design Approaches • Remote interface• Home interface• Bean class

Page 13: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

13

EJB Architecture

Page 14: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

14

EJB Flow Chart

Page 15: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

15

Client View of EJB

Page 16: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

16

EJB• EJB clients

utilizes the Java Naming and Directory Interface (JNDI) to look up for the references to home interfaces

use home and remote EJB interfaces to utilize all EJB-based functionality

• EJB Home interface create EJBs remove EJBs find handles to EJB remote interface

objects

• EJB remote interfaces provide business-specific functionalit

y of an EJB are similar to RMI Remote interface

• EJB implementation (Bean Class) business method invocation database loading logic passivation, database storage

Session Context• The Container has already reference

to the bean The bean interacts with the Container through SessionContext and retrieves home interfaces gets and sets transactions attributes obtains security attribute

• The setSessionContext method is used to inform the bean about the session context

Page 17: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

17

Steps to Develop an EJB

Page 18: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

18

Hello World Object Model using RMI

Page 19: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

19

Session Bean

Page 20: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

20

Session EJBs View • Stateless

• Stateful

Page 21: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

21

Life Cycle of Stateless Session Bean

Page 22: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

22

Life Cycle of Stateful Session Bean

Page 23: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

23

Stateful vs Stateless Stateful Bean

• A stateful bean contains a conversational state that is retained across method calls and transactions. The create method takes argumentse.g. create(String id) , create(int I , String id) There can be one or more arguments in a create method

• e.gAn EJB that unzips 100 bytes of data An EJB that checks to see if a stock symbol is valid

Stateless Bean

• A stateless bean does not have any state between calls to its methods The create method does not take argumentse.g create() There can be no arguments in a create method

• e.gAn EJB that books a flight and rents a car at a travel agent’sweb site.

Page 24: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

24

Page 25: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

25

Entity Bean

Page 26: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

26

Page 27: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

27

Message-Driven Bean

Page 28: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

28

Page 29: Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.

29