+ All Categories
Home > Documents > Enterprise JavaBeans(TM EJB(TM) 3.1 Technology...

Enterprise JavaBeans(TM EJB(TM) 3.1 Technology...

Date post: 04-Oct-2020
Category:
Upload: others
View: 9 times
Download: 0 times
Share this document with a friend
33
1 Enterprise JavaBeans( TM ) EJB( TM ) 3.1 Technology Overview 1 Kenneth Saks EJB 3.1 Specification Lead
Transcript
Page 1: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

1

Enterprise JavaBeans(TM) EJB(TM) 3.1 Technology

Overview

1

Kenneth SaksEJB 3.1 Specification Lead

Page 2: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

2

Agenda

• Introduction• New functionality

Page 3: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

3

EJB 3.1 Specification

• Goals> Continued focus on ease-of-use> New features

• JSR (Java Specification Request) 318> Expert Group Formed – August 2007> Public Draft – October 2008> Proposed Final Draft – March 2009> Final Specification – December 2009

Page 4: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

4

Ease of Use Improvements

• Optional Local Business Interfaces• Simplified Packaging• EJB 3.1 “Lite” API• Portable JNDI Names• Simple Component Testing

Page 5: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

5

Session Bean with Local Business Interface

<<interface>com.acme.Hello

String sayHello()

com.acme.HelloBean

public String sayHello() { ... }

@EJB private Hello h;

...

h.sayHello();

HelloBean Client

Page 6: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

6

Session Bean with “No-interface” View

@Stateless

public class HelloBean {

public String sayHello(String msg) {

return “Hello “ + msg;

}

}

Page 7: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

7

No-interface View Client

@EJB HelloBean h;

...

h.sayHello(“bob”);

Page 8: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

8

JavaTM EE Platform 5 Packaging

foo.ear

WEB-INF/web.xmlWEB-INF/classes/ com/acme/FooServlet.classWEB-INF/classes com/acme/Foo.class

foo_web.war

com/acme/FooBean.classcom/acme/Foo.class

foo_ejb.jar

foo.ear

lib/foo_common.jar

com/acme/Foo.class

WEB-INF/web.xmlWEB-INF/classes/ com/acme/FooServlet.class

foo_web.war

com/acme/FooBean.class

foo_ejb.jar

OR

Page 9: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

9

foo.warWEB-INF/classes/com/acme/ FooServlet.class FooBean.class

Simplified Packaging

Page 10: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

10

EJB 3.1 “Lite”

Lite • Local Session Beans• CMT / BMT• Declarative Security• Interceptors

** Web Profile also includes Java Persistence API

Full = Lite + :• Message-Driven Beans

• Web Service Endpoints

• 2.x / 3.x Remote view

• RMI-IIOP Interoperability

• Timer Service

• Async method calls

• 2.x Local view

• CMP / BMP Entity Beans

Page 11: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

11

Portable EJB JNDI Names

Each session bean gets the following entries :

• Globally unique namejava:global[/<app-name>]/<module-name>/<ejb-name>

• Unique name within same application java:app/<module-name>/<ejb-name>

• Unique name within defining modulejava:module/<ejb-name>

Page 12: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

12

Session Bean @Stateless

public class HelloBean implements Hello {

public String sayHello(String msg) {

return “Hello “ + msg;

}

}

If deployed as hello.jar, JNDI entries are:

java:global/hello/HelloBeanjava:app/hello/HelloBeanjava:module/HelloBean

Page 13: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

13

EJB Component Testing

• It's too hard to test EJB components, especially Local session beans> Forced to go through Remote facade or Web tier> Separate processes needed for server and client

• Some support for client-side EJB component execution exists, but...> Not present in all implementations> No standard behavior for bootstrapping, component

discovery, shutdown etc.

Page 14: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

14

Simple Testing : Session Bean

@Stateless

@Local(Bank.class)

public class BankBean implements Bank {

@PersistenceContext EntityManager accountDB;

public String createAccount(AcctDetails d)

{ … }

public void removeAccount(String acctID)

{ … }

Page 15: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

15

Embeddable APIpublic class BankTester {

public static void main(String[] args) {

EJBContainer container =

EJBContainer.createEJBContainer();

// Acquire Local EJB reference

Bank bank = (Bank) container.getContext().

lookup(“java:global/bank/BankBean”);

testAccountCreation(bank);

container.close();

Page 16: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

16

Test Client Execution

% java -classpath bankClient.jar :

bank.jar :

javaee.jar :

<vendor_rt>.jar

com.acme.BankTester

Page 17: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

17

New Features

• Singletons• Startup / Shutdown callbacks• Automatic timer creation / Calendar-based

timers• Asynchronous session bean invocations

Page 18: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

18

Singletons

• New session bean component type> Provides easy sharing of state within application> Designed for concurrent access> One bean instance per singleton component per

process• Lots in common with stateless / stateful beans

> Client views (Local, Remote, Web Service) > CMT / BMT> Container services: resource managers, timer

service, method authorization, etc.

Page 19: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

19

Simple Singleton @Singleton

public class SharedBean {

private SharedData shared;

@PostConstruct

private void init() {

shared = ...;

}

public int getXYZ() {

return shared.xyz;

}

Page 20: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

20

Singleton Client

@Stateless

public class FooBean {

// Inject reference to Singleton bean

@EJB

private SharedBean shared;

public void foo() {

int xyz = shared.getXYZ();

...

}

Page 21: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

21

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

Page 22: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

22

Startup / Shutdown Callbacks@Singleton

@Startup

public class StartupBean {

@PostConstruct

private void onStartup() { … }

@PreDestroy

private void onShutdown() { … }

}

Page 23: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

23

Calendar Expression Examples

• “The last Thursday in November at 2 p.m.”> (hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”)

• “Every day at 3:15 a.m. U.S. Eastern Time”> (minute=”15”, hour=”3”, timezone=”America/New_York”)

• “Every twenty seconds”> (second=”*/20”, minute=”*”, hour=”*”)

Page 24: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

24

Automatic Timer Creation@Stateless

public class BankBean {

@PersistenceContext EntityManager accountDB;

@Resource javax.mail.Session mailSession;

// Callback the last day of each month at 8 a.m.

@Schedule(hour=”8”, dayOfMonth=”Last”)

void sendMonthlyBankStatements() {

...

}

}

Page 25: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

25

Asynchronous Session Bean Invocations• Simple way to add Remote or Local

asynchrony to enterprise bean applications• “Fire and Forget” or async results via Future<V>

• Best effort delivery – persistent delivery guarantees are not required by spec

• Available for Stateful, Stateless, Singleton beans

Page 26: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

26

Local Concurrent Computation

@Stateless public class DocBean {

@PersistenceContext EntityManager resultsDB;

@EJB DocBean myself;

public void processDocument(Document document) {

myself.doAnalysisA(document);

myself.doAnalysisB(document);

}

@Asynchronous public void doAnalysisA(Document d) {...}

@Asynchronous public void doAnalysisB(Document d) {...}

Page 27: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

27

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

Page 28: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

28

Asynchronous Results -- Client

@EJB Processor processor;

Task task = new Task(...);

Future<int> computeTask = processor.compute(task);

...

int result = computeTask.get();

Page 29: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

29

Asynchronous Results@Stateless

public class ProcessorBean implements Processor {

@PersistenceContext EntityManager db;

@Asynchronous

public Future<int> compute(Task t) {

// perform computation

int result = ...;

return new javax.ejb.AsyncResult<int>(result);

}

Page 30: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

30

ResourcesJava EE 6 and GlassFish v3

Java EE 6

• Java EE 6 Homejava.sun.com/javaee

• Java EE 6 Downloadsjava.sun.com/javaee/downloads

• Upcoming Trainingjava.sun.com/javaee/support/training

• Sun GlassFish Enterprise Server v3 Home

www.sun.com/glassfishv3

• Community Pageglassfish.org

• The Aquarium Blogblogs.sun.com/theaquarium

• White Papers/Webinarshttp://www.sun.com/glassfish/resources

GlassFish

Page 31: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

31

Java EE6 Learning Path

Developing WebApplications using JSF Technologies

(SL-340-EE6)

Sun CertifiedJava Programmer*

Business ComponentDevelopment with EJB Technology

(SL-355-EE6)

Sun CertifiedJSF Developer

Sun CertifiedServlet and JSP

Developer

Building DatabaseDriven Applications

with JPA

(SL-370-EE6)

Busi

ness

App

Dev

elop

erW

eb S

ervi

ces

Dev

elop

erEn

terp

rise

Web

Dev

elop

er

Web ComponentDevelopment with Servlet and JSP

(SL-314-EE6)

Developing WebServices Using

Java Technology

(DWS-4050-EE6)Developing

Applications for the

Java EE Platform

(FJ-310-EE6)

Sun Certified Web

Services Developer

Sun Certified

JPA Developer

Sun Certified

EJB Developer

Developing Secure

Java Web Services

(DWS-4120-EE6)

Training Certifications

Page 32: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

32

Updated EJB 3.1 Training & Certification• Completely updated Training course for EJB 3.1

> Business Component Development with EJB Technology (SL-355-EE6) – 3 Days

• Includes coverage of:> Implement business-tier functionality using EJB technology > Best practices and other advanced issues in business

component development with EJB technology > Integrate an EJB technology-based application using the Java

Messaging Service API > Transactions, Security and more

• Register your interest!> https://dct.sun.com/dct/forms/reg_us_1611_480_0.jsp

Page 33: Enterprise JavaBeans(TM EJB(TM) 3.1 Technology Overviewdev.cs.ovgu.de/java/javaee-6.0/whatSnew/Session4EJB31.pdfEnterprise Web Developer Web Component Development with Servlet and

33

Enterprise JavaBeans(TM) EJB(TM) 3.1 Technology

Overview

33

Kenneth [email protected]


Recommended