8/9/2019 Complete EJB PPT
1/93
8/9/2019 Complete EJB PPT
2/93
8/9/2019 Complete EJB PPT
3/93
2. About the Author2. About the AuthorKantimahanti.N.%.Prasad
Worked in fortune 100 Corporates in Client Server Technologies.
Specialies in
Architecture! "esigning! "evelop#ent $ %anaging da&'to'da& activities.
(resentl& doing a (h" at )ueens *t&! *.+ in Adaptable Soft,are specific to
Co#ponent Technologies and has a %.-.ACo#puter Applications/ fro# an *.S. *t&.
-usiness do#ain strengths are in nvest#ent banking $ nsurance.
(rocess i#prove#ent strengths are in ' Sig#a and C%%.
is present $ past ,orking e3periences in various global locations are in corporates like
(ra#erica (rudential *.S/! 4 ( %organ Chase! A - 5 A#ro -ank $ S6S.
e ,as a part ti#e visiting facult& in affiliates of S&dne& *niversit&! Australia and All ndia %anage#ent
nstitute teaching .T! (roject %anage#ent $ Statistics. e has given so#e presentations on (roject
%anage#ent and T)% at various venues. e has ,on fe, Talent7STA8 perfor#ance a,ards and pla&s
al#ost all the sports ,hat are under the Sun.
e hails fro# 9iag7 &derabad : ndia. is ;rdpart& tested Te#pera#ent Sorter results are belo,httpsT"?@02B1@;$("?1DB00
httpsT"?@02B121D$("?1;0
f &ou liked his presentation! tell others and if &ou have a co##ent! tell hi#. e can be reached at
+anti.(rasadE(ra#erica.ie or +anti1Edonegal.net
U NEE!
"AI#
TI## U $UIT
8/9/2019 Complete EJB PPT
4/93
;. Thank &ou note;. Thank &ou note
)e 8ishes to than> Pa2l Perrone 7 Pa2lo Merson 9 'amesh +ehra or ma>ing
this t2torial loo> the 8ay it does.
)e 8ishes to than> *oerg M2eller7 M2r2ganandam7 Charles*ohnson 9 ?en2
adi2m 8ho had ol2nteered to do the editing o this presentation.
his %isters
Than% &ou for do'nloadin( m& Presentation
Than% &ou for do'nloadin( m& Presentation
%pecial than>s to all his Managers at Pramerica and Pr2dential #.%.
9 his Co2sinshis +rothersr.'ao 9
(amily
his Parents%A)I%#NA"ANA
A'#NA
&ICAT& T!Copyright 2004 Kanti Prasad All rights reserved
)e 8ishes to than> to Katherine +allantyne7 Choi K8an 8ho ol2nteers to
edit all o his Articles 9 Presentations.
8/9/2019 Complete EJB PPT
5/93
8/9/2019 Complete EJB PPT
6/93
D.D. Co#ponent CharacteristicsCo#ponent Characteristics
Properties 'e2saility
!perations %hareale
&ents istri2tale
eployale %el Containment
%el description
Components Characteristics incl2de
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
7/93
Components sho2ld hae a mechanism or e=porting
.. Co#ponent ( G HCo#ponent ( G H
Properties
!perations
&ents
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
8/93
@. "eplo&able Co#ponents@. "eplo&able Co#ponents
Components are operation independent o
F )ard8are
F The 2nderlying operating system
F Their Application %erer
F The net8or> protocol they 2se
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
9/93
B. 8eusable Co#ponentsB. 8eusable Co#ponents
Component serices can e 2sed as a part o
2siness logic o other components
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
10/93
. Shareable Co#ponents. Shareable Co#ponents
I m2ltiple clients are 2sing a component
sim2ltaneo2sly7 the component 8ill proide
the same 2ality o serice to all the clients
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
11/93
10. "istributable Co#ponents10. "istributable Co#ponents
Components sho2ld proide serices to clients
r2nning locally or remotely
'emote
CI&NT%
&*+ Container
&*+
Possile
'emoteCI&NT%
'emote
CI&NT%
'emote
CI&NT%
ocal
CI&NT%
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
12/93
11. SelfContained Co#ponents11. SelfContained Co#ponents
Components sho2ld only contain the code
necessary to implement their serices
Inrastr2ct2re serices sho2ld e inFected y
the e=ec2tion enironment
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
13/93
12. Standard nfrastructure 5eeds12. Standard nfrastructure 5eeds
%tandard inrastr2ct2re serices incl2de
F irectory %ericesF istri2ted transaction management
F %ec2rity management
F Conc2rrent access management
F Persistence management
F 'eso2rce pooling Ge.g. + connectionsHF Administration interace
F oad +alancing
F (a2lt tolerance
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
14/93
1;. Applicatoin Servers1;. Applicatoin Servers
An application serer proides the inrastr2ct2re and
serices to r2n componentsapplications
*&&
asedsol2tions
NonJ*&&
sol2tions
GP)P7 Cold (2sion7Perl7 etc.H
Microsot %ol2tions
GC!M7 A%P.Net?+.Net7C etc.H
Application %erer prod2cts are mostly
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
15/93
1. Gbject (ooling1. Gbject (ooling
An application serer may create a pool o are oFects
that may e 2sed as &*+s 8hen re2ests are made
App %erer
&*+ Container
CI&NT
Net8or>+
CI&NT&*+
&*+
&*+
&*+
&*+
&*+
Pool
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
16/93
1D. "irector& of Application Servers1D. "irector& of Application Servers
Application %erers proide clients access to sot8are orother applications that r2n only on the serer
&=amples incl2de 8e serers7 eJmail serers and dataase serers
Pop2lar Application %erers areL
F I.+.M. $e %phere
F +&A $e ogic
F %2n *aa %ystem Application %erer :.=
F *oss
The 2ll list 8ith ital statistics are aailale at
httpL888.de=.comenterprisehtml166;
httpL888.Faacommerce.comarticlessererlist.htm
Copyright 2004 Kanti Prasad All rights reserved
http://www.devx.com/enterprise/html/16268http://www.javacommerce.com/articles/serverlist.htmhttp://www.javacommerce.com/articles/serverlist.htmhttp://www.devx.com/enterprise/html/162688/9/2019 Complete EJB PPT
17/93
Container proides %ystem serices li>e
App %erer
CI&NT
Net8or>%T#+
Persistence %ec2rity Connection Pooling ThreadingTransaction
&*+ Container
&*+
(ish cannot s2rie o2tside 8ater 9
&*+s cannot s2rie o2tside containers
Container
intercepts
re2ests
Copyright 2004 Kanti Prasad All rights reserved
Container >no8s 8hat to do7 as yo2 descrie eerything in a special descriptor ile
A Container LF proides the enironment in 8hich a ean e=ec2tes
F generates )ome !Fect
F generates &*+ !Fect
F manages indiid2al ean instances
&*+
&*+
9
)ontainer means a
pre developed *oft'are
To increase capa+ilit&,
clusterin( is ta%en care
+& the vendor
#plicit %iddle,are
gained through declaration
1. Container1. Container
8/9/2019 Complete EJB PPT
18/93
[email protected]@. 42HH Gvervie,42HH Gvervie,
ard,are (latfor#
Gperating S&ste# (latfor#
*&&
Container%erer
!perating %ystem
Independence
)ard8are Independence
Common Programming
%erices
istri2ted Comm2nication
%erices
42SH 8unti#e
42SH Language7nterfaces
services standards co#ponent'based
Hnterprise Co#ponents
Application %erer
Independence
ataase Independence
$e %erer Independence
&nterprise 'eso2rce
Management %erices
"eploent7Configuration
%anage#ent Services
42HH nterfaces
"ata
eploymentescriptors GsH
eployment
escriptors GsH
"eplo&
Tools
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
19/93
*%&
Application Client
Container
+%AA*
*AEJ
'PCC
!
N*ME
*
M
%
$
&
+
%
*
A
E
'
*
+
C
MgmtA!
Client
*%&
%AA*
*AEJ
'PC *T
A
C!
N*ME
Mgmt
*A(
*aa
Mail*
M
%
*
AC
C
$
&+
%
*
AE
'
*
N
I
*
+
C
Applet
Container
*%&
)TTP%
)TTP%
$e Container
*%P %erletApplet
TI&'
3 TI&'
%AA*
*AEJ
'PC *T
A
C!
N*ME
Mgmt
*A(
*aa
Mail*
M
%
*
AC
C
$
&+
%
*
AE
'
*
N
I
*
+
C
&*+ Container
*%&
'MI
II!P
'MI
II!P
4 TI&'
&I%
Main(rames
&*+
*&& deines a model or deeloping m2ltiJtier7 8e ased7
enterprise applications 8ith distri2ted components
1B.1B. 42HH 1. A(s42HH 1. A(s
(or all the APIs reer httpLFaa.s2n.comFee1.4docst2torialdocinde=.html
*%P %erlet &NIN&
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
20/93
8/9/2019 Complete EJB PPT
21/93
8/9/2019 Complete EJB PPT
22/93
21.21. When to use H4-When to use H4-
I any o these re2irements hold or yo2r application
F the application m2st e scalale and distri2taleF Transactions 8ill e re2ired to ens2re data integrity
F the application 8ill hae a ariety o clients
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
23/93
22.22. *aa Naming and*aa Naming and
irectory Interace G*NIHirectory Interace G*NIH*NI
Proides a standardiDed 8ay o accessing reso2rces in a distri2ted
enironment
Protocol and naming serice agnosticF N%
F NI%
F AP
F E.500
Implemented y the Faa=.naming pac>age and three other pac>ageselo8 it
Faa=.naming.InitialConte=t is the entry point to the &*+ %erer
F ind associates a name 8ith an oFect
F loo>2p inds an oFect gien the name
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
24/93
2;. H4- Specification2;. H4- Specification
The &*+ speciication deines interaces et8een
F the &*+ and its containerF the container and the application serer
F the container and the client
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
25/93
2. H4- 8oles2. H4- 8oles
%erice 9 Tool Proider
proides %erer7 Container and integrates 8ith distri2ted acilities
Tools Proider
&*+ Proider
Application Assemler
Application %erer Proider
eployer %ystem Administrator
maintains deployment
s2pplies tools 2ilds application
deelops &*+ss2pplies Application %erer
deploys system
&*+ Proider
creates &*+ components
eployment %pecialistdeploys apps and 2nderstands architect2re iss2es
Application Assemler
assemles apps rom perJ2ilt &*+ comp
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
26/93
2D. H4- "esign Approaches2D. H4- "esign Approaches
&*+ model is ased on three asic design approaches or2ilding distri2ted component systems
%tateless serer approach %essionJoriented approach
Persistent !Fect approach
Copyright 2004 Kanti Prasad All rights reserved
Faa=.eF.&nterprise+ean interace
Faa=.eF.&ntity+ean
The &*+ speciication proides these as%tateless session +eans Message drien eans
%tate2l session +eans &ntity +eans
All &ntity+eans All %ession+eans All Messagerien+eans
e=tends e=tends e=tends
implements implements implementsInterace Interace Interace
e=tends
Faa=.eF.%ession+ean Faa=.eF.Messagerien+ean
Implementing one o these interaces
indicates yo2r *A?A class is an &*+.
It is only a mar>er Interace
and there are no methods to
Implement.
As all these are e=tending the
t8o Interaces hence they hae
the ehaior o oth the Interaces.%erialiDation is the reason
&*+ is distri2tale.
Faa.io.%erialiDale
8/9/2019 Complete EJB PPT
27/93
2.2.H4- ArchitectureH4- Architecture
'MIII!P
%erer A
App %erer
&*+ Container
creates
Naming %erice s2ch
as AP
%erer +
*NI
Initial Conte=t
)
)
1
%&'?IC&%
Naming Transaction Persistence %ec2rity
+
&I%
Main(rames
3
4 5
6
:
;
eletons7 net8or> and so it is aster.
&*+ !Fect or&*+ ocal !Fect
*M% estination
%&%%I!N +&AN% are li>e ?&'+% as they represent action or 2siness process related logic.
8/9/2019 Complete EJB PPT
30/93
2.2. H4- ClientH4- Client
&*+ clients
2tiliDes the *aa Naming and irectory Interace G*NIH to loo> 2p
or the reerences to home interaces
2se home and remote &*+ interaces to 2tiliDe all &*+Jased
2nctionality
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
31/93
;0.;0. H4- o#e nterfaceH4- o#e nterface
&*+ home interaces e=tends Faa=.eF.&*+)ome
&*+ home interaces proide operations or clients toF create &*+sF remoe &*+sF ind handles to &*+ remote interace oFectsF hae its st2 placed into *NI at start2p
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
32/93
8/9/2019 Complete EJB PPT
33/93
;2.;2. H4- #ple#entationH4- #ple#entation
&*+ implementation
Class in 8hich &*+ deeloper codes the 2siness methodsdeined in the eans component interaceGsH to proide any
application speciic
F 2siness method inocation
F creationF remoalF indingF actiationF passiation7 dataase storageF dataase loading logic
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
34/93
;;. Session Conte3t;;. Session Conte3t
The Container has already reerence to the ean
The ean interacts 8ith the Container thro2gh %essionConte=t and
F retriees home interaces
F gets and sets transactions attri2tes
F otains sec2rity attri2te
The set%essionConte=t method is 2sed to inorm the ean
ao2t the session conte=t
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
35/93
;. Stateless Session H4-;. Stateless Session H4-
%tateless session &*+s hae the ollo8ing ehaio2r
F proide a single 2se serice
Fdo not maintain state on ehal o the client
F are relatiely short lied
F do not s2rie &*+ serer crashes
F any t8o instances o the same stateless session &*+
type are al8ays identical
Feach instance can e shared y m2ltiple clients
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
36/93
42HH H4- Container7Server
;D.;D. Stateless Session H4-sStateless Session H4-s9ie,9ie,
&*+ Impl eeloper ?ie8
&*+ gets re2ests and generates responses
An instance can serice m2ltiple clients oer time
&*+ Client eeloper ?ie8
creates it7 2ses it and then its done
&*+ Container ?ie8
can p2ll instances rom pool 2pon client re2est
can shrin>gro8 pool as needed
A e8 pooled eans can serice tho2sands o clients
Client (rocess
H4-
Client 'emote
)ome
Stateless Session
ocal)ome ocalH4- Client
5et,ork
Logic
input
outputH4- (ool
8/9/2019 Complete EJB PPT
37/93
(ool of eJuivalent
#ethod read& instances
ejb8e#ove/
eFCreateGH
-ean nstance
does not e3iistContainer decided it
needs #ore instances
in the pool to service clients
Client called re#ove/
on the H4- object
or the client ti#es out/
Class.ne,nstance/
set%essionConte=tGH
&ach method call is an
inocation rom the
container to the +ean
36. ie Cycle36. ie Cycle oo %tateless %ession%tateless %ession+ean+ean
Transactional
+2siness Method
Client called another
Transactional business #ethod
on the H4- Gbject.
8/9/2019 Complete EJB PPT
38/93
8/9/2019 Complete EJB PPT
39/93
8/9/2019 Complete EJB PPT
40/93
8/9/2019 Complete EJB PPT
41/93
8/9/2019 Complete EJB PPT
42/93
8/9/2019 Complete EJB PPT
43/93
8/9/2019 Complete EJB PPT
44/93
;. Shared Hntit& -ean;. Shared Hntit& -ean
$hen m2ltiple clients share an &ntity &*+ they
F receie their o8n instance
F share the 2nderlying data
F do not hae to handle synchroniDation
App *erver
EJB )ontainer
)#IENT
Net'or%
-B
)#IENTEJB
EJB
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
45/93
8ead&ejbLoad/ ejbStore/
(ooled
(assivates the -ean
ejbCreate/
ejb(ostCreate/
ejb8e#ove/
ejbo#e/ eF(indGH
"oes not e3iistContainer decided it
needs another
Hntit& -ean insinstance
Container decided it
doesnKt need the
Hntit& -ean instance
anore
Client called a finder
%ethod on the ho#e
interface
Client called re#ove/
on the H4- object
this ,ill destro&
"atabase data/
Container deter#ined
that the database is out of
s&nch ,ith the bean. The
-ean needs to store its
"ata into the "atabase
Container deter#inedthat the database is out of
s&nch ,ith the bean. The
-ean needs to load the
ne, "atabase data.
Client called create/ on
the ho#e interface this ,ill
Create ne, database data/
Client called instance
independent ejbo#e/
-usiness #ethod
Activates the -ean
ne,nstance/
setHntit&Conte3t/
unsetHntit&Conte3t/
49% ,ill garbage
collectt and call finalie/
ejbActivate/
ejbLoad/
ejbStore/
ejb(assivate/
&ach method call is an
Inocation rom the
container to the +ean
44. ie Cycle44. ie Cycle oo +MP+MP &ntity +ean&ntity +ean
+2siness Method
Client called a business
#ethod on a H4-Gbject
8/9/2019 Complete EJB PPT
46/93
8/9/2019 Complete EJB PPT
47/93
8/9/2019 Complete EJB PPT
48/93
8/9/2019 Complete EJB PPT
49/93
B. %essage "riven -eanB. %essage "riven -ean
M+ has the ollo8ing ehaio2r
F Is stateless
F is a *M% listener
F 8hen a *M% message arries the method
onMessageGH is e=ec2ted
F does not s2rie &*+ serer crashes
F proides a singleJ2se serice
F is relatiely short liedF is only a ean class no interaces
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
50/93
8/9/2019 Complete EJB PPT
51/93
8/9/2019 Complete EJB PPT
52/93
8/9/2019 Complete EJB PPT
53/93
D2.D2. Gther interfaces and classesGther interfaces and classes
ocal interaces are 2sed or access 8ithin serer conte=t Faa=.eF.&*+ocal)ome
Faa=.eF.&*+ocal!Fect
Interaces or serialiDing &*+ reerences )ome)andle J reerence to &*+)ome
)andle J reerence to &*+!Fect
&*+Metaata interace proides mechanism to gatherinormation ao2t the ean reerence to &*+)ome oFect
)ome7 component interace and primary >ey classes
2nctions to determine ean type
&.g.LFInter component callsF%erlet inocation
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
54/93
8/9/2019 Complete EJB PPT
55/93
8/9/2019 Complete EJB PPT
56/93
8/9/2019 Complete EJB PPT
57/93
8/9/2019 Complete EJB PPT
58/93
D@ ello-ean o#e nterfaceD@ ello-ean o#e nterface
8/9/2019 Complete EJB PPT
59/93
D@. ello-ean o#e nterfaceD@. ello-ean o#e nterface
pac>age e=amples O
import Faa.io.%erialiDaleOimport Faa.rmi.'emote&=ceptionO
import Faa=.eF.Create&=ceptionO
import Faa=.eF.&*+)omeO
p2lic interace )ello)ome e=tends Faa=.eF.&*+)ome
)ello createGH thro8s Faa.rmi.'emote&=ception7
Faa=.eF.Create&=ceptionO
Q
Copyright 2004 Kanti Prasad All rights reserved
8ules of 4ava sa&s package declaration should be at the beginning and ends ,ith a se#i colon
This is the o#e nterface for the o#e H4- ello-ean/.
This #ethod creates7#anufactures the H4-Gbject and returns it . This create/ #ethod corresponds to the
ejbCreate/ #ethod in ello-ean.
5ote n o#e nterface ,e are thro,ing 2 e3ceptions 8e#ote and Create .
NO!E " #ules o$ %nter$aces states that there should e no i&ple&entation so you will $ind only ðod signatures'
Gur interface elloo#e is e3tending H4-o#e #eans it has all the behaviour of H4-o#e
%nter$ace ðods should end with a se&icolon (
H4- H3a#ple reJuire#ent age e=amples O
import Faa.2til.RO
import Faa=.eF.&*+!FectO
import Faa.rmi.'emote&=ceptionO
p2lic interace )ello e=tends Faa=.eF.&*+!Fect
p2lic %tring helloGH thro8s Faa.rmi.'emote&=ceptionO
Q
Copyright 2004 Kanti Prasad All rights reserved
8ules of 4ava sa&s package declaration should be at the beginning and ends ,ith a se#i colon
Clients interact ,ith the H4- Gbject through this 8e#ote interface that is ,h& ,e need to ,rite this interface '
As for ever& nterface ,e need i#ple#entation! so Container ,ill i#ple#ent autogenerate code/ for this 8e#ote nterface for us! ,hich is the H4-Gbject
As our reJuire#ent ,ants a business logic to greet ello World a single #ethod ,ould be sufficient .
As 8e#ote interface is used to interact ,ith the -ean ,e need to #irror all the #ethod signatures ,hat
are there in a -ean class so that is ,h& ,e are ,riting onl& one #ethod in this 8e#ote interface.
5ote H4- specification states that all re#ote calls should thro, 8e#oteH3ception so ,e are thro,ing it.
So lets code the 8e#ote nterface
NO!E " #ules o$ %nter$aces states that there should e no i&ple&entation so you will $ind only ðod signatures'
Gur interface ello is e3tending H4-Gbject #eans it has all the behaviour of H4-Gbject
%nter$ace ðods should end with a se&icolon (
#porting the reJuired files
0 elloLocal nterface0 elloLocal nterface
8/9/2019 Complete EJB PPT
62/93
0. elloLocal nterface0. elloLocal nterface
pac>age e=amples O
import Faa=.eF.&*+ocal!FectO
p2lic interace )elloocal e=tends Faa=.eF.&*+ocal!Fect
p2lic %tring helloGH O
Q
Copyright 2004 Kanti Prasad All rights reserved
8ules of 4ava sa&s package declaration should be at the beginning and ends ,ith a se#i colon
Clients interact ,ith the H4- Gbject through this Local interface ,hen there is no net,ork involved.'
As our reJuire#ent ,ants a business logic to greet ello World a single #ethod ,ould be sufficient .
As Local interface is used to interact ,ith the -ean ,e need to #irror all the #ethod signatures ,hat
are there in a -ean class so that is ,h& ,e are ,riting onl& one #ethod in this Local interface.
5ote As there is no re#ote calls no 8e#ote H3ception is thro,n
NO!E " #ules o$ %nter$aces states that there should e no i&ple&entation so you will $ind only ðod signatures'
Gur interface ello is e3tending H4-LocalGbject #eans it has all the behaviour of H4-LocalGbject
%nter$ace ðods should end with a se&icolon (
As for ever& nterface ,e need i#ple#entation! so Container ,ill i#ple#ent autogenerate code/ for this Localnterface for us! ,hich is the H4- Local Gbject
1 The -ean Class1 The -ean Class
8/9/2019 Complete EJB PPT
63/93
1. The -ean Class1. The -ean Class
pac>age e=amples O
import Faa.2til.RO
import Faa=.eF.RO
p2lic class )ello+ean implements Faa=.eF.%ession+ean
priate %essionConte=t ct=O
p2lic oid eFCreateGH %ystem.o2t.printlnGSeFCreateGHHO Q
p2lic oid eF'emoeGH %ystem.o2t.printlnGSeF'emoeGHHOQ
p2lic oid eFActiateGH %ystem.o2t.printlnGSeFActiateGHHOQ
p2lic oid eFPassiateGH %ystem.o2t.printlnGSeFPassiateGHHO Qp2lic oid set%essionConte=tGFaa=.eF.%essionConte=t ct=H
this.ct= ct=O Q
p2lic %tring helloGH %ystem.o2t.printlnGS)elloGHHO
ret2rn S)ello $orld/ S O Q
Q
Copyright 2004 Kanti Prasad All rights reserved
8ules of 4ava sa&s package declaration should be at the beginning and ends ,ith a se#i colon
This is ,here ,e ,ill code our -usiness logic
5ote < this is a class and not an nterface like the other t,o o#e 7 8e#ote/. This is i#ple#enting Session-ean so it is a Session -ean
This ejbCreate/ corresponds to the o#eobject Create/. 5GTH < in Stateless -ean no argu#ents are sent
So no, lets code the actual H4- Class
As per the belo, note in red ,e need to ,rite all the #ethods ,hat are in java3.ejb.Session-ean .
4ava does not support #ultiple inheritance so &ou can e3tend onl& one class. To overco#e
this the& had given us the #ple#entation option . So ,hen ,e use i#ple#ent ,e need toi#ple#ent or ,rite all the #ethods ,hat are there in the interface ,e i#ple#ented.
5GTH < f it is Hntit& -ean ,e ,ill i#ple#ent java3.ejb.Hntit&-eanand if it is %essage driven bean ,e ,ill i#ple#ent java3.ejb.%essagedriven-ean
These are called
%anage#ent or
Call back #ethods
Gur -usiness #ethod ,hich #atches
our 8e#ote nterface #ethod signature
n Statelss -ean ejbActivate
and ejb(assivate "o not appl&
There is nothing #uch to clean up.
Storing the Conte3t in a variable so that it can be Jueried later .
5GTH < -ecause it is a Session -ean ,e are using setSessionConte3t for Hntit& -ean ,e
use setHntit&Conte3t and for %essage "riven -ean ,e use set%essage"rivenConte3t.
#porting the reJuired files
2 The "eploent descriptor2 The "eploent descriptor
8/9/2019 Complete EJB PPT
64/93
2. The "eploent descriptor2. The "eploent descriptor
U/!CT"P& eFJFar P#+IC SJ%2n Microsystems7 Inc. T &nterprise *aa+eans .0
&N S S httpLFaa.s2n.com.dtdeFJFarVV0.dtdW
UeFJFarW
UenterpriseJeansWUsessionW
UeFJnameW )ello UeFJnameW
UhomeWe=amples.)ello)omeUhomeW
UremoteWe=amples.)elloUremoteW
UlocalJhomeWe=amples.)elloocal)omeUlocalJhomeW
UlocalWe=amples.)elloocalUlocalW UeFJclassWe=amples.)ello+eanUeFJclassW
UsessionJtypeW%tatelessUsessionJtypeW
UtransactionJtypeWContainerUtransactionJtypeW
UsessionW
UenterpriseJeansW
UeFJFarW
Copyright 2004 Kanti Prasad All rights reserved
As a -ean provider ,e need to specif& the %iddle,are needs through this descriptor.
So no, lets co#plete our H4- b& ,riting the deploent descriptor.
O%L Standard reJuire#ent
The nickna#e for this particular -ean
The full& Jualified na#e of the o#e nterface
The full& Jualified na#e of the 8e#ote nterface
The full& Jualified na#e of the Local o#enterfaceThe full& Jualified na#e of the Local nterface
The full& Jualified na#e of the H4- Class
Whether the session bean is stateful or stateless
T)&'& A'& MAN"
T!!% $)IC)
C'&AT&% T)&
&%C'IPT!'
(!' #%
8/9/2019 Complete EJB PPT
65/93
8/9/2019 Complete EJB PPT
66/93
. H4- 4ar Iile. H4- 4ar Iile
Properties
(ile
'emoteocal
Interace
)omeocal)ome
Interace
&nterprise
+ean Class
eployment
escriptor
*ar
Maniest
*ar
ile*ar Creator
&P!"&
Copyright 2004 Kanti Prasad All rights reserved
*ar ile is a .ZIP compression ormat . M&TAJM( ile is a listing ile a2tomatically created y the *ar 2tility.
!r man2ally r2n CL[W*ar c )ello$orld.Far R
The folder structure ,ithin the Hjb'jar file is
%HTA'5I7%A5IHST.%I%HTA'5I7ejb'jar.3#l
e3a#ples7ello-ean.class
e3a#ples7elloLocalo#e.class
e3a#ples7elloLocal.class
e3a#ples7ello.class
Please read the eployment instr2ctions proided y the Application serer as it is ?endor speciic
8/9/2019 Complete EJB PPT
67/93
D. H4- Application Asse#blerD. H4- Application Asse#bler
.*A' .$A'eployment
escriptor
eployment
Tool
&nterpriseArchie
G.&A' (ilesHGApplication.EMH
$&+ A'C)I&?& G.8arH
*%P
%erlets
)TM$&+.EM
*A' A'C )I&?& G.FarH
)!M&&*+
'&M!T&&*+J*A'.EM
Copyright 2004 Kanti Prasad All rights reserved
*ar
ile
8/9/2019 Complete EJB PPT
68/93
Copyright 2004 Kanti Prasad All rights reserved
&EAMP&
%TAT&(# +&AN
8/9/2019 Complete EJB PPT
69/93
Stateful Session 8e#ote nterfaceStateful Session 8e#ote nterface
Copyright 2004 Kanti Prasad All rights reserved
package declaration should be in the beginning
#porting the reJuired classes
There ,ill not be an& i#ple#entation in nterfaces
H4- spec sa&s all re#ote interface #ethods need to thro, re#ote e3ception
Gur bean class Cart-ean #ethods are #irrored here
8e#ote Cart is e3tending H4-Gbject #eans Cart has all the behaviour of it
pac>age samples.eF.state2l.simple.eFO
import Faa.2til.RO
import Faa=.eF.&*+!FectO
import Faa.rmi.'emote&=ceptionO
import samples.eF.state2l.simple.tools.+oo>&=ceptionO
p2lic interace Cart e=tends &*+!Fect
p2lic oid add+oo>G%tring titleH thro8s 'emote&=ceptionO
p2lic oid remoe+oo>G%tring titleH thro8s +oo>&=ception7 'emote&=ceptionO
p2lic ?ector getContentsGH thro8s 'emote&=ceptionO
Q
8/9/2019 Complete EJB PPT
70/93
Stateful Session o#e nterfaceStateful Session o#e nterface
Copyright 2004 Kanti Prasad All rights reserved
package declaration should be in the beginning
#porting the reJuired classes
There ,ill not be an& i#ple#entation in nterfaces
H4- spec sa&s all o#e interface #ethods need to thro, re#ote $ create e3ceptions
n a Stateful -ean &ou can have #ore than one create #ethod taking argu#ents
Carto#e is e3tending H4-o#e #eans Carto#e has all the behaviour of it
n our bean class Cart-ean these represent
ejbCreateString person/ $ejbCreateString person! String id/
pac>age samples.eF.state2l.simple.eFO
import Faa.io.%erialiDaleO
import Faa.rmi.'emote&=ceptionO
import Faa=.eF.Create&=ceptionO
import Faa=.eF.&*+)omeO
p2lic interace Cart)ome e=tends &*+)ome
Cart createG%tring personH thro8s 'emote&=ception7 Create&=ceptionO
Cart createG%tring person7 %tring idH thro8s 'emote&=ception7
Create&=ceptionO
Q
St t f l S i - ClSt t f l S i - Cl
8/9/2019 Complete EJB PPT
71/93
Stateful Session -ean ClassStateful Session -ean Class
Copyright 2004 Kanti Prasad All rights reserved
package declaration should be in the beginning
#porting the reJuired classes
as this is the -ean class ,e ,ill i#ple#ent the business logic here
Cart-ean Class is i#ple#enting sessionbean #eans this bean class is a session bean
5GTH < AS ,e are i#ple#enting and not e3tending ,e need to ,rite all the #ethods that are there in the Sessionbean
We defined this #ethod in the Cart re#ote interface.This also represents the o#e createString person/ #ethod
pac>age samples.eF.state2l.simple.eFO
import Faa.2til.RO
import Faa=.eF.RO
import samples.eF.state2l.simple.tools.+oo>&=ceptionO
import samples.eF.state2l.simple.tools.Id?eriierO
p2lic class Cart+ean implements %ession+ean
%tring c2stomerNameO
%tring c2stomerIdO
?ector contentsO
p2lic oid eFCreateG%tring personH thro8s Create&=ception
i Gperson n2llH
thro8 ne8 Create&=ceptionG\N2ll person not allo8ed.\HOQ else
c2stomerName personO
Q
c2stomerId \0\O
contents ne8 ?ectorGHO
Q
S f S C
8/9/2019 Complete EJB PPT
72/93
This loc> is a s2pporting 2siness method 8ritten in id?eriier class
Stateful Session -ean ClassStateful Session -ean Class
Copyright 2004 Kanti Prasad All rights reserved
We defined this #ethod in the Cart re#ote interfaceThis also represents the o#e createString person! String id/ #ethod ,e defined
The ne, operator is instantiating the instance of a class
We are calling the validateid/ #ethod fro# the class " 9erifier
We defined this #ethod in the Cart re#ote interface
We defined this #ethod in the Cart re#ote interface
We defined contents as a vector
p2lic oid eFCreateG%tring person7 %tring idH thro8s Create&=ception
i Gperson n2llH
thro8 ne8 Create&=ceptionG\N2ll person not allo8ed.\HO
Q else
c2stomerName personO
Q
Id?eriier idChec>er ne8 Id?eriierGHO
i GidChec>er.alidateGidHH
c2stomerId idO
Q else
thro8 ne8 Create&=ceptionG\Inalid idL \ B idHO
Q
contents ne8 ?ectorGHO
Q
p2lic oid add+oo>G%tring titleH contents.add&lementGtitleHO
Q
p2lic oid remoe+oo>G%tring titleH thro8s +oo>&=ception
oolean res2lt contents.remoe&lementGtitleHO
i Gres2lt alseH
thro8 ne8 +oo>&=ceptionGtitle B \ not in cart.\HO
Q
Q
8/9/2019 Complete EJB PPT
73/93
Stateful Session -ean ClassStateful Session -ean Class
Copyright 2004 Kanti Prasad All rights reserved
We defined this #ethod in the Cart re#ote interface
We need to ,rite these #ethods as ,e are i#ple#enting Session-ean
8ules of i#ple#ent states ,e need to i#ple#ent all #ethods that are there in the i#ple#ented interface
-ean class constructor
p2lic ?ector getContentsGH
ret2rn contentsO
Q
p2lic Cart+eanGH Q
p2lic oid eF'emoeGH Q
p2lic oid eFActiateGH Q
p2lic oid eFPassiateGH Q
p2lic oid set%essionConte=tG%essionConte=t scH Q
Q
8/9/2019 Complete EJB PPT
74/93
U-=ml ersion\1.0\ encoding\#T(J;\-W
U/JJ
Copyright 004 %2n Microsystems7 Inc. All rights resered.
%#N P'!P'I&TA'"C!N(I&NTIA. #se is s2Fect to license terms.
JJW
UeFJFar ersion\.1\ =mlns\httpLFaa.s2n.com=mlnsFee\ =mlnsL=si\httpL888.83.org001EM%chemaJ
instance\ =siLschemaocation\httpLFaa.s2n.com=mlnsFee httpLFaa.s2n.com=mlnsFeeeFJFarVV1.=sd\W
UdisplayJnameWCart*A'UdisplayJnameW UenterpriseJeansW
UsessionW
UdisplayJnameWCart&*+UdisplayJnameW
UeFJnameWCart&*+UeFJnameW
UhomeWsamples.eF.state2l.simple.eF.Cart)omeUhomeW
UremoteWsamples.eF.state2l.simple.eF.CartUremoteW
UeFJclassWsamples.eF.state2l.simple.eF.Cart+eanUeFJclassW
UsessionJtypeW%tate2lUsessionJtypeW
UtransactionJtypeWContainerUtransactionJtypeW Usec2rityJidentityW
U2seJcallerJidentityW
Usec2rityJidentityW
UsessionW
UenterpriseJeansW
Stateful "eploent "escriptorStateful "eploent "escriptor
Copyright 2004 Kanti Prasad All rights reserved
reJuired b& an& O%L docu#ent
The nickna#e for this particular -ean
The full& Jualified na#e of the o#e nterface
The full& Jualified na#e of the 8e#ote nterface
The full& Jualified na#e of the H4- Class
-ean t&pe is #entioned here
Closing session and ejb
T)&'& A'& MAN"T!!% $)IC)
C'&AT&% T)&
&%C'IPT!'
(!' #%
8/9/2019 Complete EJB PPT
75/93
Stateful "eploent "escriptorStateful "eploent "escriptor
Copyright 2004 Kanti Prasad All rights reserved
(assing -ean class #ethods and para#eter info
(assing -ean class #ethods and para#eter info
UassemlyJdescriptorW
UcontainerJtransactionW
UmethodW
UeFJnameWCart&*+UeFJnameW
UmethodJintW'emoteUmethodJintW
UmethodJnameWgetContentsUmethodJnameW
UmethodW
UtransJattri2teW'e2iredUtransJattri2teW UcontainerJtransactionW
UcontainerJtransactionW
UmethodW
UeFJnameWCart&*+UeFJnameW
UmethodJintW'emoteUmethodJintW
UmethodJnameWremoe+oo>UmethodJnameW
UmethodJparamsW
UmethodJparamWFaa.lang.%tringUmethodJparamW
UmethodJparamsW UmethodW
UtransJattri2teWNot%2pportedUtransJattri2teW
UcontainerJtransactionW
8/9/2019 Complete EJB PPT
76/93
Stateful "eploent "escriptorStateful "eploent "escriptor
Copyright 2004 Kanti Prasad All rights reserved
(assing -ean class #ethods and para#eter info
UcontainerJtransactionW
UmethodW
UeFJnameWCart&*+UeFJnameW
UmethodJintW'emoteUmethodJintW
UmethodJnameWadd+oo>UmethodJnameW
UmethodJparamsW
UmethodJparamWFaa.lang.%tringUmethodJparamW
UmethodJparamsW UmethodW
UtransJattri2teW'e2iredUtransJattri2teW
UcontainerJtransactionW
UassemlyJdescriptorW
UeFJFarW
8/9/2019 Complete EJB PPT
77/93
8/9/2019 Complete EJB PPT
78/93
Stateful Session ClientStateful Session Client
Copyright 2004 Kanti Prasad All rights reserved
We defined booklist as a vector
After storing in the variable MtitleN ,e are printing it
8e#oving a particular book using the bean class #ethod re#ove-ook throughre#ote interface Cart :as ,e defined it this ,a&
Cart shoppingCart ? ho#e.createQ"uke "eHarlQ!Q12;Q/P
We had ,ritten a ne, class -ookH3ception and using its #ethod to catch an& errors
&n2meration en2mer oo>ist.elementsGHO
8hile Gen2mer.hasMore&lementsGHH
%tring title G%tringH en2mer.ne=t&lementGHO
%ystem.o2t.printlnGtitleHO
Q
shoppingCart.remoe+oo>G\Alice in $onderland\HO
shoppingCart.remoeGHO
%ystem.e=itG0HO
Q catch G+oo>&=ception e=H
%ystem.err.printlnG\Ca2ght a +oo>&=ceptionL \ B e=.getMessageGHHO
%ystem.e=itG0HO
Q catch G&=ception e=H
%ystem.err.printlnG\Ca2ght an 2ne=pected e=ception/\HO
e=.print%tac>TraceGHO %ystem.e=itG1HO
Q
Q
Q
8/9/2019 Complete EJB PPT
79/93
-ook H3ception-ook H3ception
pac>age samples.eF.state2l.simple.toolsO
p2lic class +oo>&=ception e=tends &=ception
RR
R ea2lt constr2ctor.
R p2lic +oo>&=ceptionGH
Q
RR
R Constr2ctor 8ith a UcodeW%tringUcodeW as a parameter.
R @param msg message7 descriing the e=ception.
R
p2lic +oo>&=ceptionG%tring msgH
s2perGmsgHO Q
Q
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
80/93
" 9erifier" 9erifier
pac>age samples.eF.state2l.simple.toolsO
p2lic class Id?eriier
RR
R ea2lt constr2ctor.
R p2lic Id?eriierGH
Q
p2lic oolean alidateG%tring idH
oolean res2lt tr2eO
or Gint i 0O i U id.lengthGHO iBBH
i GCharacter.isigitGid.charAtGiHH alseH
res2lt alseO
Q ret2rn res2ltO
Q
Q
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
81/93
8/9/2019 Complete EJB PPT
82/93
8/9/2019 Complete EJB PPT
83/93
&*+
e=ports operations thro2gh 'emote Interace
ActieE
e=ports operations in the same interace
C!'+A
e=ports methods thro2gh Interace 'epository
@.@. Co#ponentCo#ponent Co#parisonCo#parison
Components proide interaces in the orm o !perations
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
84/93
&*+
Containers inFect code to handle transactions7 dataase management7
sec2rity7 distri2taility and other c2stomisale serices. Containers
can e proided independent o App %erer and &*+ proiders
ActieE
Transactions7 dataase management7 legacy integration hae to e coded
into the logic o the component. %ec2rity policy can e inherited rom
NTM. Transactions can e aided thro2gh MT%
C!'+A
C!'+A%erices hae dierent APIs. C!'+A%erices can e complicated
to code 8ith. C!'+A%erices are not s2pported y all !'+s
B.B. Co#ponentCo#ponent Co#parisonCo#parison
%el Container Components
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
85/93
8/9/2019 Complete EJB PPT
86/93
&*+
&ents s2pported thro2gh *M% 8ith Message
rien +ean
ActieE
e=ports &ents in the same interace
C!'+A
&ents s2pported thro2gh &ent %erice 2t cannot
e e=ported
@0.@0. Co#ponentCo#ponent Co#parisonCo#parison
Components proide interaces in the orm o &ents.
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
87/93
&*+
Incorporating the contents o an &*+ can e done
in t8o 8aysLF y haing the ne8 &*+ 2se the serices o an old
&*+ as a direct client
or
F y 8riting an &*+ class that inherits rom an
e=isting one
These t8o methods o leeragaility gie deelopers
ma=im2m le=iility
@1.@1. Co#ponentCo#ponent Co#parisonCo#parison
Component 'e2saility
Copyright 2004 Kanti Prasad All rights reserved
8/9/2019 Complete EJB PPT
88/93
@; C t C i
8/9/2019 Complete EJB PPT
89/93
C!'+A
&ery C!'+A oFect has to hae its o8n interace
deinition
C!'+A oFects can 2se the serices o other !Fects
No mechanism or inheritance or !Fect re2se
inherently s2pported7 tho2gh
@;.@;. Co#ponentCo#ponent Co#parisonCo#parison
Component 'e2saility
Copyright 2004 Kanti Prasad All rights reserved
@ CC t CC i
8/9/2019 Complete EJB PPT
90/93
&*+
Application %erer ma>es m2ltiple instances o &*+ !Fects. Client
conte=ts can e stored in dierent thread conte=ts. ierent types
o &*+s identiy leels o shareaility.
ActieE
2ses Microsot^s inprocesso2tJoJprocess architect2re or sharing
m2ltiple ActieE components and Client components.
C!'+A
!'+ ma>es m2ltiple instances o C!'+A oFects. Clients conte=ts are
managed y !'+ 2t can ehae dierently ased 2pon endors
Implementation.
@.@. Co#ponentCo#ponent Co#parisonCo#parison
Components %hareaility
Copyright 2004 Kanti Prasad All rights reserved
@D@D ConclusionConclusion
8/9/2019 Complete EJB PPT
91/93
I yo2 hae any comments or appreciations then please email him at
[email protected] [email protected]
)e li>es to hear yo2r eed ac>/
C!N'AT#ATI!N%/No8 yo2 >no8
as m2ch as he
>no8 o &*+
@D.@D. ConclusionConclusion
Copyright 2004 Kanti Prasad All rights reserved
$e s2ccess2lly completed a To2r on &*+ . $e loo>ed at ho8 an &*+ is identiied. )o8 manydierent types o &*+s are there and 8hat each &*+ type implements. $hy
ocalInteraces 8ere introd2ced. $e disected the &*+ and 8ent deeper into each part i.e. +&AN
Class7 'emote Interace7 &*+ !Fect7 ocal !Fect7 ocal Interace7 )ome !Fect. $e loo>ed
Into the deployment descriptor and also seen all the iles in &*+*ar. $e loo>ed into each
+eans
Methods and also learned 8hy 8e needed those methods. $e had done dierent +eans
e=amples and 8e 8ere directed to the $e lin>s 8here all the e=amples are demonstrated.!nce
yo2 can get an idea o all the Interaces7 methods 9 e=ceptions raised7 yo2 can attempt to
try
some e=amples to get amiliar and master &*+. There are nearly 100s o Application serers
2t in this presentation yo2 can see a e8 maForly 2sed App%erers sample
implementation
8e lin>s. *2st do8nload any one o them and try o2t or yo2rsel.
@.@. 8eferences8eferences
8/9/2019 Complete EJB PPT
92/93
Application %erers do8nload inormation . Most o them are either ree or hae a 60 day trial ersion
8H"ATApplication Server and H3a#ples
http
8/9/2019 Complete EJB PPT
93/93