Sie sind auf Seite 1von 52

p 

   

The Enterprise JavaBeans architecture is a


component architecture for the development and
deployment of object-oriented distributed
enterprise-level applications. Applications written
using the Enterprise JavaBeans architecture is
scalable, transactional and multi-user secure.
These applications may be written once, and
deployed on any server platform that supports the
Enterprise JavaBeans specification
¦  
 
  ¦ 

x 
   x  |
0 
ΠEnterprise JavaBeans is a specification
± (a piece of paper) not a product
± As is XML, CORBA, TCP/IP
ΠEnterprise JavaBeans is Java based
± Defined by Sun Microsystems
± Applications are written in Java
ΠEnterprise JavaBeans is distributed objects
± Similar to CORBA | Java RMI (JRMP) | Microsoft MTS
ΠEnterprise JavaBeans is components
± Similar to regular JavaBeans (similar but not the same)
± Similar to COM/DCOM/COM+
ΠEnterprise JavaBeans products are Transactional
Monitors
± Similar to CICS | TUXEDO
± A complete environment for a distributed object G

   
ΠSimple Programming Model
± Attribute based programming
± Focus on Business Logic
± Simple API
± Well defined Lifecycle
ΠPortable
± Specification ensures basic services
± Component Packaging (JARs and XML DD)
± Java

·
  

ΠWith EJB, you can write a business object


and easily make it
± Persistent
± Distributed
± Transactional
± Secure
± Multithreaded

ü
 

ΠBeans need to load and store data


Πou can let the server do it
± (Container-Managed Persistence)
Πou can do it yourself
± (Bean-Managed Persistence)


 

ΠSupport for distributed transactions


Πou can let the Server manage all
transactions
± ou will if you know what¶s good for you
± ou can give it hints in deployment descriptor

A
¦ 

ΠSSL/RMI protects transmitted data


ΠClient-Server architecture protects
± proprietary code
± backend database
ΠSSL authenicates client, server
ΠACLs provide fine-grained control of access
to objects, methods, services

o
½ 

ΠProgrammer delegates all responsibility for


multithreading to server
± Programmer literally can¶t spawn a thread
ΠProgram designer and/or sysadmin
establishes multithreading policies
ΠServer enforces them invisibly

†
¦ 

ΠJNDI
ΠWrapper for many naming services
± CORBA, RMI, etc.


  ¦  
ΠCORBA: Complex Programming Model
± Different API for each Service
± Explicit use of service APIs
± Lifecycle depends on services used
ΠFairly Portable
± Many Languages, many platforms (pro and con)
± Non-Uniform support of Services

|
  

ΠTransport
± EJB uses RMI interface, RMI uses IIOP
ΠCORBA 3.0 promises object compatibility
with EJB
± Not quite sure what that means
ΠSome EJB Servers contain an ORB
± All EJB Objects are also CORBA objects

||
   

ΠAll EJB Servers use CORBA Transactions


(via JTS)
± That means that any client can make a distributed
transaction that includes both CORBA and EJB
Objects
ΠNot an either-or decision
± ou can have both EJB and CORBA working
together in a single system

|G
p 

ΠEnterprise Java Beans has absolutely nothing to


do with JavaBeans
± Except that both are Java-based component architectures
ΠEJB is server-side, JB is client-side
± EJB has no GUI, JB usually has GUI
ΠJB is basically naming conventions for fully
powered Java classes
ΠEJB rules are much more rigid
ΠEJB classes are less powerful on their own, but
more powerful in a container


  

ΠEJB is all about really poor names


ΠArchitecture makes sense, object names
don¶t
± ³Home´ is a factory
± ³Container´ is a helper or wrapper
± ³EJB Object´ is an object but is not an EJB
± "Enterprise JavaBean" is not a JavaBean


[   
   
ΠLearning curve
Π cost of products
Π cost of extra servers to achieve
performance
Πtime +  cost of maintenance
ΠObject-relational mapping

ΠBasically, app servers are good for large,


general solutions (e.g. multiple data
sources, multiple applications) |
    

]
 
 

Π2   
creates JAR with:
± Remote interface with business functions
± Home for accessing instances of bean
± Bean itself
± Properties and descriptor
Π
integrates beans into clients
Π 
modifies and deploys beans
± Organization-specifics, ie security

|o
 

Œ ¦    provides Server run-time


Π  
provides tools and
containers
± Creates container classes that wrap bean
± Manage installed beans


  
ΠThink of the container as the server, holding
your objects
ΠContainers host enterprise beans
ΠContainers isolate beans from clients
± Intercept client requests
± Set up transactions, security, persistence, etc.
before and after calling EJB methods
± Beans can also call methods of the container
interface to get services
ΠContainers provide JNDI services too
|
G

00 

ΠHome Interface
± Extends javax.ejb.EJBHome
± Provides remote access to create, find, remove beans
ΠRemote Interface
± Extends javax.ejb.EJBObject
± Provides remote access to business methods
ΠBean Class
± Extends a javax.ejb.EnterpriseBean type
± Implements business logic and other functionality

G|
    

Naming Service

Server

Home Interface Container


(Factory)
RMI
Client
RMI
Remote EJB Object
Interface (Wrapper)
ou write this
Enterprise
Java Bean
Implements
(Biz Logic)
Invokes
Creates / uses
GG

  p ! 
ΠRemote Interface
± extend EJBObject interface
± Define business method signatures
ΠHome Interface
± extend EJBHome interface
± Define create signatures
± May define findBy signatures for entities


p ! 

ΠEnterprise Bean Class


± implement EntityBean or SessionBean
± Implement business method signatures
± Does not need to implement Remote Interface
± not abstract
± Implement ejbCreate methods matching Home
create
Π ejbCreate for every Home.create
Œ N.B.: ³create´ in home interface, ³ejbCreate´ in Bean


0 

› 

  
› 
 ›
   ›

 ››        

 › a      ›


 ››      
   ›
 › a 
    ›
 ›› 

  
   ›

G
U0 

› 

! 
› 

   ›
› 

"›   ›
› 
 ›
   ›

 ››   !    ! 

 ›   #$ %   &


   ›'   ›

 › ›()› (* (#$ %   &


   ›'"›   ›

 ›  ››(+› #›,› &


   ›'"›   ›
GA


›    ›  

›     ›    ›  





  
 ›  › 

›  a  


  

› ›      
   

› 
a 

 


› ›  

 

 

Go



  
ΠEntity Beans
± Represent data in the database
± Include behavior (business methods)
ΠSession Beans
± Represent tasks or processes
± Do not represent data, but can access data
± Manage the interactions of other beans


U0 

ΠDefined by Bean developer


ΠImplemented by server tools
(autogenerated)
ΠMust extend interface EJBHome
± EJBMetaData getEJBMetaData()
± void remove(Handle ejbHandle)
± void remove(Object primaryKey)
ΠMust provide your own create() methods
± Foo create()
± Foo create(Bar b, Baz z)«
G
U0  

ΠEntity Beans are persistent, therefore they


need more than a ³create´ method
ΠNeed findXXX methods
± public Foo findByPrimaryKey(Object key);
± public Foo findByBar(Bar bar);
± public Enumeration findOverdrawnAccounts();
ΠImplement ejbFindXXX methods in bean
± N.B.: ³find´ in home interface, ³ejbFind´ in Bean

·
0 

ΠWritten by developer
ΠDefines methods accessible by client
± our business methods go here
Πextends javax.ejb.EJBObject
± standard methods provided by all EJBs
± getEJBHome(), getPrimaryKey(), getHandle(),
remove(), isIdentical(EJBObject obj)

·|
0   " 

ΠDeveloper writes Remote Interface
ΠTool uses RI to automatically generate the
EJBObject class
ΠDeveloper writes the EJB source file
ΠN.B.: The EJB does  implement the Remote
Interface
± However, you still must implement all the business
methods
± Lame-o-rama: no type safety provided by compiler
± Better: if EJB tool auto-created a new interface for the
EJBObject (oh well)
·G
0
 

ΠImplements all your business methods


ΠMust also implement
± ejbCreate() methods
± ejbFind() methods (for Entity Beans)
ΠAlso callback methods
± ejbRemove()
± ejbActivate()
± ejbPassivate()
ΠImplement which interface?
± javax.ejb.SessionBean
± javax.ejb.EntityBean
··
0 0


  
 
     
a      

÷ 
÷ 
a  
  
a 
  
  
a   
   
   

   
 
  
  
a    
a    

·ü
 

]
 
 
ΠContainer-Managed Persistence
± Server reads values from your bean
± Server stores/loads data for you
± Very easy to write - just define data and server
magically takes care of persistence

·A
 ½ 
½
ΠPersistence is automatic
± inserts, updates, and deletes are automatic
± transactions managed automatically
± server reads/writes your bean instance variables
± Server also informs you before/after it's done
something
Πyou implement callback methods

·o
 ½ 
½
ΠEasier to write beans
± Focus on business logic, not persistence
± But, requires sophisticated, vendor-specific data
mapping tools
ΠComponents more portable
± not backend-specific
± shrink-wrapped components

·†
½ 
ΠBean-Managed Persistence
± ou code access database directly
± Callback methods dictate when to insert, update,
delete
ΠMore control over persistence, performance
ΠMuch harder to write
Œ Don¶t need sophisticated data mapping
tools

·
 
ΠModel entities in a system
± represent their data and associated behavior
Πone or many relational database tables
Πan object in an object database
Πan entity in a legacy system
± Nouns: People, Places or Things
ΠCustomer, Employee, Student
ΠCity, Building, Hotel Room
ΠOrder, Organization, Health Benefit

ü
¦ 
ΠNot persistent, but can access database
ΠModel tasks, process or agents
± Charge a credit card
± Process a stock purchase
± Perform hotel reservations
ΠManage interactions of other beans

ü|
¦¦ 
ΠPerform transitive tasks
ΠIndependent business methods
± Act on method arguments, not bean state
± Similar to procedures in traditional TPM systems
ΠMost performant bean type
ΠNot dedicated to one client

üG
¦ ¦ 
ΠAct on behalf of one client
± Extension of the client
± Agent that performs work for the client
ΠInterdependent business methods
± Bean has conversational state
± Method depend on conversational state
ΠDedicated to exactly one client

ü·
 [


]
 
Î [

[ 

ΠDescribe bean(s) to the container
± interfaces and class
± type of bean (entity or session)
± identify primary key & container-managed fields
ΠDeclare runtime behavior
± transaction attributes of methods
± authorization access to method
± persistence type (BMP vs. CMP)
ΠWritten in XML

ü
 

]
 

 
ΠEnterprise beans
ΠJ2EE Application Components
ΠJava Applications
ΠJava Applets
ΠServlets
ΠJSP

üo
#
 $




   
  !

"" ›  !   


! ›  # $%  " " " $

""    &'(# 


""  ›  
 )  *     + !,
   

""-   ›  !   


"" +›  !    
        ('

""- ›      


     

ü†
½ 
ΠNew with EJB 2.0
ΠUse JMS for asynchronous message queue
services
ΠAllows asynchronous response
± I will gladly pay you Tuesday for a hamburger
today
± Get some of the missing Thread functionality back
ΠNot completely supported yet
± Must sit on a message queue product

ü
± "
ΠFact:
± EJBs are RMI remote objects
ΠProblem:
± Calling each setter or getter goes across the network
± Slow if you're accessing more than one value at once
ΠSolution:
± Value object which mimics the EJB, only it isn't remote
± EJB has methods to get and set value object
± Client sets/gets values locally, sends/receives  


 
ΠjGuru EJB FAQ
± http://www.jguru.com/faq/EJB
ΠSun EJB Page
± http://java.sun.com/products/EJB
ΠEJBNow
± http://www.ejbnow.com/

|
 %
ΠRichard Monson-Haefel
ΠDave Orchard
ΠRandom Walk Computing

G

Das könnte Ihnen auch gefallen