introduction enterprise javabeans - ida.liu.sechrke55/courses/swe/07-ejb.pdf · 5 ejb container ejb...

9

Click here to load reader

Upload: vonhan

Post on 21-Jan-2019

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

1

Enterprise JavaBeans

Jens Gustavsson

Introduction

Enterprise JavaBeans ≠ JavaBeansServer side component architectureSeparation of business logic from middleware services:– networking– transactions– persistence– logging– resource pooling

Introduction

EJB Container / Application server– Manages beans– Provides middleware services

Part of J2EE, standard from SunImplementation by independent tool vendors– IBM, Oracle, BEA, Borland, …– Open source: JBoss (www.jboss.org)

EJB Architecture

Client

EJB

EJB

EJB

EJB

EJB Container

Client

Client Database

Page 2: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

2

Clients

HTML-client EJB

EJB

EJB

EJB

EJB Container

Javaapplication

DatabaseWeb server

Servletor JSP

Implicit Middleware

Explicit middleware (e.g. CORBA) :– Write to API– Difficult to write, maintain and support

Implicit middleware (e.g. EJB)– Write isolated business logic– Declarative middleware service specifications– Middleware services automatically– Limitations by architectural constraints

Distributed Objects

Client

DistributedobjectRemote

interface

Network

Distributed Objects

Client Stub

Skeleton DistributedobjectRemote

interface

Network

Remoteinterface

Page 3: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

3

Distributed Objects

Client Stub

Skeleton Distributedobject

RequestInterceptor

Remoteinterface

Network

Remoteinterface

Remoteinterface

Distributed Objects the EJB way

Client Stub

Skeleton Bean

EJBObject

Remoteinterface

Network

Remoteinterface

Remoteinterface

EJB Container

Enterprise JavaBeans

Client Stub

Skeleton

BeanEJBObject

Network

EJB Container

EJB Home Object

Client Stub

Skeleton

BeanEJBObject

Network

EJBHome

Page 4: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

4

EJB Container

EJB Architecture

ClientBeanEJB

Object

EJBHome

What does an EJB consist of?

Enterprise Bean classSupporting classesEJB ObjectRemote interfaceHome objectDeployment descriptor (XML)Vendor-specific files(Local interface)

EJB-jar file

Deployment

JavaBeans - for developmentEnterprise JavaBeans - for deploymentDeployment descriptor language is a composition languageDeployment in practiceEJB-jar file is verified by containerContainer generates stubs and skeletons

How to find a home object

Java Naming and Directory Interface (JNDI)– Similar to CORBA naming service– Mapping between resource names and physical

locationsNo machine address to home object hard coded– Address to JNDI server is needed

Page 5: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

5

EJB Container

EJB Architecture

ClientBeanEJB

Object

EJBHome

JNDI

12

3

Different kinds of Beans

Session beans– Stateless– Stateful

Entity beansMessage-Driven beans

So, what does the container do?

Generate stubs and skeletonsCreate EJB instances as needed. Pooling instances.Persisting entity beans.Handles security and transactions via EJB object

How can container vendors compete?

Caching strategiesDevelopment tool integrationDatabase access optimizationPerformance

Page 6: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

6

XDoclet

Remote interface, home interface, local interface, local home interface, primary key class, deployment descriptor, vendor specific filesSpecification in comments in Bean class

Demonstration

Our first bean

Local interfaces

When beans calls beans locallyOptimizationCalls by value/reference problem

How is Persistence Achieved?

Bean managed persistenceContainer managed persistence:– Object to relational database mapping (common)– Object databases (uncommon)– Container generates persistence as subclass– EJB-QL, query language

An entity bean should be seen as a view into the database

Page 7: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

7

Façade design pattern for EJB

EJB Container

EntityBean

SessionBean

SessionBean Entity

Bean

EntityBean

Security

Authentication - JAASAuthorizationDeployment descriptor– Roles– Roles and methods

No instance level based security

Demonstration

En entity bean

Message-Driven beans

Don't have home, remote or local interfacesHave a single business method:– onMessage

No static type checkNo return valuesNo exceptionsStateless

Page 8: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

8

Point-to-Point

Queue

Publish - Subscribe

Topic

Why Message-Driven Beans?

PerformanceReliabilitySupport for multiple senders and receiversEasy integration to legacy systems

Final thoughts

Is it object-oriented?– Separation of data and operations (entity beans

and session beans)– No inheritance between beans

Suitable for which tasks?– One architecture. Anomalies if trying to do

anything elseComponent marketplace?– Not today!

Page 9: Introduction Enterprise JavaBeans - ida.liu.sechrke55/courses/SWE/07-ejb.pdf · 5 EJB Container EJB Architecture Client Bean EJB Object EJB Home JNDI 1 2 3 Different kinds of Beans

9

Resources

Szyperski, chapter 14Sun EJB tutorial

http://java.sun.com/j2ee/learning/tutorial/index.html

Ed Roman: Mastering EJBhttp://www.theserverside.com/books/wiley/masteringEJB/index.jsp

JBoss, Open source EJB Containerhttp://www.jboss.org