SlideShare a Scribd company logo
1 of 33
Download to read offline
1
How to cuddle your EJBs
Carlo de Wolf
EJB 3 Product Lead
JBoss by Red Hat
October 2010
2
Agenda
● Quest for The Holy Grail
● EAP
● Why use EJB?
– Simple
– Predictable
– Re-usable
– Testable
● Road-map
3
Quest for The Holy Grail
● Looking for software components that are:
– Simple
– Predictable
– Re-usable
– Testable
● Also
– Performant
4
Enterprise Application Platform
● A fork of AS 5
● Plus functional patches
● Plus performance patches
● Plus support
● Some bits available through Plugin 1.0.19
5
Why use EJB(tm)
?
● Allow rapid development of reusable
business components
● Using an easy infrastructure which does:
– Memory management
– Remote invocation
– Thread management
● Thus having a predictable QoS
6
What is an EJB(tm)
?
● It's not a POJO!
● It consists of a class + interceptor classes
+ interfaces
● Construction is different
● Invocation is different
● It's an assembly with one or more views
7
Quest for The Holy Grail
● Looking for software components that are:
– Simple
– Predictable
– Re-usable
– Testable
● Also
– Performant
8
Simplicity
● Create an EJB with a remote business
view
● Create an EJB archive
● Deploy it
9
Creating an EJB
● Learn how to code EJBs with Andrew's
book: Enterprise JavaBeans 3.1
– ISBN: 978-0-596-15802-6
– Develop your first EJBs with a
hands-on walkthrough of
EJB 3.1 concepts
10
Creating an EJB archive
● Use Ant to create an archive
<jar jarfile=”${build.lib}/myfirstejb.jar”>
<fileset dir=”${build.class}”/>
</jar>
● Or use Maven
11
Deploying an archive
● Copy into deploy
$ cp myfirstejb.jar $JBOSS_HOME/server/default/deploy/
● Use the MainDeployer
MbeanServerConnection conn =
iniCtx.lookup(“jmx/invoker/RMIAdaptor”);
conn.invoke(“jboss.system:service=MainDeployer”,
“deploy”, new URL(“file:myfirstejb.jar”));
12
Quest for The Holy Grail
● Looking for software components that are:
– Simple
– Predictable
– Re-usable
– Testable
● Also
– Performant
13
Dynamic Code Changing
● EJBTHREE-1096: Make SLSB and SFSB
hot deployable for RAD.
● Allow changing functionality / invariants
● Allow changes in the EJB structure
● Compiling (Deploying) vs Interpreted
14
Bean State
● Bean State is governed by invariants
@Stateful
public class ConsentWizard
{
private Date birthdate;
public void setBirthday(Date date)
{
if(age(date) < 18)
throw new IllegalStateException("Minors not allowed");
this.birthdate = date;
}
}
● Changing an invariant leaves artifacts
● Bean State has become non-deterministic
15
Application State
● Application state is determined by the
assembly of all components
@Stateful
public class ConsentWizard implements RemoteWizard
{
}
public class SomeServletThingy
{
@EJB RemoteWizard wizard;
}
● Changing component structure may leave
application undeployable
16
Deploying is like Compiling
● It checks whether the application is
deployable
● It sets up a clean slate to begin tests from
● So, Dynamic Code Changing is a fluffy
white rabbit. Looks cute, but will kill you in
the end.
17
Quest for The Holy Grail
● Looking for software components that are:
– Simple
– Predictable
– Re-usable
– Testable
● Also
– Performant
18
Separation of Concerns
● By making aspects configurable and
manageable
● Security
● Transaction Management
● Remoting
● Interceptors (now separated!)
● Persistence (separated into JPA)
19
Spec EJB 3.1 Async
● A re-usable component separates
concerns
● Brings an application developer
requirement to the bean developer
● Ergo doesn't make for re-usable
components
20
JBoss EJB 3.1 Async
● A callers functional concern
● If the caller resides in the same VM, let the
EJB manage it
21
Quest for The Holy Grail
● Looking for software components that are:
– Simple
– Predictable
– Re-usable
– Testable
● Also
– Performant
22
Test it using a remote view
● Create an archive, deploy it, then call it
public class RemoteTestCase
{
@Test
public void test() throws NamingException
{
MyFirstView bean = (MyFirstView) iniCtx.lookup("MyFirstBean/remote");
String result = bean.doSomething();
assertEquals("done", result);
}
}
23
Assembled Directory
● Use VFS 2
AssembledDirectory jar =
AssembledContextFactory.getInstance().create("test.jar");
jar.addClass(GreetingsBean.class);
jar.addClass(Greetings.class);
● The venerable JBoss Embeddable
Bootstrap.getInstance().deploy(jar);
● JBoss Reloaded Embedded prototype
VFSDeployment deployment =
VFSDeploymentFactory.getInstance().createVFSDeployment(root);
mainDeployer.deploy(root);
● EJB 3.1 Embeddable prototype
EJBContainer container = EJBContainer.createEJBContainer();
on(container).deploy(deployment(jar));
24
ShrinkWrap
● Easily build an archive
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(GreetingsBean.class, Greetings.class);
File tempFile = File.createTempFile("test", ".jar");
jar.as(ZipExporter.class).exportZip(tempFile, true);
URL url = tempFile.toURI().toURL();
● Deploy the archive
MbeanServerConnection conn = iniCtx.lookup("jmx/invoker/RMIAdaptor");
conn.invoke("jboss.system:service=MainDeployer", "deploy", url);
● See it in action
$ git clone git://github.com/jbossejb3/jboss-ejb3-timerservice.git
$ cd jboss-ejb3-timerservice
$ mvn install
25
EJB 3.1 Embeddable
● By spec only does local session beans
● You want more services, so ultimately a
full Application Server
● Two solutions:
– Paravirtualized, not standalone
– JBoss Embedded
26
Arquillian
● Or we could go to the server
@RunWith(Arquillian.class)
public class GreetingManagerTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(GreetingsBean.class, Greetings.class);
}
@EJB
private Greetings alien;
@Test
public void shouldGreetUser() throws Exception {
String name = "Earthlings";
assertEquals("Hello, " + name, alien.greet(name));
}
}
27
Arquillian #2
● Access to local views
● Debug my EJBs and unit test
– Breakpoints
– Step through
– Happens on the VM running the Server
● JBoss AS becomes an 'OS' resource
– No worry about Server lifecycle / startup time
28
ShrinkWrap + Arquillian
● The Aliens love any container
● Complete separation of concerns
29
Road-map
● EAP 6 will do EJB 3.1
● AS 6 CR1 time-box closes Nov 16th
● AS 7 M1 is coming up
● Bug reports / requests can end up in a
milestone, get on the band-wagon.
30
EJB 4
● More separation of concerns
● Concrete aspects of Managed Beans?
● CDI Extension?
31
How to cuddle your EJBs?
● Don't try to bring the EJBs to you.
● Go to the EJBs.
● Use ShrinkWrap & Arquillian for your
travels!
Q & A
http://jboss.org/ejb3
http://jboss.org/shrinkwrap
http://jboss.org/arquillian
How to cuddle your EJBs, Carlo de Wolf

More Related Content

What's hot

What's hot (20)

De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14
 
Java Unit Testing with Unitils
Java Unit Testing with UnitilsJava Unit Testing with Unitils
Java Unit Testing with Unitils
 
Monitoring And Tuning Glass Fish In The Wild Community One 2009
Monitoring And Tuning Glass Fish In The Wild   Community One 2009Monitoring And Tuning Glass Fish In The Wild   Community One 2009
Monitoring And Tuning Glass Fish In The Wild Community One 2009
 
Preparing your code for Java 9
Preparing your code for Java 9Preparing your code for Java 9
Preparing your code for Java 9
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
SLF4J+Logback
SLF4J+LogbackSLF4J+Logback
SLF4J+Logback
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Are app servers still fascinating
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinating
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
Hackathon - building and extending OpenJDK
Hackathon - building and extending OpenJDKHackathon - building and extending OpenJDK
Hackathon - building and extending OpenJDK
 
Play framework
Play frameworkPlay framework
Play framework
 
OSGi & Java EE in GlassFish
OSGi & Java EE in GlassFishOSGi & Java EE in GlassFish
OSGi & Java EE in GlassFish
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 201450 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
 
Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012
 

Viewers also liked

Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
OpenBlend society
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
OpenBlend society
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
OpenBlend society
 
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
OpenBlend society
 

Viewers also liked (6)

Migracao gae-openshift
Migracao gae-openshiftMigracao gae-openshift
Migracao gae-openshift
 
Tackling Actual Problems on the Wings of the Netbeans Platform, Jure Polutnik
Tackling Actual Problems on the Wings of the Netbeans Platform, Jure PolutnikTackling Actual Problems on the Wings of the Netbeans Platform, Jure Polutnik
Tackling Actual Problems on the Wings of the Netbeans Platform, Jure Polutnik
 
Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
Memory is the new disk, disk is the new tape, Bela Ban (JBoss by RedHat)
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
Java SE 7 - The Platform Evolves, Dalibor Topić (Oracle)
 
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
Seam 3 from a Web developer’s point of view, Matija Mazi (Parsek)
 

Similar to How to cuddle your EJBs, Carlo de Wolf

Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
CIB Egypt
 

Similar to How to cuddle your EJBs, Carlo de Wolf (20)

Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Glass Fishv3 March2010
Glass Fishv3 March2010Glass Fishv3 March2010
Glass Fishv3 March2010
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011
 
Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
 
EJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 PreludeEJB 3.1 and GlassFish v3 Prelude
EJB 3.1 and GlassFish v3 Prelude
 
Spock pres
Spock presSpock pres
Spock pres
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9
 
Java On Speed
Java On SpeedJava On Speed
Java On Speed
 
Java Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, HibernateJava Course 15: Ant, Scripting, Spring, Hibernate
Java Course 15: Ant, Scripting, Spring, Hibernate
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
 
Javascript training sample
Javascript training sampleJavascript training sample
Javascript training sample
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
The Java EE 6 platform
The Java EE 6 platformThe Java EE 6 platform
The Java EE 6 platform
 
Ad111
Ad111Ad111
Ad111
 
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
 
Build, logging, and unit test tools
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test tools
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 

More from OpenBlend society

SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
OpenBlend society
 
National Reference runtime environment, Boris Šaletić (MJU)
National Reference runtime environment, Boris Šaletić (MJU)National Reference runtime environment, Boris Šaletić (MJU)
National Reference runtime environment, Boris Šaletić (MJU)
OpenBlend society
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
OpenBlend society
 
Enterprise Java Virtualization, Sacha Labourey
Enterprise Java Virtualization, Sacha LaboureyEnterprise Java Virtualization, Sacha Labourey
Enterprise Java Virtualization, Sacha Labourey
OpenBlend society
 

More from OpenBlend society (8)

SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
SOA architecture patterns, Matjaž Jurič (FRI/Univerza v Ljubljani)
 
National Reference runtime environment, Boris Šaletić (MJU)
National Reference runtime environment, Boris Šaletić (MJU)National Reference runtime environment, Boris Šaletić (MJU)
National Reference runtime environment, Boris Šaletić (MJU)
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
 
Enterprise Java Virtualization, Sacha Labourey
Enterprise Java Virtualization, Sacha LaboureyEnterprise Java Virtualization, Sacha Labourey
Enterprise Java Virtualization, Sacha Labourey
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
 
Android Up Close, Martin Sonc
Android Up Close, Martin SoncAndroid Up Close, Martin Sonc
Android Up Close, Martin Sonc
 
Successful Application Lifecycle Management in heterogeneous environments, Ma...
Successful Application Lifecycle Management in heterogeneous environments, Ma...Successful Application Lifecycle Management in heterogeneous environments, Ma...
Successful Application Lifecycle Management in heterogeneous environments, Ma...
 
Becoming an Open Source developer, Dimitris Andreadis
Becoming an Open Source developer, Dimitris AndreadisBecoming an Open Source developer, Dimitris Andreadis
Becoming an Open Source developer, Dimitris Andreadis
 

Recently uploaded

Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 

Recently uploaded (20)

Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 

How to cuddle your EJBs, Carlo de Wolf

  • 1. 1 How to cuddle your EJBs Carlo de Wolf EJB 3 Product Lead JBoss by Red Hat October 2010
  • 2. 2 Agenda ● Quest for The Holy Grail ● EAP ● Why use EJB? – Simple – Predictable – Re-usable – Testable ● Road-map
  • 3. 3 Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant
  • 4. 4 Enterprise Application Platform ● A fork of AS 5 ● Plus functional patches ● Plus performance patches ● Plus support ● Some bits available through Plugin 1.0.19
  • 5. 5 Why use EJB(tm) ? ● Allow rapid development of reusable business components ● Using an easy infrastructure which does: – Memory management – Remote invocation – Thread management ● Thus having a predictable QoS
  • 6. 6 What is an EJB(tm) ? ● It's not a POJO! ● It consists of a class + interceptor classes + interfaces ● Construction is different ● Invocation is different ● It's an assembly with one or more views
  • 7. 7 Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant
  • 8. 8 Simplicity ● Create an EJB with a remote business view ● Create an EJB archive ● Deploy it
  • 9. 9 Creating an EJB ● Learn how to code EJBs with Andrew's book: Enterprise JavaBeans 3.1 – ISBN: 978-0-596-15802-6 – Develop your first EJBs with a hands-on walkthrough of EJB 3.1 concepts
  • 10. 10 Creating an EJB archive ● Use Ant to create an archive <jar jarfile=”${build.lib}/myfirstejb.jar”> <fileset dir=”${build.class}”/> </jar> ● Or use Maven
  • 11. 11 Deploying an archive ● Copy into deploy $ cp myfirstejb.jar $JBOSS_HOME/server/default/deploy/ ● Use the MainDeployer MbeanServerConnection conn = iniCtx.lookup(“jmx/invoker/RMIAdaptor”); conn.invoke(“jboss.system:service=MainDeployer”, “deploy”, new URL(“file:myfirstejb.jar”));
  • 12. 12 Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant
  • 13. 13 Dynamic Code Changing ● EJBTHREE-1096: Make SLSB and SFSB hot deployable for RAD. ● Allow changing functionality / invariants ● Allow changes in the EJB structure ● Compiling (Deploying) vs Interpreted
  • 14. 14 Bean State ● Bean State is governed by invariants @Stateful public class ConsentWizard { private Date birthdate; public void setBirthday(Date date) { if(age(date) < 18) throw new IllegalStateException("Minors not allowed"); this.birthdate = date; } } ● Changing an invariant leaves artifacts ● Bean State has become non-deterministic
  • 15. 15 Application State ● Application state is determined by the assembly of all components @Stateful public class ConsentWizard implements RemoteWizard { } public class SomeServletThingy { @EJB RemoteWizard wizard; } ● Changing component structure may leave application undeployable
  • 16. 16 Deploying is like Compiling ● It checks whether the application is deployable ● It sets up a clean slate to begin tests from ● So, Dynamic Code Changing is a fluffy white rabbit. Looks cute, but will kill you in the end.
  • 17. 17 Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant
  • 18. 18 Separation of Concerns ● By making aspects configurable and manageable ● Security ● Transaction Management ● Remoting ● Interceptors (now separated!) ● Persistence (separated into JPA)
  • 19. 19 Spec EJB 3.1 Async ● A re-usable component separates concerns ● Brings an application developer requirement to the bean developer ● Ergo doesn't make for re-usable components
  • 20. 20 JBoss EJB 3.1 Async ● A callers functional concern ● If the caller resides in the same VM, let the EJB manage it
  • 21. 21 Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant
  • 22. 22 Test it using a remote view ● Create an archive, deploy it, then call it public class RemoteTestCase { @Test public void test() throws NamingException { MyFirstView bean = (MyFirstView) iniCtx.lookup("MyFirstBean/remote"); String result = bean.doSomething(); assertEquals("done", result); } }
  • 23. 23 Assembled Directory ● Use VFS 2 AssembledDirectory jar = AssembledContextFactory.getInstance().create("test.jar"); jar.addClass(GreetingsBean.class); jar.addClass(Greetings.class); ● The venerable JBoss Embeddable Bootstrap.getInstance().deploy(jar); ● JBoss Reloaded Embedded prototype VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root); mainDeployer.deploy(root); ● EJB 3.1 Embeddable prototype EJBContainer container = EJBContainer.createEJBContainer(); on(container).deploy(deployment(jar));
  • 24. 24 ShrinkWrap ● Easily build an archive JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses(GreetingsBean.class, Greetings.class); File tempFile = File.createTempFile("test", ".jar"); jar.as(ZipExporter.class).exportZip(tempFile, true); URL url = tempFile.toURI().toURL(); ● Deploy the archive MbeanServerConnection conn = iniCtx.lookup("jmx/invoker/RMIAdaptor"); conn.invoke("jboss.system:service=MainDeployer", "deploy", url); ● See it in action $ git clone git://github.com/jbossejb3/jboss-ejb3-timerservice.git $ cd jboss-ejb3-timerservice $ mvn install
  • 25. 25 EJB 3.1 Embeddable ● By spec only does local session beans ● You want more services, so ultimately a full Application Server ● Two solutions: – Paravirtualized, not standalone – JBoss Embedded
  • 26. 26 Arquillian ● Or we could go to the server @RunWith(Arquillian.class) public class GreetingManagerTest { @Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses(GreetingsBean.class, Greetings.class); } @EJB private Greetings alien; @Test public void shouldGreetUser() throws Exception { String name = "Earthlings"; assertEquals("Hello, " + name, alien.greet(name)); } }
  • 27. 27 Arquillian #2 ● Access to local views ● Debug my EJBs and unit test – Breakpoints – Step through – Happens on the VM running the Server ● JBoss AS becomes an 'OS' resource – No worry about Server lifecycle / startup time
  • 28. 28 ShrinkWrap + Arquillian ● The Aliens love any container ● Complete separation of concerns
  • 29. 29 Road-map ● EAP 6 will do EJB 3.1 ● AS 6 CR1 time-box closes Nov 16th ● AS 7 M1 is coming up ● Bug reports / requests can end up in a milestone, get on the band-wagon.
  • 30. 30 EJB 4 ● More separation of concerns ● Concrete aspects of Managed Beans? ● CDI Extension?
  • 31. 31 How to cuddle your EJBs? ● Don't try to bring the EJBs to you. ● Go to the EJBs. ● Use ShrinkWrap & Arquillian for your travels!