Enterprise Java Beans - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Enterprise Java Beans

Description:

Provides the environment for executing J2EE application clients. ... The EJB standard is part of the J2EE architecture for distributed systems ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 21
Provided by: alanoca
Category:
Tags: beans | enterprise | j2ee | java

less

Transcript and Presenter's Notes

Title: Enterprise Java Beans


1
Enterprise Java Beans
  • CSCI3007 Component Based Development
  • downloadable .PDF file

2
Enterprise Java Beans
  • Enterprise Java Beans (EJBs) are part of the Java
    2 Enterprise Edition (J2EE) standard
  • Enterprise beans are components that are part of
    a distributed, transaction-oriented enterprise
    application.
  • EJBs have the following characteristics
  • They depend on a container environment to supply
    life-cycle services
  • They contain business logic that operates on the
    enterprises data
  • They can be customized at deployment time by
    editing an XML-based deployment descriptor

3
J2EE Programming Environments (1)
  • The J2EE Platform consists of four programming
    environments
  • The EJB container
  • Provides the environment for the development,
    deployment and runtime management for enterprise
    beans.
  • The Web Container
  • Provides the environment for the development,
    deployment and runtime management of servlets and
    Java Server Pages (JSP). The servlets and JSP are
    grouped into deployable units called Web
    Applications. A web application encapsulates the
    presentation logic of an enterprise application.

4
J2EE Programming Environments (2)
  • The Application-Client Container
  • Provides the environment for executing J2EE
    application clients. The environment is
    essentially J2SE
  • The Applet Container
  • Provides the environment for executing Java
    applets. This environment is typically embedded
    in a Web browser

5
J2EE Application Programming Model
Web Container
EJB Container
Enterprise Java Bean
Database
Web Application
Browser
Web Service
Business Logic
6
EJB Architecture Roles
  • Bean developer
  • Develops the enterprise bean component
  • Application assembler
  • Composes the enterprise bean component into
    larger, deployable units
  • Deployer
  • Deploys the application within a particular
    environment
  • System Administrator
  • Configures and administers the enterprise network
    and infrastructure
  • EJB Container Provider
  • Usually vendor-provided
  • EJB Server Provider
  • Usually vendor-provided

7
EJB Types
  • Starting with the EJB 2.0 Specification there are
    three types of enterprise beans
  • Entity bean
  • Often suggested as an equivalent to a row in a
    database
  • Session bean
  • Typically represents business logic
  • Message-driven bean
  • Used to handle Java Message Service (JMS)
    messages asynchronously
  • New to EJB 2.0 specification

8
Choosing Between Entity Beans and Session Beans
  • Guidelines
  • Business entities are typically implemented as an
    entity bean or a dependent object of an entity
    bean
  • Conversational business logic is usually
    implemented as a session bean
  • Collaborative business processes (those with
    multiple actors) are implemented as entity beans
  • If an intermediate state of a process needs to be
    saved then the process is implemented as an
    entity bean

9
Session Beans v Entity Beans (1)
10
Session Beans v Entity Beans (2)
11
The Structure of Entity Beans
  • Each entity bean consists of the following parts
  • The enterprise bean class
  • A Java class that implements the methods and the
    enterprise bean object lifecycle methods. The
    enterprise bean class may use other helper
    classes to implement the business methods
  • The enterprise bean client-view API
  • consists of two interfaces
  • The home interface
  • The remote interface
  • The deployment descriptor
  • An XML document that contains declarative
    information about the enterprise bean

12
The Home Interface
  • The enterprise bean home interface controls the
    life cycle of the enterprise bean objects.
  • Defines the methods
  • create ( )
  • find ( )
  • Returns the Remote Interface or a collection of
    such interfaces
  • NB session beans do not have find( ) methods
  • remove ( )
  • Inherited from EJBHomeInterface

13
The Remote Interface
  • The enterprise bean remote interface defines the
    business methods that a client can invoke on
    individual enterprise bean objects

14
The Structure of EJBs
15
Session Beans
  • A session object lasts for the duration of a
    clients session
  • A session is defined as the time between the
    creation of a session bean and its removal
  • During that time the session bean stores the
    state information for the client
  • A session bean typically implements a process
    performed from start to finish by a single actor
    in a single session
  • The scope of this is called a conversation

16
Stateful session beans
  • Session objects can be designed to be stateful or
    stateless
  • An instance of a stateful bean is associated with
    one client
  • There is a oneone correspondence between session
    objects and the (stateful) instances of the
    session bean class
  • The container always delegates requests from a
    given client to the same session bean instance

17
Stateless session beans
  • Stateless session objects do not retain any
    client-specific state between invocations
  • The EJB container maintains a pool of instances
    of the session bean class
  • Delegates clients requests to any available
    instance
  • Typically implements a procedural service on top
    of a database or legacy application

18
Stateful v Stateless Session Beans
EJB container
inst1EnrollmentBean
obj1EnrollmentRMI
client1
Stateful session bean always delegates to same
instance
client2
inst2EnrollmentBean
obj2EnrollmentRMI
obj3EnrollmentRMI
inst3EnrollmentBean
client3
EJB container
client1
Stateless session bean delegates to any
available instance
inst1PayrollBean
objPayrollRMI
client2
inst2PayrollBean
client3
19
Message-Driven Beans
  • Message-Driven Beans are new
  • Previously JMS messages were handled outside of
    the container by Java programs
  • Message-Driven Beans are anonymous
  • Offer no home interface or remote interface
  • Clients deliver messages to a JMS destination (a
    queue or a topic) and the container passes it a
    message-driven bean object that has registered as
    a listener for that destination
  • Message-Driven beans are stateless

20
Summary
  • The EJB standard is part of the J2EE architecture
    for distributed systems
  • At its centre is the specification of enterprise
    beans
  • Entity beans
  • Offer two interfaces home and remote
  • Session beans
  • Can be stateful or stateless
  • Message-driven beans
Write a Comment
User Comments (0)
About PowerShow.com