Your SlideShare is downloading. ×
How to cuddle your EJBs, Carlo de Wolf
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How to cuddle your EJBs, Carlo de Wolf

1,887
views

Published on

Looking for ideal tools and techniques for building applications is like a quest for the holy grail. In this pursuit we’re looking for features like simplicity, performance, reusability, testability, …

Looking for ideal tools and techniques for building applications is like a quest for the holy grail. In this pursuit we’re looking for features like simplicity, performance, reusability, testability, hot-deployment, and embeddability.

In an attempt to find the holy grail of software development we'll mount up and try to assert whether EJB is a step forward or backward on our path. We'll go through a couple of aspects of an utopian software component in terms of performance/scalability and testability.

What if we opt for a simple direct-call solutions?
What if we invite aliens to help testing EJBs?
Class hot-deploy, a fluffy white rabbit?
What if we snuggle up real close to our EJBs in an embedded environment?

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,887
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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!
  • 32. Q & A http://jboss.org/ejb3 http://jboss.org/shrinkwrap http://jboss.org/arquillian

×