Upload
openblend-society
View
2.218
Download
1
Embed Size (px)
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?
Citation preview
1
How to cuddle your EJBs
Carlo de WolfEJB 3 Product LeadJBoss 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 MainDeployerMbeanServerConnection 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@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
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
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 itpublic 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 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
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/ejb3http://jboss.org/shrinkwraphttp://jboss.org/arquillian