• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

How to cuddle your EJBs, Carlo de Wolf

  • 1,854 views
Uploaded 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?

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,854
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
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. How to cuddle your EJBs Carlo de Wolf EJB 3 Product Lead JBoss by Red Hat October 2010 1
  • 2. Agenda ● Quest for The Holy Grail ● EAP ● Why use EJB? – Simple – Predictable – Re-usable – Testable ● Road-map 2
  • 3. Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant 3
  • 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 4
  • 5. (tm) Why use EJB ? ● Allow rapid development of reusable business components ● Using an easy infrastructure which does: – Memory management – Remote invocation – Thread management ● Thus having a predictable QoS 5
  • 6. (tm) What is an EJB ? ● 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 6
  • 7. Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant 7
  • 8. Simplicity ● Create an EJB with a remote business view ● Create an EJB archive ● Deploy it 8
  • 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 9
  • 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 10
  • 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”)); 11
  • 12. Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant 12
  • 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 13
  • 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 14
  • 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 15
  • 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. 16
  • 17. Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant 17
  • 18. Separation of Concerns ● By making aspects configurable and manageable ● Security ● Transaction Management ● Remoting ● Interceptors (now separated!) ● Persistence (separated into JPA) 18
  • 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 19
  • 20. JBoss EJB 3.1 Async ● A callers functional concern ● If the caller resides in the same VM, let the EJB manage it 20
  • 21. Quest for The Holy Grail ● Looking for software components that are: – Simple – Predictable – Re-usable – Testable ● Also – Performant 21
  • 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); } } 22
  • 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)); 23
  • 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 24
  • 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 25
  • 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)); } } 26
  • 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 27
  • 28. ShrinkWrap + Arquillian ● The Aliens love any container ● Complete separation of concerns 28
  • 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. 29
  • 30. EJB 4 ● More separation of concerns ● Concrete aspects of Managed Beans? ● CDI Extension? 30
  • 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! 31
  • 32. Q&A http://jboss.org/ejb3 http://jboss.org/shrinkwrap http://jboss.org/arquillian