63
Using JBoss Forge, Arquillian & Java EE 6 RAPID JAVA APPLICATION DEVELOPMENT Ray Ploski Director, Developer Programs & Strategy JBoss, by Red Hat, Inc.

Developer Productivity with Forge, Java EE 6 and Arquillian

Embed Size (px)

DESCRIPTION

Presentation given at JavaOne Tokyo 2012 about the innovations in Java EE 6, JBoss Forge, Arquillian.

Citation preview

Page 1: Developer Productivity with Forge, Java EE 6 and Arquillian

Using JBoss Forge, Arquill ian & Java EE 6

RAPID JAVA APPLICATION

DEVELOPMENT

Ray Ploski Director, Developer Programs & Strategy

JBoss, by Red Hat, Inc.

Page 2: Developer Productivity with Forge, Java EE 6 and Arquillian

? DEVELOPER PRODUCTIVITY

- WHAT IF?

Faster Start-Up Times

Easier Integration Testing

80% Less Configuration

50% Less Code

25% Less Classes

Rapid Application Tooling

Vendor Agnostic

Open eco-system

* Based on a Sample POJO/JPA/REST Based Application

Page 3: Developer Productivity with Forge, Java EE 6 and Arquillian

GREAT !!!

Page 4: Developer Productivity with Forge, Java EE 6 and Arquillian

J2EE

EJB

#fail #fail

#fail

Page 5: Developer Productivity with Forge, Java EE 6 and Arquillian

PURPOSE OF THIS TALK ¡  Demonstrate productivity gains §  Less Code, Classes and Configuration

¡  Address Concerns §  About Java EE, EJBs, App Servers & Lock-in

¡  Introduce new innovations §  JBoss Forge §  CDI and Apache DeltaSpike §  Arquillian

Page 6: Developer Productivity with Forge, Java EE 6 and Arquillian

J2EE 1.4

Page 7: Developer Productivity with Forge, Java EE 6 and Arquillian

EJB 2.X SESSION BEAN

Page 8: Developer Productivity with Forge, Java EE 6 and Arquillian

EJB 2.X DEPLOYMENT DESCRIPTOR

<!-- … à!<enterprise-beans>! <session>! <display-name>BankSB</display-name>! <ejb-name>BankBean</ejb-name>! <local-home>com.advocacy.legacy.ejb.BankLocalHome</local-home>! <local>com.advocacy.legacy.ejb.BankLocal</local>! <ejb-class>com.advocacy.legacy.ejb.BankBean</ejb-class>! <session-type>Stateless</session-type>! <transaction-type>Container</transaction-type>! </session>!</enterprise-beans>!<assembly-descriptor>! <container-transaction>! <method>! <ejb-name>BankSB</ejb-name>! <method-name>*</method-name>! </container-transaction>!</assembly-descriptor>!

Page 9: Developer Productivity with Forge, Java EE 6 and Arquillian

EJB 2.X CLIENT VIEW

try {!! Context ctx = new InitialContext();! BankLocalHome home = (BankLocalHome)

!ctx.lookup(“java:comp/env/ejb/bank”);! BankLocal bank = home.create();! bank.deposit(2500.00, new Account(12345)); !} catch (Exception ex) {!! // …!}!

Page 10: Developer Productivity with Forge, Java EE 6 and Arquillian

J2EE

EJB

#fail #fail

#fail

Page 11: Developer Productivity with Forge, Java EE 6 and Arquillian

? DEVELOPER PRODUCTIVITY

WHAT IF?

Faster Start-Up Times

Easier Integration Testing

80% Less Configuration

50% Less Code

25% Less Classes

Rapid Application Tooling

Vendor Agnostic

Open eco-system

* Based on a Sample POJO/JPA/REST Based Application

Page 12: Developer Productivity with Forge, Java EE 6 and Arquillian

¡ Resource injection in JEE5 § @EJB, @Resource, @PersistenceContext, § @PersistenceUnit

¡ Into Container Components: § Servlets, JSF backing beans and other EJBs

¡ Progress but still Problems § No POJOs § Cannot inject DAOs or helper classes that were not written as

EJBs § Hard to integrate anything but strictly business components

JAVA EE 5

Page 13: Developer Productivity with Forge, Java EE 6 and Arquillian

Java EE 6

Page 14: Developer Productivity with Forge, Java EE 6 and Arquillian

EJB 3.1 SESSION BEAN O

PTION

AL!

Page 15: Developer Productivity with Forge, Java EE 6 and Arquillian

JAVA EE 6 DEPLOYMENT DESCRIPTOR

Page 16: Developer Productivity with Forge, Java EE 6 and Arquillian

EJB 3.1 CLIENT VIEW

@EJB BankLocal bank;!!public void makeDeposit() !{! bank.deposit(2500.00, new Account(12345));!}!

Page 17: Developer Productivity with Forge, Java EE 6 and Arquillian

¡ Configuration by exception with sensible defaults §  Security permissions defaults to UNCHECKED §  Transaction type defaults to CONTAINER §  Transaction attribute defaults to REQUIRED

¡ Use Annotations §  To choose explicitly (recommended) §  To override defaults

¡ Deployment descriptor is no longer required §  But can override above configurations

HOW DID THEY DO THAT?

Page 18: Developer Productivity with Forge, Java EE 6 and Arquillian

¡  Optional Local Interface ¡  Simplified Packaging ¡  EJB-Lite ¡  Portable JNDI Naming ¡  Simple Component Testing

EASE-OF-USE IMPROVEMENTS

Page 19: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 20: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 21: Developer Productivity with Forge, Java EE 6 and Arquillian

Loose Coupling

STRONG TYPING

Page 22: Developer Productivity with Forge, Java EE 6 and Arquillian

DI (@Inject) JSR 330 javax.inject! @Inject!@Named!@Singleton!@Qualifier!@Scope!

CDI JSR 299 javax.enterprise.context!!

Alternatives!Producers!Scopes!Stereotypes!Decorators!Extensions!

DEPENDENCY INJECTION IN TWO PARTS

Page 23: Developer Productivity with Forge, Java EE 6 and Arquillian

INJECTION 101

public class StatusUpdater {!! @Inject! private UrlShortener shortener;!! public void post (String username, String status) {! !String sStatus = shortener.shortenUrls(status);!

!System.out.println(username + “ said “ + sStatus);! }!!}! !

Page 24: Developer Productivity with Forge, Java EE 6 and Arquillian

WH

AT MA

KES

CD

I UN

IQU

E?

STANDARD TYPE SAFE

EXTENSIBLE

Page 25: Developer Productivity with Forge, Java EE 6 and Arquillian

QUALIFIED INJECTION OF RESOURCES

@Path(“/items”) @ManagedBean!public class ItemRestService {!! @Inject @NumberOfDigits(Digits.EIGHT)! private NumberGenerator numberGenerator;! …!}!!!@WebServlet(urlPatterns = “/itemServlet”)!public class ItemServlet extends HttpServlet {!! @Inject @NumberOfDigits(Digits.THIRTEEN)! private NumberGenerator numberGenerator;! …!}!

Strong Typing No Strings

Loose Coupling No Reference to Implementation

Page 26: Developer Productivity with Forge, Java EE 6 and Arquillian

DEFINING THE QUALIFIER

!@Qualifier!@Retention(RUNTIME)!@Target({FIELD, TYPE, METHOD, PARAMETER})!public @interface NumberOfDigits {!!

!Digits value();!!}!!public enum Digits {!

!TWO, EIGHT, TEN, THIRTEEN!!}!!

Page 27: Developer Productivity with Forge, Java EE 6 and Arquillian

DEFINING THE BEANS @NumberOfDigits(Digits.EIGHT)!public class IssnGenerator implements NumberGenerator {!! public String generateNumber() {! return “8-” + nextNumber();! }!! // …!}!!@NumberOfDigits(Digits.THIRTEEN)!public class IsbnGenerator implements NumberGenerator {!! public String generateNumber() {! return “13-84356-” + nextNumber();! }!! // …!}!

Page 28: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 29: Developer Productivity with Forge, Java EE 6 and Arquillian

CDI - EXTENSIBLE BY DESIGN

¡ Many community projects of extensions: § Seam 3, CODI, Cambridge Technology Partners

¡ These multiple projects merging to deliver a vendor-neutral open ecosystem for extensions

named DeltaSpike.

¡  Hosted on Apache. Works on all Java EE 6 servers

CDISource+ + DeltaSpike

Page 30: Developer Productivity with Forge, Java EE 6 and Arquillian

Servlet Container

(After lots of tweaking)

Java EE6 vs.

Page 31: Developer Productivity with Forge, Java EE 6 and Arquillian

? DEVELOPER PRODUCTIVITY

- WHAT IF?

Faster Start-Up Times

Easier Integration Testing

80% Less Configuration

50% Less Code

25% Less Classes

Rapid Application Tooling

Vendor Agnostic

Open eco-system

* Based on a Sample POJO/JPA/REST Based Application

Page 32: Developer Productivity with Forge, Java EE 6 and Arquillian

¡  Startup Times w/ an Application Deployed

§  JBoss AS 7.10 ~ 2 seconds §  GlassFish v3 ~ 4 seconds §  Tomcat 6 + Spring ~ 4 seconds § Java EE 6 War File < 100kb

ISN’T JAVA EE TOO SLOW & FAT?

Page 33: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 34: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 35: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 36: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 37: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 38: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 39: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 40: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 41: Developer Productivity with Forge, Java EE 6 and Arquillian

MEMORY COMPARISON

Page 42: Developer Productivity with Forge, Java EE 6 and Arquillian

JAVA EE 5

Page 43: Developer Productivity with Forge, Java EE 6 and Arquillian

JAVA EE 6

Page 44: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 45: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 46: Developer Productivity with Forge, Java EE 6 and Arquillian

JAVA EE 6 SPECIFICATION

No Where in the Specification does it

mention that App Servers must be slow

and complex.

Page 47: Developer Productivity with Forge, Java EE 6 and Arquillian

? DEVELOPER PRODUCTIVITY

- WHAT IF?

Faster Start-Up Times

Easier Integration Testing

80% Less Configuration

50% Less Code

25% Less Classes

Rapid Application Tooling

Vendor Agnostic

Open eco-system

* Based on a Sample POJO/JPA/REST Based Application

Page 48: Developer Productivity with Forge, Java EE 6 and Arquillian

Start up Costs Gotchas Integration Details

Page 49: Developer Productivity with Forge, Java EE 6 and Arquillian

I need one of those widgets for

a marketing meeting in an

hour.

TYPIC

AL D

EVELOP

ER

NIG

HTM

AR

E

Page 50: Developer Productivity with Forge, Java EE 6 and Arquillian

CARVE OUT A PROJECT WORK IT INTO SHAPE

Page 51: Developer Productivity with Forge, Java EE 6 and Arquillian

Let’s get started

Page 52: Developer Productivity with Forge, Java EE 6 and Arquillian

JAVA EE IN MINUTES

Page 53: Developer Productivity with Forge, Java EE 6 and Arquillian

FORGE LEVERAGES FACETS & PLUGINS

Project

Java Facet Web Facet X Facet

Plugin A Plugin B Plugin X...

Page 54: Developer Productivity with Forge, Java EE 6 and Arquillian

Demonstration of Forge and Java EE Application

Page 55: Developer Productivity with Forge, Java EE 6 and Arquillian

GETS YOU STARTED QUICKLY

HANDLES “GOTCHAS”

ADDS & ACTIVATES

TECH VIA

PLUGINS

Handles details, gives you perspective … and time

Page 56: Developer Productivity with Forge, Java EE 6 and Arquillian

TESTING JAVA EE USED TO BE DIFFICULT

Page 57: Developer Productivity with Forge, Java EE 6 and Arquillian

MANY STEPS REQUIRED FOR MODIFYING CODE PRODUCTIVELY

Page 58: Developer Productivity with Forge, Java EE 6 and Arquillian

ARQUILLIAN REMOVES THE STEPS

Page 59: Developer Productivity with Forge, Java EE 6 and Arquillian

ARQUILLIAN

Page 60: Developer Productivity with Forge, Java EE 6 and Arquillian
Page 61: Developer Productivity with Forge, Java EE 6 and Arquillian

ARQUILLIAN REMOVES THE STEPS

SEE MORE AT コンテナでテストをまわせ!

Page 62: Developer Productivity with Forge, Java EE 6 and Arquillian

A powerful programming model.

Less code, greater portability.

Optimized for productivity & automation.

CDI and Forge plugins.

Absolutely. You saw it first hand.

Page 63: Developer Productivity with Forge, Java EE 6 and Arquillian

REFERENCES

¡  Max Andersen §  “See Context & Dependency Injection from Java EE 6 in

Action” §  http://www.slideshare.net/maxandersen/see-context-

dependency-injection-from-java-ee-6-in-action

¡  Pete Muir §  “CDI in Action”

¡ Andrew Lee Rubinger §  “The Death of Slow” §  http://www.slideshare.net/ALRubinger/devoxx-2011-

jboss-as7-death-of-the-slow

¡ Bert Ertman §  EJB 3.1 §  http://www.slideshare.net/stephanj/ejb-31-by-bert-

ertman

¡  Antonio Goncalves §  “To inject or not to inject: CDI is the question” §  http://www.slideshare.net/agoncal/to-inject-or-not-to-inject-cdi-is-the-

question