EJB 3.1 by Bert Ertman
Upcoming SlideShare
Loading in...5
×
 

EJB 3.1 by Bert Ertman

on

  • 5,538 views

With the official release of Java EE 6 in December 2009 a new version of the Enterprise JavaBeans specification also saw the light. Enterprise JavaBeans is an architecture for the development and ...

With the official release of Java EE 6 in December 2009 a new version of the Enterprise JavaBeans specification also saw the light. Enterprise JavaBeans is an architecture for the development and deployment of component-based business applications. Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and concurrent.

While a lot of faithful EJB developer's have been scared away from the specification and some of its unfortunate implementations in the past five years, EJB 3.1 has all the ingredients that make for a successful lightweight component based implementation. At last a decent implementation of a server-side component framework as part of the Java EE specification. This no longer makes you dependent on rebel frameworks such as the Spring framework.

EJB 3.1 continues down the path where EJB 3.0 left us off. The purpose of the Enterprise JavaBeans 3.1 specification is to further simplify the EJB architecture by reducing its complexity from the developer's point of view, while also adding new functionality in response to the needs of the community. Although the Java Persistence API was developed within EJB 3.0, it now evolves under a separate JSR rather than within EJB 3.1 and will therefore not be covered in this presentation.

This presentation will mainly focus on the new features introduced by EJB 3.1 and the basics of EJB are only covered very briefly. Topics covered include: EJB Lite, simple packaging, no-interface local view, portable JNDI names, Embeddable API, Startup/shutdown callbacks, Singleton beans, the new and improved timer and scheduler component, Async invocations, and REST integration.

Statistics

Views

Total Views
5,538
Views on SlideShare
5,283
Embed Views
255

Actions

Likes
9
Downloads
450
Comments
3

6 Embeds 255

http://www.bejug.org 224
http://java-tech-review.blogspot.com 27
http://www.bejug.be 1
http://bejug.org 1
http://webcache.googleusercontent.com 1
http://java-tech-review.blogspot.in 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Excellent stuff
    Are you sure you want to
    Your message goes here
    Processing…
  • is time to migrate from spring
    Are you sure you want to
    Your message goes here
    Processing…
  • Excellent material to get an overview of the features of ejb 3.1.Keep the good work going....
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

EJB 3.1 by Bert Ertman EJB 3.1 by Bert Ertman Presentation Transcript

  • Enterprise JavaBeans 3.1 Bert Ertman berte@infosupport.com
  • Enterprise JavaBeans 3.1 Bert  Ertman Technology  Manager Competence  Center  Java Co-­‐lead  NLJUG,  Sun/Oracle  recognized  Java  Champion Author  and  editorial  board  member   for  Dutch  Java  Magazine E-­‐mail:  berte@infosupport.com Follow  me  on  TwiLer:  @BertErtman
  • J2EE #fail #fail EJB #fail
  • BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Agenda • EJB 3: short recap • What’s new in EJB 3.1 • Ease-of-use improvements • EJB Lite • New features BeJUG Evening Session - Enterprise JavaBeans 3.1
  • The 3 minutes introduction to EJB 3 BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 2.x Session Bean BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 2.x Deployment Descriptor BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 2.x Client View BeJUG Evening Session - Enterprise JavaBeans 3.1
  • blissful ignorance or painful truth of reality? BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 3.x Session Bean BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 3.x Deployment Descriptor BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 3.x Client View BeJUG Evening Session - Enterprise JavaBeans 3.1
  • How did they do that? • Configuration by exception with sensible defaults • Transaction type defaults to CONTAINER • Transaction attribute defaults to REQUIRED • Security permissions defaults to UNCHECKED • Use Annotations • To choose explicitly (recommended) • To override defaults • Deployment descriptor is no longer required • But can override above configurations BeJUG Evening Session - Enterprise JavaBeans 3.1
  • EJB 3 Programming Model 2. Invokes middleware services: Lifecycle mgmt, trx mgmt, Persistence, security, etc. 1. Call a method 4. Return from call 3. Invoke corresponding method on bean class 4. Return outcome BeJUG Evening Session - Enterprise JavaBeans 3.1
  • So, what’s new in EJB 3.1? BeJUG Evening Session - Enterprise JavaBeans 3.1
  • EJB 3.1 • Separate JSR (318) • Evolve separately from JPA • Focus on ease-of-use • Expert group formed - Aug 2007 • Final release - December 2009 BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Ease-of-use improvements • Optional Local Business interface • Simplified packaging • EJB-Lite • Portable JNDI names • Simple component testing BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: Session Bean with Local Business interface BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: Session Bean without Local Business interface BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Simplified packaging • Goal is to remove artificial packaging restrictions • All resources are shared within .war • Web application APIs are not exposed to EJB components • ejb-jar.xml is still optional • If needed, placed in WEB-INF BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Java EE 5 packaging BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Simplified packaging BeJUG Evening Session - Enterprise JavaBeans 3.1
  • EJB 3.1 lite BeJUG Evening Session - Enterprise JavaBeans 3.1
  • EJB 3.1 “Lite” • Small subset of EJB 3.1 API required by Java EE 6 Web Profile • Broadens the availability of EJB technology without losing portability BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Specs are ok: Blond hair, blue eyes, red lips, EJB HEAVY pink thong... BUT... EJB lite BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Lite vs Full • EJB Lite: • Full = Lite + ... • Local Session Beans • Message Driven Beans • CMT / BMT • EJB Web Service Endpoints • Declarative Security • Interceptors • RMI-IIOP Interop • Web Profile also includes • 2.x / 3.x Remote view JPA 2.0 • 2.x Local view • Timer Service • CMP / BMP Entities BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Portable global JNDI names • Spec-defined lookup names for Remote and Local session beans • Three main goals : • Simplify intra-application Local Session lookups • Simplify mapping of cross-application Remote session bean dependencies • Improve portability of Remote Java clients BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Portable naming syntax • Each session bean gets the following entries : • Globally unique name: java:global[/<app-name>]/<module-name>/<ejb-name> • Unique name within same application: java:app[/<module-name>]/<ejb-name> • Unique name within defining module: java:module/<ejb-name> BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: remote session bean with remote client Bean deployed as part of hello.jar BeJUG Evening Session - Enterprise JavaBeans 3.1
  • EJB component testing • Session Beans were always hard to test • Unit-testing was possible, but what about container resources? • Automated integration testing required • Now supported with in-process EJB container BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Embeddable API • Portable API for running EJB components in same process as client code • Same component behavior / life cycle as server-side • CMT/BMT, injection, threading guarantees, ... • “Single Application” model • Only required to support 3.1 “Lite” API • Vendors can optionally support additional functionality BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: Embeddable API BeJUG Evening Session - Enterprise JavaBeans 3.1
  • New features • Singletons • Startup / shutdown callbacks • Calendar-based timers / automatic timer creation • Asynchronous invocations • JAX-RS integration BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Singletons • One instance per application, per JVM • Not intended to provide cluster-wide singleton • Fits into existing dependency injection architecture • Access through @EJB or lookup • Intended for sharing data within entire application (not just EJB components) • Designed for concurrent access BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Lifecycle of a singleton session bean Does not exist Class.newInstance() @PreDestroy Dependency injections @PostConstruct Method-ready Business method BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: simple singleton usage BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Singleton concurrency options • Single threaded (default) • For consistency with all existing bean types • Container Managed Concurrency • Control access via method-level locking metadata • Bean Managed Concurrency • All concurrent invocations have access to bean instance BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Container Managed Concurrency • Concurrent access determined by method- level locking metadata • READ lock: allow any number of concurrent accesses to bean instance • WRITE lock (default): ensure single-threaded bean instance access • Incoming invocations are blocked by container until the necessary lock can be acquired • … or until an optional timeout has been reached BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: read-only singleton (container managed) BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: read-mostly singleton (container managed) BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Bean Managed Concurrency • All incoming invocations allowed to access bean instance concurrently • Bean developer is solely responsible for maintaining integrity of instance state • Can use synchronization primitives such as synchronized, volatile BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: bean managed concurrency BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Application Startup/shutdown callbacks • Uses singleton bean life cycle • Full container services available • Container-managed transactions • Entity Managers, Timer Service, etc. • Startup callback: • @Startup and @PostConstruct • Shutdown callback: • @PreDestroy BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: startup/shutdown callbacks BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Timer Service enhancements • Calendar-based timeouts • Automatic timer creation • Non-persistent timers BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: EJB 3.0 use of Timer Service BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Some (hard) lessons learned... • Difficult to configure calendar-based events using only relative time units • How to register the timer in the first place? • Typical container events not a great fit; they happen every time application initializes and in every server instance • Burden is on developer to figure out if timer already exists • No way to guarantee that only one is created per cluster BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Calendar based timeouts • Cron-like semantics with improved syntax • Can be created programmatically or automatically • Named attributes: • second, minute, hour (default = “0”) • dayOfMonth, month, dayOfWeek, year (default = “*”) • Relative to optionally specified time zone BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Calendar expression examples • The last Thursday in November at 2 pm: • (hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”) • Every day at 3:15 am U.S. Eastern Time: • (minute=”15”, hour=”3”, timezone=”America/New_York”) • Every twenty seconds: • (second=”*/20”, minute=”*”, hour=”*”) BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Automatic Timer creation • Container creates timer automatically when application is being deployed: BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: non-persistent timers BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Simple asynchronous operations • Use metadata to mark a Local/Remote business method as asynchronous • Container returns control to client before executing business method • No separate API to learn BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: local concurrent computation BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Asynchronous results • Based on java.util.concurrent.Future • Result value is returned via Future.get() • Also supports Future.get(long, TimeUnit) • Client exception wrapped by ExecutionException • getCause() returns same exception as would have been thrown by a synchronous invocation BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: Asynchronous operation result AsyncResult<V> implements Future<V> BeJUG Evening Session - Enterprise JavaBeans 3.1
  • JAX-RS support • Java API for XML RESTful Services • JSR-311 annotations can be used within Stateless Session Beans BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Example: Session Bean as JAX-RS resource BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Rod, I am your father
  • Spring vs Java EE 6 “Now that Java EE 6 is here…do I still need those proprietary frameworks?” Lean Java EE 6 without Spring “Java EE 6 provides similar benefits without tying you to a non-standard solution”
  • BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Soon, in a store near you... Bert Ertman “I wrote this book for developers who ha architects and ve grown increasin frustrated with that gly annoying rebel framework called Sp you can do to impl ring. It shows what ement cleaner, m productive and ab ore ove all STANDARD code for developm en web applications.” t of first class Java with EJB !!! BeJUG Evening Session - Enterprise JavaBeans 3.1
  • Questions? BeJUG Evening Session - Enterprise JavaBeans 3.1