Dia 1 - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Dia 1

Description:

By using EJB, you can write scalable, reliable, and secure ... Perfecting EJB 1.0. Major improvement of Entity-beans. Message driven beans. Webservice support ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 56
Provided by: geertd9
Category:
Tags: dia | perfecting

less

Transcript and Presenter's Notes

Title: Dia 1


1
(No Transcript)
2
Enterprise JavaBeansIntroduction
  • Geert De Maere
  • GDM AT cs.Nott.ac.UK

3
Course overview
  • Introduction
  • EJBs
  • Session beans
  • Stateless
  • Stateful
  • Entity beans
  • BMP Bean managed persistence
  • CMP Container managed persistence
  • Exercises (Ecommerce application)
  • Best practices

4
Todays overview
  • J2EE overview
  • Enterprise applications?
  • Component models
  • EJB components
  • Developing EJBs
  • Session beans

5
EJB appetizer
Enterprise JavaBeans is a server-side component
architecture that simplifies the process of
building enterprise-class distributed component
applications in Java. By using EJB, you can write
scalable, reliable, and secure applications
without writing your own complex distributed
component framework. EJB is about rapid
application development for server side you can
quickly and easily construct server-side
components in Java by leveraging a prewritten
distributed infrastructure provided by the
industry. EJB is designed to support application
portability and reusability across any vendors
enterprise middleware services. From Mastering
Enterprise Javabeans
6
Introduction to J2EE
7
Platform overview
  • Java 2 Platform, Micro Edition (J2ME)
  • Java applications for micro-devices
  • Java 2 Platform, Standard Edition (J2SE)
  • applets
  • standalone applications
  • Java 2 Platform, Enterprise Edition (J2EE)
  • enterprise applications

Specifications!!!
8
J2EE platform
  • J2EE contains
  • Specifications
  • Test suite
  • Blueprints (describes function of the APIs)
  • Reference implementation
  • Provides middleware services

9
J2EE APIs
  • Enterprise JavaBeans (EJBs)
  • Remote method invocation (RMI)
  • Java Naming and Directory Interface (JNDI)
  • Java Database Connectivity (JDBC)
  • Java Transaction API (JTA)
  • Java Messaging Service (JMS)
  • Java Servlets
  • Java Server Pages (JSPs)
  • Java IDL
  • JavaMail
  • J2EE Connector Architecture (JCA)
  • Java API for XML Parsing (JAXP)
  • Java Authentication and Authorisation Service
    (JAAS)

Generic APIs
10
J2EE architecture
Browsers
Applications
Others
Java Packages
Swing
EnterpriseBeans
JavaServerPages
JDBC
Others
Java Virtual Machine
Windows, Solaris, Linux, others...
11
Enterprise applications
12
Enterprise applications
GUI
GUI
GUI
BusinessLogic
GUI Logic
Presentation Logic
GUI BusinessLogic Data access
Data access
Data access
BusinessLogic
BusinessLogic
Data access
Distributed
13
Enterprise applications
Client
Client
Client
Server
Server
Back-end
14
Enterprise applications, multi-tier
Web services
Application
Browser
Client tier
SOAP, UDDI, WSDL,
IIOP
HTTP
Application logic
Business tier
Presentation Logic
Business Logic
Database
Filesystem
XML Documents
Data tier
15
Enterprise applications, multi-tier
  • Tree logical layers
  • Client tier
  • Business tier
  • Data tier
  • More flexible design
  • UI is independent from application logic

16
Enterprise applications, demands
  • Demands
  • Resource pooling
  • Transactions
  • Back-end integration, persistence
  • Security
  • Reliable
  • Scalable
  • Load balancing
  • Transparent fail-over
  • Clustering
  • Dynamic redeployment
  • Caching
  • Low complexity
  • Fast development, Low TTM

J2EE allows you to buy middleware services
17
Component models
18
Component model
Container
Interface between component and container is
specifiedin component architecture!
  • A component model defines a set of contracts
    between the component developer and the system
    that hosts the component (container). The
    contract expresses how a component should be
    developed and packaged
  • A component is an independent piece of software
    that can be distributed and used in other
    applications
  • A container is a managed environment

19
Component model
Application server
Container
Client
Component
JRMP, IIOP, HTTP SSL, SOAP HTTP,
Container and application server provide low
level services (example CD)
20
J2EE components, containers
  • Components
  • Client components (apps, applets, web clients)
  • Web components (servlets, jsp)
  • Business components (EJBs)
  • Containers
  • Application client container
  • Applet container
  • Web container
  • Enterprise JavaBean container

21
EJB components
22
EJB History
J2EE
DNA
CORBA
EJB 1.0
EJB 1.1
Perfecting EJB 1.0
  • Major improvement of Entity-beans
  • Message driven beans

EJB 2.0
EJB 2.1
  • Webservice support

EJB 3.0
23
Request interception
Application server
Vendor specific implementation
24
Container services
  • Resource management
  • Instance pooling (similar to connection pooling)
  • Activation
  • Primary services
  • Concurrency
  • Transaction management
  • Persistence
  • Distributed objects
  • Naming
  • Security

Managed by the EJB container!
25
Resource management, instance pooling
26
Resource management, instance pooling
Appl. 1
Appl. 2
Appl. 3
Appl. 4
Appl. 5
Appl. 6
Appl. 7
Appl. 8
DB
27
Resource management, activation
  • Used for stateful session beans (conversational
    state)
  • Mechanism
  • Passivation serialize beans state in secondary
    storage
  • Remove bean from memory
  • ActivationRestoring the beans state

28
Resource management, activation
EJB Container
Client
Passivation
FS
Bean
EJB Container
Client
Clear memory
FS
EJB Container
Client
Activation
FS
Bean
29
Primary services, distributed objects
  • Location transparency
  • RMI-IIOP (Other protocols are possible JRMP,
    SOAP)
  • Client view remote interface

30
Primary services, concurrency
Client
EJB Container
Bean
Client
Bean instance does not allow concurrent access!
Only one client thread is executed at a
time! Beans are single threaded!
31
Primary services, transaction
  • Unit-of-work
  • Types
  • Flat transactions (example order book)
  • Nested transactions (example book trip)
  • EJB container supports declarative transaction
    support!

32
Primary services, data persistence
  • Container synchronizes beans state with database
  • BMP
  • CMP
  • Vendor specific implementation, based on callback
    methods
  • Uses
  • JDBC (generic API)
  • EJB QL
  • Mappings
  • Relational
  • Objects
  • Legacy systems (mainly BMP)

33
Primary services, naming
  • Lookup service, locating distributed objects,
    resources
  • Fundamentals
  • Binding
  • Lookup
  • Java Naming and Directory Interface
    JNDI(generic API)
  • Most platforms support Corba naming service

34
Primary services, security
  • Types
  • Authentication
  • Access control
  • Secure communication
  • Security roles are mapped to real-world
    user-groups
  • Security identity is propagated

35
Benefits of EJBs
  • Simplified, and rapid development of distributed
    applications
  • EJB container provides system-level service
  • Supports multi-tiered development
  • Widely used technology
  • Portability
  • Any operating system
  • Any application server
  • Reusability

36
When to use EJBs
  • The application must be scalable (clustering)
  • Transaction management is necessary
  • Different clients have to be supported (web, app)

37
Component marketplace
  • Buy components (pricing components)(www.component
    source.com)(www.flashline.com)
  • Assemble application form prewritten components
  • Less in-house experience needed
  • Faster development
  • Lower cost

38
Application servers
39
Application servers
  • Additional Features
  • E-commerce components
  • Load-balancing
  • Transparent fail-over
  • Caching

Over 50 vendors!!!
40
Application servers
41
Application servers
  • Commercial
  • Orion
  • BEA weblogic
  • Pramati Sybase EAServer
  • IBM WebSphere
  • Open Source
  • OpenEJB
  • JOnAS
  • JBoss

42
Session beans
43
Overview
Session Beans
Stateful
Stateless
No conversational state (pooled)
Conversational state (exclusive/client)
Deployment option
Managed by container
44
Developing beans
  • Write the java files
  • Compile the java files
  • Write/generate deployment descriptors
  • Create vendor specific files
  • Create jar-file
  • Deploy jar-file

TOOLS available
45
Parts of an EJB
  • Remote (used for request interception)
  • Remote interface
  • Remote home interface
  • Local (EJB 2.0)(used for request interception)
  • Local interface
  • Local home interface
  • Enterprise bean class
  • Deployment descriptor
  • Vendor specific files

Interfaces
Applies to Session and Entity beans!!!
46
Parts of an EJB
47
EJB request interception
Application server
EJB Container
Client
EJB container middleware
2. Call middleware
1. Client method call
5. Return result
EJB Object Request interception
3. Call bean
4. Return result
Vendor specific implementation
48
EJB request interception
Application server
49
Parts of an EJB
Remotehome interface
Localhome interface
EJB Container
Client
Home Object (factory)
Enterprisebean class
Remote interface
EJB Object Request interception
Local interface
50
EJB remote interface
  • Used by the container for generating the EJB
    Object
  • Defines business methods exposed to remote
    clients
  • Must be written according to the EJB
    specifications
  • Inherits from javax.ejb.EJBObject (which extends
    java.rmi.Remote)
  • Properties
  • Callable from remote JVM
  • Methods must throw RemoteException
  • Method parameters must be RMI-Parameters
  • Primitive
  • Serializable
  • Remote objects

51
EJB remote home interface
  • Used by the container for generating the Home
    Object (EJB object factory)
  • Defines lifecycle methods which can be accessed
    from outside the container
  • Creating EJB objects
  • Destroying EJB objects
  • Finding EJB objects (Entity beans)
  • Must be written according to the EJB
    specifications
  • Inherits from javax.ejb.EJBHome
  • Extends java.rmi.Remote
  • Defines required methods

52
EJB local interface (EJB 2.0)
  • Used by the container for generating the LOCAL
    Object
  • Defines business methods exposed to co-located
    beans
  • Must be written according to the EJB
    specifications
  • Inherits from javax.ejb.EJBLocalObject
  • Properties
  • Increased performance
  • No RMI overhead
  • Call Local object
  • Request middleware services
  • Execute request
  • Parameters are passed by reference
  • Method calls must be performed within the same
    container

53
EJB local home interface (EJB 2.0)
  • Used by the container for generating the LOCAL
    Home Object (EJB object factory)
  • Defines lifecycle methods exposed to co-located
    beans
  • Creating Local EJB objects
  • Destroying Local EJB objects
  • Finding Local EJB objects
  • Must be written according to the EJB
    specifications(Inherits from javax.ejb.EJBLocalHo
    me)
  • Improved performance!

54
Bean class
  • Implements
  • Business methods (Remote/Local interface)
  • Life-cycle methods (Remote/Local home interface)
  • Callback methods (notify container, lifecycle)
  • ejbActivate()
  • ejbPassivate()
  • ejbRemove()
  • setSessionContext(javax.ejb.SessionContext
    sessionContext)
  • Methods must match the signatures defined in
    remote and local interfaces

55
Bean class
//Bean class import javax.ejb. import
java.rmi. public class ExampleBean implements
SessionBean //callback method //life-cycle
methods //Business methods
56
Stateless session bean lifecycle
  • State transitions
  • Create bean instance (1)
  • Class.newInstance()
  • setSessionContext()
  • ejbCreate()
  • Delete bean instance (2)
  • ejbRemove()
  • Garbage collection
  • Business methods (3)

Does not exist
1.
2.
Pooled (method ready)
3.
57
Stateful bean lifecycle
Does not exist
1.
ejbPassivate()
Pooled (method ready)
Passive
ejbActivate()
3.
58
Deployment descriptor
  • File format
  • EJB 1.0 serializable classes
  • EJB 1.1, 2.0 XML
  • Allow us to define runtime properties attributes
  • Similar to property files
  • Used by container tools
  • Important tags
  • ltejb-namegt
  • lthomegt
  • ltremotegt
  • ltejb-classgt

59
Example, HelloWorld(Stateless Session Bean)
60
Example, diagram
ltltinterfacegtgt Remote (java.rmi)
ltltinterfacegtgt Serializable (java.io)
J2EE platform
ltltinterfacegtgt EnterpriseBean (javax.ejb)
EJB distribution
ltltinterfacegtgt EJBObject (javax.ejb)
ltltinterfacegtgt EJBHome (javax.ejb)
ltltinterfacegtgt EJBLocalHome (javax.ejb)
ltltinterfacegtgt SessionBean (javax.ejb)
ltltinterfacegtgt HelloWorld
ltltinterfacegtgt HelloWorld- Home
ltltinterfacegtgt HelloWorld- LocalHome
HelloWorldBean
Write yourself
Remote EJBObject
RemoteEJBHome Obj
Local EJB Home obj
Generated by container tools
61
Example, remote interface
package helloWorld public interface HelloWorld
extends javax.ejb.EJBObject public String
hello() throws java.rmi.RemoteException
62
Example, local interface
package helloWorld import javax.ejb. public
interface HelloWorldLocal extends EJBLocalObject
public String hello()
63
Example, remote home interface
package helloWorld import java.rmi. import
javax.ejb. public interface HelloWorldHome
extends EJBHome public HelloWorld create()
throws RemoteException, CreateException
64
Example, local home interface
package helloWorld import javax.ejb. public
interface HelloWorldLocalHome extends
EJBLocalHome public HelloWorldLocal
create() throws CreateException
65
Example, bean class
package helloWorld import javax.ejb. public
class HelloWorldBean implements SessionBean
private SessionContext ctx public
HelloWorldBean() public String hello()
return "hello world" public void
ejbCreate() throws CreateException public
void ejbActivate() public void
ejbPassivate() public void ejbRemove()
public void setSessionContext(SessionContext sc)
this.ctx sc
66
Naming conventions
  • Access methods (remote/local interface)
  • setltPersistence-fieldgt
  • getltPersistence-fieldgt
  • Files
  • Remote interface ltlogical-object-namegt
  • Remote interface lt logical-object-namegt Home
  • Local interface lt logical-object-namegt Local
  • Local home interface lt logical-object-namegt
    LocalHome
  • Bean class lt logical-object-namegt Bean

67
Example, deployment descriptor
lt?xml version"1.0" encoding"UTF-8"?gt lt!DOCTYPE
ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD
Enterprise JavaBeans 2.0//EN' 'http//java.sun.com
/dtd/ejb-jar_2_0.dtd'gt ltejb-jargt
ltdisplay-namegtHelloWorldEJBlt/display-namegt
ltenterprise-beansgt ltsessiongt
ltdisplay-namegtHelloWorldBeanlt/display-namegt
ltejb-namegtHelloWorldBeanlt/ejb-namegt
lthomegthelloWorld.HelloWorldHomelt/homegt
ltremotegthelloWorld.HelloWorldlt/remotegt
ltlocal-homegthelloWorld.HelloWorldLocalHomelt/local-
omegt ltlocalgthelloWorld.HelloWorldLocallt/loca
lgt ltejb-classgthelloWorld.HelloWorldBeanlt/ejb
-classgt ltsession-typegtStatelesslt/session-typ
egt lt/sessiongt lt/enterprise-beansgt lt/ejb-jargt
68
Example, client
package helloWorld import javax.naming. publi
c class HelloWorldClient public static void
main(String args) try Context ctx
new InitialContext() Object obj
ctx.lookup("ejb/helloWorld")
helloWorld.HelloWorldHome home
(HelloWorldHome) javax.rmi.PortableRemoteObject.na
rrow(obj, helloWorld.HelloWorldHome.class)
HelloWorld helloWorld home.create()
System.out.println(helloWorld.hello())
helloWorld.remove() catch(Exception
e) System.out.println("Exception "
e.getMessage()) e.printStackTrace()

69
EJB ecosystem
Supply tools
Deploy system
Assemble application
Tool Provider
Develop beans
System administrator
Application assembler
Deployer
Supply container
Bean provider
EJB container/server provider
70
Exercise
  • E-commerce

71
Methods
  • getAvailableProducts()(returns a vector of
    products)
  • selectProduct(int productCode)(marks a product
    as selected)
  • getAllSelectedProducts()(returns a vector
    containing the selected products)
  • calculatePrice()(returns the total price of all
    selected products)

72
Documentation
  • Tutorial Sun (http//java.sun.com)
  • Application server reviews
  • http//www.flashline.com/components/appservermatri
    x.jsp
  • http//www2.theserverside.com/reviews/index.jsp
  • Books
  • Enterprise JavaBeans (Oreilly, ISBN
    0-596-00226-2)
  • Mastering EJBs (Wiley, ISBN 0-471-41711-4)

73
Java Rules!!!
Write a Comment
User Comments (0)
About PowerShow.com