+ All Categories
Home > Technology > How to cuddle your EJBs, Carlo de Wolf

How to cuddle your EJBs, Carlo de Wolf

Date post: 29-Nov-2014
Category:
Upload: openblend-society
View: 2,209 times
Download: 1 times
Share this document with a friend
Description:
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?
33
1 How to cuddle your EJBs Carlo de Wolf EJB 3 Product Lead JBoss by Red Hat October 2010
Transcript
Page 1: How to cuddle your EJBs, Carlo de Wolf

1

How to cuddle your EJBs

Carlo de WolfEJB 3 Product LeadJBoss by Red Hat

October 2010

Page 2: How to cuddle your EJBs, Carlo de Wolf

2

Agenda

● Quest for The Holy Grail● EAP● Why use EJB?

– Simple– Predictable– Re-usable– Testable

● Road-map

Page 3: How to cuddle your EJBs, Carlo de Wolf

3

Quest for The Holy Grail

● Looking for software components that are:– Simple– Predictable– Re-usable– Testable

● Also– Performant

Page 4: How to cuddle your EJBs, Carlo de Wolf

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

Page 5: How to cuddle your EJBs, Carlo de Wolf

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

Page 6: How to cuddle your EJBs, Carlo de Wolf

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

Page 7: How to cuddle your EJBs, Carlo de Wolf

7

Quest for The Holy Grail

● Looking for software components that are:– Simple– Predictable– Re-usable– Testable

● Also– Performant

Page 8: How to cuddle your EJBs, Carlo de Wolf

8

Simplicity

● Create an EJB with a remote business view

● Create an EJB archive● Deploy it

Page 9: How to cuddle your EJBs, Carlo de Wolf

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

Page 10: How to cuddle your EJBs, Carlo de Wolf

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

Page 11: How to cuddle your EJBs, Carlo de Wolf

11

Deploying an archive

● Copy into deploy$ cp myfirstejb.jar $JBOSS_HOME/server/default/deploy/

● Use the MainDeployerMbeanServerConnection conn = iniCtx.lookup(“jmx/invoker/RMIAdaptor”);conn.invoke(“jboss.system:service=MainDeployer”, “deploy”, new URL(“file:myfirstejb.jar”));

Page 12: How to cuddle your EJBs, Carlo de Wolf

12

Quest for The Holy Grail

● Looking for software components that are:– Simple– Predictable– Re-usable– Testable

● Also– Performant

Page 13: How to cuddle your EJBs, Carlo de Wolf

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

Page 14: How to cuddle your EJBs, Carlo de Wolf

14

Bean State

● Bean State is governed by invariants@Statefulpublic 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

Page 15: How to cuddle your EJBs, Carlo de Wolf

15

Application State

● Application state is determined by the assembly of all components

@Statefulpublic class ConsentWizard implements RemoteWizard{}

public class SomeServletThingy{ @EJB RemoteWizard wizard;}

● Changing component structure may leave application undeployable

Page 16: How to cuddle your EJBs, Carlo de Wolf

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.

Page 17: How to cuddle your EJBs, Carlo de Wolf

17

Quest for The Holy Grail

● Looking for software components that are:– Simple– Predictable– Re-usable– Testable

● Also– Performant

Page 18: How to cuddle your EJBs, Carlo de Wolf

18

Separation of Concerns

● By making aspects configurable and manageable

● Security● Transaction Management● Remoting● Interceptors (now separated!)● Persistence (separated into JPA)

Page 19: How to cuddle your EJBs, Carlo de Wolf

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

Page 20: How to cuddle your EJBs, Carlo de Wolf

20

JBoss EJB 3.1 Async

● A callers functional concern● If the caller resides in the same VM, let the

EJB manage it

Page 21: How to cuddle your EJBs, Carlo de Wolf

21

Quest for The Holy Grail

● Looking for software components that are:– Simple– Predictable– Re-usable– Testable

● Also– Performant

Page 22: How to cuddle your EJBs, Carlo de Wolf

22

Test it using a remote view

● Create an archive, deploy it, then call itpublic class RemoteTestCase{ @Test public void test() throws NamingException { MyFirstView bean = (MyFirstView) iniCtx.lookup("MyFirstBean/remote"); String result = bean.doSomething(); assertEquals("done", result); }}

Page 23: How to cuddle your EJBs, Carlo de Wolf

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));

Page 24: How to cuddle your EJBs, Carlo de Wolf

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 archiveMbeanServerConnection 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

Page 25: How to cuddle your EJBs, Carlo de Wolf

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

Page 26: How to cuddle your EJBs, Carlo de Wolf

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)); } }

Page 27: How to cuddle your EJBs, Carlo de Wolf

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

Page 28: How to cuddle your EJBs, Carlo de Wolf

28

ShrinkWrap + Arquillian

● The Aliens love any container

● Complete separation of concerns

Page 29: How to cuddle your EJBs, Carlo de Wolf

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.

Page 30: How to cuddle your EJBs, Carlo de Wolf

30

EJB 4

● More separation of concerns● Concrete aspects of Managed Beans?● CDI Extension?

Page 31: How to cuddle your EJBs, Carlo de Wolf

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!

Page 32: How to cuddle your EJBs, Carlo de Wolf

Q & A

http://jboss.org/ejb3http://jboss.org/shrinkwraphttp://jboss.org/arquillian

Page 33: How to cuddle your EJBs, Carlo de Wolf

Recommended