- Jeffrey Veen
CmpE 275
Section: Java EE (JEE) - Enterprise Java Beans
2
3/4/14
Singe JVM/Process
Remote: Container + Object
getFirstName()
Requesting
Object
getLasttName()
Person
getAddressName()
getID()
id : Long
lastName : String
firstName: String
4
3/4/14
! Framework
" Standards and software to
build applications
" Includes tools for transactions,
database access, security, etc.
5
3/4/14
(JSR
(JSR
(JSR
(JSR
318)
317)
914)
907)
Web Services
!
!
!
Web Application
(JSR 224)
(JSR 311)
(JSR 222)
(JSR 315)
(JSR 245)
(JSR 314)
Misc.
!
6
3/4/14
JavaBean
! POJO plus naming, metadata, and access rules
" Getter/Setter methods:
void setName(String name)
void setCool(boolean yes)
String getName()
boolean isCool()
7
3/4/14
Lifecycle management
Transaction support
Security
Discovery
8
3/4/14
EJB Restrictions
Static fields for read & write (read only okay - final)
Java UI classes (awt, swing, etc)
Prompt for information from the stdin or redirect stdin, stdout, stderr
Create or manage threads
" Thread synchronization primitives
!
!
!
!
!
!
3/4/14
EJB Container
(from pool)
Transaction
JNDI (for DI)
Timer
Bean.method
Security
11
3/4/14
! Method execution
" invoke interceptors (declared by @AroundInvoke or XML)
" try { execute bean.method(); }
catch (Exception e) { handle(TX policy); }
finally { after TX policy }
12
3/4/14
Message-driven beans
! Decouple direct interaction (delay response)
Entities
! Persistence
Note all EJBs are classes, all classes are not EJBs
13
3/4/14
EJB: Stateless
!
!
v2.x:
v3.x
Annotations:
@PostConstruct,
@PreDestroy
Note from the image (EJB 2.x) we can see the evolution of the EJB specification from
a required method-based framework to a casual (use if needed) design (v3.1) to a
more developer friendly through annotations to designate lifecycle methods. Does this
really created separation of the lifecycle of an object?
ejbCreate(), ejbRemove() are EJB 2.x methods that in EJB 3.x are replaced by lifecycle annotation
image: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/images/ejbcon-statefulSessionBeanLifeCycle.gif
14
3/4/14
@Local
EchoPointLocal
@Remote
EchoPointRemote
@Stateless
public class EchoPointEJB implements EchoPointLocal, EchoPointRemote {
16
3/4/14
EJB: Stateful
v3.x lifecycle
@PostConstruct
@PreDestroy
@PrePassivate
@PostActivate
v2.x ejbLC()
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/images/ejbcon-statefulSessionBeanLifeCycle.gif
17
3/4/14
Stateful passivation
Unlike stateless which can be limited to the number
of instances (pooled), a stateful is created per
client, which can create a memory burden on the
server.
The lifecycle includes passivation and activation of
a stateful instance
! Invoked when the server is experiencing heavy memory
usage or the instance is idle for a period of time
(configurable)
! Data contained in the instance is saved to disk or database
! A passivated object is activated before removing
(More on lifecycles in the next lecture)
18
3/4/14
@Local
AccountCreatorLocal
@Remote
AccountCreatorRemote
Not required
in EJB v3.1
@Stateful
public class AccountCreatorEJB implements AccountCreatorRemote {
. . .
19
3/4/14
@Stateful
public class AccountCreatorEJB implements AccountCreatorRemote {
private Account acct;
private Address addr;
public void addAccount(Account acct) {
this.acct = acct;
}
public void addAddress(AccountAddress addr) {
this.addr = addr;
}
@Remove
public void cancelCreation() {
acct = null;
}
. . .
20
3/4/14
. . .
21
3/4/14
Usage differences
22
3/4/14
23
3/4/14
24
3/4/14
Motivation
! Manage information that does not lend itself to copies.
" E.g., Caching across tiers
@Lock(READ)
public String getData(String key) {}
25
3/4/14
! Annotation: @Timeout
" Specify a the callback method within a stateless or message beans
" Container invoked method
" Transactional - can rollback
! Weaknesses
" Programmatic scheduling of tasks only (v3.0)
3/4/14
27
3/4/14
@Schedule(expression="0 0 0 1 * * *")
seconds, minutes as
hour as
dayOfMonth as
month as
dayOfWeek as
year as
0-59
0-23
1-31
1-12
0-7 or Sun,
yyyy
@Timeout
public void TimeHandler(Timer timer)
wildcard
28
3/4/14
Deployment
29
3/4/14
Configuration by exception
EE 5 (EJB 3.0) introduced many
changes we have seen session
declarations (annotations)
The second significant simplification is
in deployments
!deployment descriptors are optional
We will revisit this more when we talk about interceptors and lifecycles
30
3/4/14
Optional since J EE 5
Contains a complete application (beans + web)
Resources META-INF/ra.xml
EJBs META-INF/ejb-jar.xml, META-INF/persistence.xml
" Annotations have simplified what is placed in the ejb-jar.xml file
! Web META-INF/web.xml
" Servlet 3.0 fragments
31
3/4/14
EAR (v3.1)
WAR
WEB-INF
" EJBs
web.xml
ejb-jar.xml
classes
EJBs
! WAR
" WEB-INF
web.xml
JSP files
32
3/4/14
Java EE 5 and 6 (EJB 3.0 and 3.1) deployment has been greatly
simplified through the use of annotations
! Deployment configuration files (Deployment Descriptors) are optional for
session beans
Deployment Descriptors
! XML file defining what is being deployed
" Jars
" Declarative transaction statements for methods
" Security
3/4/14
resources used
security and transaction levels
interceptors and lifecycle methods
persistence
queues
For instance
! @stateless maps to <session-type>stateless</session-type>
34
3/4/14
35
3/4/14
36
3/4/14
JBoss Setup
Install JBoss AS (6.x, 7.0, 7.1)
! Choose an easy to get to location
" E.g., /opt, /usr/local
37
3/4/14
Instructions
!
!
!
!
Is that it?
38
3/4/14
Console
!http://localhost:9990
!Create user first: bin/add-user.sh
40
3/4/14
41
3/4/14
References
Tutorials and References
! http://download.oracle.com/javaee/6/tutorial/doc/
javaeetutorial6.pdf
! http://www.perfdynamics.com/Test/gcaprules.html
! http://www.oracle.com/technetwork/java/javaee/documentation
http://community.jboss.org/wiki/EJB31inAS600M2
JBoss 7
!
!
http://www.mastertheboss.com/jboss-application-server.html
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using
+JNDI
Source code
! Apache OpenEJB (supports EJB 3.0) - http://openejb.apache.org/
" Start exploring from container/openejb-core/src/main/java/org/apache/openejb/core
42
3/4/14
Reading
Books
!
!
!
!
!
Pattern Books
! Java Enterprise Design Patterns, Grand (2002)
! Core J2EE Patterns 2nd Ed., Alur, Crupi, Malks (2003)
! EJB Design Patterns, Marinescu (2002)
43
3/4/14
Backup slides:
1. Example of the effects of fine grain processing
2. Use of proxies to decouple implementation
3. JBoss 6.x notes
44
3/4/14
2500.0
2000.0
1500.0
No Wait
.5 Wait
.25 Wait
1000.0
500.0
0.0
1
112
223
334
445
556
667
778
889
1000
Milliseconds
Files transferred
46
Copyright 2011, Gash
Presentation
Business
Persistence
Database
47
3/4/14
Interface (cont)
Beyond simple decoupling, interfaces
are the fundamental concept behind
scalable and strategic patterns
!Why? What is it about this simple pattern
that is so neat?
49
3/4/14
50
Copyright 2011, Gash
Request
Accept
(async)
Process
(async)
Dispatch
Respond
(handler(reply))
op + handler
reply
51
3/4/14
Client
startSession(u,c)
Authentication
Transaction
doTask()
begin()
validate()
Persistence
find/save()
end()
endSession(u)
Service
(Interface)
Base
Impl
54
Copyright 2011, Gash
55
Copyright 2011, Gash
ServiceBase
Client
startSession(u,c)
Authentication
Transaction
doTask()
begin()
Core functionality
isolated from service /
communication
infrastructure
Functionality
MyService
validate()
Persistence
delegates doTask()
end()
endSession(u)
56
Copyright 2011, Gash
Discovery
Remote object
Isolate technology
Local object
Client
Service
Framework
(w/ predefined
interfaces to a set of
custom services)
Authentication
Transaction
Persistence
57
58
3/4/14
$JBOSS_HOME/server
! Runtime configurations
" Defines what services are started (e.g., JMS)
" You should use default
! $JBOSS_HOME/server/default/deploy
" Where you copy your applications (jars) to you deploy
! $JBOSS_HOME/server/default/deploy/message
59
3/4/14
Old Slides
61
3/4/14
! Exception handling
" Connection retries, failover (location transparency)
" Translate communication exceptions to domain
exceptions
62
3/4/14
EJB v1
!
1998-1999
"
"
"
"
EJB v2
!
EJB v3
!
!
2006 -
Simplify development
"
Examples
2001 - 2003-ish
"
"
"
EJB v3.1
!
!
!
!
!
64
3/4/14
@Remote(EchoPoint.class)
@Stateless
public class EchoPointEJB {
. . .
65
3/4/14
Factors: Availability
Defining availability
! Two perspectives host and application
" Uptime of a machine/software
" Accessible for use
! Nines
" How to describe the level of availability
" Percent the system is available (accumulative)
Down Mon, Tue, Wed, Thu is bad
7.2 hours of planned maintenance and upgrades per month is okay
Availability (%)
Down/Year
Down/Month
90%
36.5 days
72 hrs
99%
3.65 days
7.2 hrs
99.9%
8.76 hrs
43.2 min
99.99%
52.6 min
4.32 min
99.999%
5.26 min
25.9 sec
66
3/4/14
Complexity
! Cost to build, cost to support
! Synchronization of data requires bandwidth and cycles
! Where to apply replication?
" Web, middle, data?
" Database?
" Network, power
" Centers (installations)
67
3/4/14
Causes
! Expansion exceeds original purpose (design)
" Mission changes, increased load
Issues
!
!
!
!
!
Scalability should
! Not change consistency (reliability)
! External latency does not decrease
! Code base does not change
68
3/4/14
Pattern for two should allow for many more - up to a point where issues of
replication and caching become a factor to the design
Software updates are easier - redirect all to one, bring down other to
update, switch procedure and then reset (assumes all hosts are identical)
However, the use of local caching will prevent failover consistency this may not be a problem if the system and consumers agree to
occasional break in continuity of service
69
3/4/14
Design (cont.)
Blade - linear scalability with nearly unlimited
expansion
70
3/4/14
Designs (cont.)
Shard - a bladed architecture with no collective
memory - truly independent.
Separation of data is a referential integrity (RI) defeating design breaks optimization and reduction of duplication of normal form
database design
71
3/4/14
! Project
" Measurable
" ROI
" Realistic time, money, resources
72
3/4/14