SlideShare uma empresa Scribd logo
1 de 86
[object Object],[object Object],[object Object],[object Object],[object Object]
The Motivation… ,[object Object],[object Object]
What does EJB give me? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Portability ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EJB Architecture It’s about infrastructure…
High Level View Client Object EJB Object B I Z I N T E R F A C E S e r v i c e s EJB Server DB ? ? ? How does a client get a reference to a different machine/JVM? How does the client communicate with the bean? How does the server step into client-bean call? Java references hold bits that don’t means anything outside the  Currently running JVM.
The RMI Remote Method Invocation…
What is RMI? ,[object Object],[object Object],[object Object],[object Object]
Stubs ,[object Object],[object Object],[object Object],[object Object]
Skeletons ,[object Object],[object Object],[object Object],[object Object]
RMI Layers TCP Java Virtual Machine Client Object Java Virtual Machine Stub Remote Object Skeleton Remote Reference Layer Transport Layer Remote Reference Layer Transport Layer
Remote Reference Layer ,[object Object],[object Object],[object Object]
Transport Layer ,[object Object],[object Object],[object Object]
RMI Flow Client Virtual Machine Client Server Virtual Machine Stub Remote Object Skeleton Registry Virtual Machine “ Team”   Server 1 2 1.   Server Creates Remote Object 2. Server Registers Remote Object 3. Client requests object from Registry 3 4. Registry returns remote reference (and stub gets created) 4 5. Client invokes stub method 5 6. Stub talks to skeleton 6 7. Skeleton invokes remote object method
Food for thought How does a local method call, passes an object reference? By Value: by copying the bits in the reference variable. The object Itself is never passed. How does it work with remote method call? That reference would Actually mean nothing on the other heap. An object copy is shipped, not the reference copy.  Actually sends Remote  Object’s stub.
Algorithm ,[object Object],[object Object],[object Object]
Digging deep in to it Exploring the components and the architecture…
EJB Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How does it all happen? EJB S e r v i c e s The bean is deployed, and the server instantiates the Bean Home object and registers it with JNDI. The client does a JNDI lookup on the Home, using the registered name. The JNDI sends back a stub to the Remote Home object. The client asks the Home for a reference to the Component interface, by calling  create() The services kick in and the Bean is created. The EJBObject is created and stub returned to the client. The client can call the business method on the bean The client can get rid of Home stub if he doesn’t want access to more Beans of this type. Home Stub create() EJBObject EJBObject stub
Who does what? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Getting specific ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Session Bean Creation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The client view Bean exposed…
What client wants? ,[object Object],[object Object],[object Object],[object Object]
How does he get it? The process…
JNDI ,[object Object],[object Object],[object Object]
The Client code…
PortableRemoteObject ,[object Object],[object Object],[object Object],[object Object],[object Object]
The home interface Stateless  Session Bean Stateful Session Bean Rules: Declare a create() method that returns the component interface and throw CreateException and RemoteException ,[object Object],[object Object],[object Object],[object Object],[object Object]
EJBHome methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Component Interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EJBObject Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Session Beans Being a Session Bean…
Lifecycle ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Container callbacks ,[object Object],ExampleHome create() ExampleBean setSessionContext(SessionContext sc) ejbActivate() ejbPassivate() ejbRemove() ejbCreate() printStuff() SessionBean setSessionContext(…) ejbActivate() ejbPassivate() ejbRemove() Your Home interface SessionBean interface For every create() in the home There must be a matching ejbCreate() in the bean Business method, not a container callback For Stateless session bean there will be exactly five container callbacks As has only one create(). Stateful beans will have arguments in create() to  pass the client-specific state to be stored.
State chart: stateful EJB EJB EJB 1. constructor 2. setSessionContext 3. ejbCreate() does not exist method ready passivated Timeout.  ejbRemove() not called ejbPassivate() ejbActivate() ejbRemove() or timeout Bean throws system exception (uncheked, uncaught) cannot be brought out of passivation, just to kill it.
Beanness ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
When can you do what? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],constructor setSessionContext() ejbCreate() ejbActivate() ejbPassivate() Business methods ejbRemove()
Passivation: When/Why/How? ,[object Object],[object Object],[object Object],[object Object]
Implementing activate and passivate ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
State chart: stateless EJB EJB 1. constructor 2. setSessionContext 3. ejbCreate() does not exist method ready ejbRemove() or timeout Bean throws system exception (uncheked, uncaught)
Rules for Home methods: bean class ,[object Object],[object Object],[object Object],[object Object]
Rules for business methods :Component interface ,[object Object],[object Object],[object Object]
Rules for business methods:  bean class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Entity Beans The persistence…
Entity Beans: Why? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What you have to do? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The code
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
finders ,[object Object],[object Object],[object Object]
ejbRemove() ,[object Object],[object Object],[object Object]
? Who loves Stale things? Do they matter?
Entity Bean Synchronization ,[object Object],[object Object],[object Object],[object Object],Still a Problem?
The Flow tx EJB updateCustomer() Client calls a business method Container intercepts the call,  Starts a transaction before getting the bean Container tells the db to lock the row Container loads the bean with the entity state from the db Bean runs multiple business methods in the same transaction Container ends the transaction  after updating the new state in bean which might have been cached on  behalf of the entity Container asks the db to release the lock some Sk 1 Address Name ID some Sk 1 Address Name ID
Activation/Passivation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Container callbacks EntityBean set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejLoad() ejbStore() SessionBean set Session Context(…) ejbActivate() ejbPassivate() ejbRemove() When bean is reactivated, deserialization Container gives the bean a reference to its context When bean is taken out of the  pool to service a client’s buz method call When bean is about to be serialized To reduce pool size When bean is about to return to pool,  following a transaction Delete entity from database Container calls when Wants to reduce size of pool When bean has be refreshed with  data from persistent storage When container is about to update the db Both EntityContext and SessionContext extend EJBContext, but EJBContext adds One method getPrimaryKey(). This is different from EJBObject’s getPrimary key as This is only exposed to the entity beans and not to both Session bean and Entity bean
Container callbacks ExampleHome create() findByPrimaryKey(..) doAll() ExampleBean Your Home interface EntityBean interface For every create() in the home There must be two methods in the bean ejbCreate() and ejbPostCreate() EntityBean set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejbLoad() ejbStore() set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejbLoad() ejbStore() ejbCreate() ejbPostCreate() ejbFindByPrimaryKey(String key) ejbHomeDoAll() //business methods from  //component interface Bean also has the Virtual Persistent fields, which are for values that map to db. They represent entity’s persistent state. They exist as abstract getters and setters
State chart: Entity bean EJB EJB EJB 1. constructor 2. setEntityContext does not exist pooled method ready Timeout.  ejbRemove() not called ejbPassivate() ejbActivate() unsetEntityContext() Bean throws system exception (uncheked, uncaught) ejbFind<method>() ejbSelect<method>() ejbHome<method>() ejbFind<method>() ejbHome<method> Biz method (Component interface) ejbSelect<method>() From business method
A reference to EJB object ,[object Object],[object Object],[object Object],?
Why ejbPostCreate? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
finders ,[object Object],[object Object],[object Object],[object Object]
 
Message Driven Beans Asynchronous communication…
MDB: Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
State chart: MDB EJB EJB 1. constructor 2. setMessageDrivenContext 3. ejbCreate() does not exist method ready ejbRemove() or timeout Bean throws system exception (uncheked, uncaught) onMessage()
MDB class
JMS destination ,[object Object],[object Object]
Flavors of Messaging ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What if something goes wrong? ,[object Object],[object Object],[object Object],[object Object],[object Object]
How is it tracked? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EJB Transactions The ACID test…
Exceptions in EJB Handle the bad…
Security in EJB The secrets…
 
Deployment Prepare the environment…
 
 
 
 
 
 
 
 
 

Mais conteúdo relacionado

Mais procurados

Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
phanleson
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
phanleson
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
Stephan Janssen
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
achraf_ing
 

Mais procurados (20)

enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Java bean
Java beanJava bean
Java bean
 
EJB Clients
EJB ClientsEJB Clients
EJB Clients
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Java EE EJB Applications
Java EE EJB ApplicationsJava EE EJB Applications
Java EE EJB Applications
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 

Semelhante a Ejb 2.0

Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
phanleson
 
Session 6 Tp6
Session 6 Tp6Session 6 Tp6
Session 6 Tp6
phanleson
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
vikram singh
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
vikram singh
 
Session 7 Tp7
Session 7 Tp7Session 7 Tp7
Session 7 Tp7
phanleson
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
Dhiraj Champawat
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
KalsoomTahir2
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
Svetlin Nakov
 

Semelhante a Ejb 2.0 (20)

Session 5 Tp5
Session 5 Tp5Session 5 Tp5
Session 5 Tp5
 
Ejb examples
Ejb examplesEjb examples
Ejb examples
 
Session 6 Tp6
Session 6 Tp6Session 6 Tp6
Session 6 Tp6
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Session 7 Tp7
Session 7 Tp7Session 7 Tp7
Session 7 Tp7
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
 
1-introduction to ejb
1-introduction to ejb1-introduction to ejb
1-introduction to ejb
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Skillwise EJB3.0 training
Skillwise EJB3.0 trainingSkillwise EJB3.0 training
Skillwise EJB3.0 training
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 

Último

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Último (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Ejb 2.0

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. EJB Architecture It’s about infrastructure…
  • 6. High Level View Client Object EJB Object B I Z I N T E R F A C E S e r v i c e s EJB Server DB ? ? ? How does a client get a reference to a different machine/JVM? How does the client communicate with the bean? How does the server step into client-bean call? Java references hold bits that don’t means anything outside the Currently running JVM.
  • 7. The RMI Remote Method Invocation…
  • 8.
  • 9.
  • 10.
  • 11. RMI Layers TCP Java Virtual Machine Client Object Java Virtual Machine Stub Remote Object Skeleton Remote Reference Layer Transport Layer Remote Reference Layer Transport Layer
  • 12.
  • 13.
  • 14. RMI Flow Client Virtual Machine Client Server Virtual Machine Stub Remote Object Skeleton Registry Virtual Machine “ Team” Server 1 2 1. Server Creates Remote Object 2. Server Registers Remote Object 3. Client requests object from Registry 3 4. Registry returns remote reference (and stub gets created) 4 5. Client invokes stub method 5 6. Stub talks to skeleton 6 7. Skeleton invokes remote object method
  • 15. Food for thought How does a local method call, passes an object reference? By Value: by copying the bits in the reference variable. The object Itself is never passed. How does it work with remote method call? That reference would Actually mean nothing on the other heap. An object copy is shipped, not the reference copy. Actually sends Remote Object’s stub.
  • 16.
  • 17. Digging deep in to it Exploring the components and the architecture…
  • 18.
  • 19. How does it all happen? EJB S e r v i c e s The bean is deployed, and the server instantiates the Bean Home object and registers it with JNDI. The client does a JNDI lookup on the Home, using the registered name. The JNDI sends back a stub to the Remote Home object. The client asks the Home for a reference to the Component interface, by calling create() The services kick in and the Bean is created. The EJBObject is created and stub returned to the client. The client can call the business method on the bean The client can get rid of Home stub if he doesn’t want access to more Beans of this type. Home Stub create() EJBObject EJBObject stub
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. The client view Bean exposed…
  • 25.
  • 26. How does he get it? The process…
  • 27.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. Session Beans Being a Session Bean…
  • 35.
  • 36.
  • 37. State chart: stateful EJB EJB EJB 1. constructor 2. setSessionContext 3. ejbCreate() does not exist method ready passivated Timeout. ejbRemove() not called ejbPassivate() ejbActivate() ejbRemove() or timeout Bean throws system exception (uncheked, uncaught) cannot be brought out of passivation, just to kill it.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42. State chart: stateless EJB EJB 1. constructor 2. setSessionContext 3. ejbCreate() does not exist method ready ejbRemove() or timeout Bean throws system exception (uncheked, uncaught)
  • 43.
  • 44.
  • 45.
  • 46. Entity Beans The persistence…
  • 47.
  • 48.
  • 50.
  • 51.
  • 52.
  • 53. ? Who loves Stale things? Do they matter?
  • 54.
  • 55. The Flow tx EJB updateCustomer() Client calls a business method Container intercepts the call, Starts a transaction before getting the bean Container tells the db to lock the row Container loads the bean with the entity state from the db Bean runs multiple business methods in the same transaction Container ends the transaction after updating the new state in bean which might have been cached on behalf of the entity Container asks the db to release the lock some Sk 1 Address Name ID some Sk 1 Address Name ID
  • 56.
  • 57. Container callbacks EntityBean set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejLoad() ejbStore() SessionBean set Session Context(…) ejbActivate() ejbPassivate() ejbRemove() When bean is reactivated, deserialization Container gives the bean a reference to its context When bean is taken out of the pool to service a client’s buz method call When bean is about to be serialized To reduce pool size When bean is about to return to pool, following a transaction Delete entity from database Container calls when Wants to reduce size of pool When bean has be refreshed with data from persistent storage When container is about to update the db Both EntityContext and SessionContext extend EJBContext, but EJBContext adds One method getPrimaryKey(). This is different from EJBObject’s getPrimary key as This is only exposed to the entity beans and not to both Session bean and Entity bean
  • 58. Container callbacks ExampleHome create() findByPrimaryKey(..) doAll() ExampleBean Your Home interface EntityBean interface For every create() in the home There must be two methods in the bean ejbCreate() and ejbPostCreate() EntityBean set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejbLoad() ejbStore() set Entity Context(EntityContext ec) ejbActivate() ejbPassivate() ejbRemove() unsetEntityContext() ejbLoad() ejbStore() ejbCreate() ejbPostCreate() ejbFindByPrimaryKey(String key) ejbHomeDoAll() //business methods from //component interface Bean also has the Virtual Persistent fields, which are for values that map to db. They represent entity’s persistent state. They exist as abstract getters and setters
  • 59. State chart: Entity bean EJB EJB EJB 1. constructor 2. setEntityContext does not exist pooled method ready Timeout. ejbRemove() not called ejbPassivate() ejbActivate() unsetEntityContext() Bean throws system exception (uncheked, uncaught) ejbFind<method>() ejbSelect<method>() ejbHome<method>() ejbFind<method>() ejbHome<method> Biz method (Component interface) ejbSelect<method>() From business method
  • 60.
  • 61.
  • 62.
  • 63.  
  • 64. Message Driven Beans Asynchronous communication…
  • 65.
  • 66.
  • 67. State chart: MDB EJB EJB 1. constructor 2. setMessageDrivenContext 3. ejbCreate() does not exist method ready ejbRemove() or timeout Bean throws system exception (uncheked, uncaught) onMessage()
  • 69.
  • 70.
  • 71.
  • 72.
  • 73. EJB Transactions The ACID test…
  • 74. Exceptions in EJB Handle the bad…
  • 75. Security in EJB The secrets…
  • 76.  
  • 77. Deployment Prepare the environment…
  • 78.  
  • 79.  
  • 80.  
  • 81.  
  • 82.  
  • 83.  
  • 84.  
  • 85.  
  • 86.  

Notas do Editor

  1. In Older days, each app server vendor had its own proprietary API. You learn it then work with it. If you need a new feature, its totally vendor dependent.
  2. If you are an object and you have a reference to another object, that object must be in the same heap with you.
  3. JRMP is Java Remote Method Protocol and is only Java to Java. Here you can be sure that the object that you get is the one you asked for.
  4. RMI-IIOP compatible arguments are : Serializable, primitive types, Remote, or array or a collections of any of those. Application exceptions or compiler checked exceptions extends Exception class and runtime exceptions are a subclass of RuntimeExceptions.
  5. isIdentical(): Stateless Session Bean: True, if both references come from same Home, even if stubs are referring to two different Remote EJB Objects Stateful Session Bean: False no matter what, for any two unique stubs, even if for same home Entity Beans: True if the stubs refer to two entities with the same Primary Key. How are the three remove() methods different?
  6. When ejbPassivate() completes, every non-transient instance variable must be a reference to one of the following: A serializable object A null value A bean’s remote component or home interface, even if the stub class is not serializable A bean’s local component or home interface, even if the stub class is not serializable A SessionContext object, even if its not serializable A bean’s special JNDI context,or any of its sub-context The UserTransaction interface A resource manager connection factory (like DataSource)
  7. Is different from Stateless Session bean which calls the ejbActivate() and ejbPassivate(), and hence has to serialize and save the state.