EJB Session Beans - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

EJB Session Beans

Description:

... directory service and DNS to locate network ... Use JNDI to lookup and find reference to object 'Create' a client ... initialContext.lookup(jndiName ) ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 17
Provided by: evon1
Category:
Tags: ejb | beans | dns | lookup | session

less

Transcript and Presenter's Notes

Title: EJB Session Beans


1
EJB Session Beans
  • Controlling your application
  • (the business logic)

2
What you need to know
  • Advantage of using Session EJBs
  • Guidelines for their use
  • Know the Session EJB pattern
  • Define and describe the role of a Java Interface
    class
  • Stateful vs. stateless EJBs
  • Passivation vs. activation
  • Remote vs. local interface
  • Bean vs. container managed Session EJBs
  • Naming directory services and JNDI
  • Algorithm for using Session EJBs
  • Develop an application using Session EJBs and
    describe the function of each statement in the
    program.

3
Advantages
  • Automatic Transaction management
  • Resource management
  • Security

4
Basic EJB Pattern
ltltEJBgtgt
Bean(Implementation)
Implementation
Client Interface
5
Full Internal View
ltltEJB Session BeangtgtOrderControl
Client Interface
Implementation
6
Remote vs. Local Entity Beans
  • Remote Session EJB
  • Anywhere on the network
  • Pass by value
  • Local EJB are faster but not as flexible,
    scalable and adaptable
  • On same server as Session Beans
  • No network traffic
  • Pass by reference

7
Stateful vs. Stateless Transactions
  • A stateless transactions is
  • Usually a one step transaction
  • Does not the save transaction state data
  • No memory is allocated in the pool for each
    session with a client
  • EJB is never passivated or activated
  • Stateful transaction
  • Used for multi-step transactions
  • Saves state data for each client session
  • Memory is allocated in pool for each client
    session
  • EJB is passivated and activated

8
Stateless Session Bean LifeCycle
Does not exist
Class.newInstance(), _at_PostConstruct
Ready in pool
Business method
9
Stateful EJB Session Bean Lifecycle
10
Locating an EJB
  • EJBs can be remote anywhere on the network
  • Must use a directory service and DNS to locate
    network objects
  • JNDI (Java Naming Directory Interface)
  • Programming interface to the directory services
    to locate any object in a network (files, EJBs,
    web services, etc.)

11
Directory Service names
  • Most use X.500 naming standard
  • c (country name)
  • o (organizationName)
  • ou (organizationUnitName)
  • l (localityName)
  • cn (commonName)
  • dc (domainComponent)
  • uid (userid)
  • Each type of directory service has its own
    naming syntax
  • LDAP example
  • cnMartin Bond, ouAuthors, oSAMS, cus
  • Microsoft Active Directory Service
  • cnMartin Bond/ouAuthors/oSAMS/cus

12
JNDI names
  • JNDI names are not specific to directory services
  • JNDI maps universal name to specific directory
    service syntax
  • Typical JNDI name
  • SAMS/authors/Martin Bond

13
Guidelines for use
  • Coarse-Grained better than Finely-Grained
  • Use stateless whenever possible
  • Use the remote interface for flexibility

14
Outline for using remote EJBs
  • Get initial naming context for EJB
  • Use JNDI to lookup and find reference to object
  • Create a client session for the EJB
  • (returns remote interface)
  • Call business methods defined in the remote
    interface

15
Locate a Remote Session EJB
try InitialContext initialContext new
InitialContext() // get jndi context String
jndiName BusinessRulesBean.RemoteJNDIName //
get jndi name // lookup and get remote
interface for session bean
BusinessRulesRemote businessRulesRemote
(BusinessRulesRemote)
initialContext.lookup(jndiName )
catch (NamingException ne) throw new
MyAppException(ne.getMessage())
16
Calling business methods
try InitialContext initialContext new
InitialContext() // get jndi context String
jndiName BusinessRulesBean.RemoteJNDIName //
get jndi name // lookup and get remote
interface for session bean
BusinessRulesRemote businessRulesRemote
(BusinessRulesRemote)
initialContext.lookup(jndiName ) // call
any business methods defined in the interface
Person person businessRulesRemote.login(usernam
e, password) catch (Exception ne)
throw new MyAppException(ne.getMessage())
Write a Comment
User Comments (0)
About PowerShow.com