Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Push
J2EE your development
Best furtherusing
Practices Tech
Days
Real-life Examples.
Carol McDonald
Technology Evangelist
carol.mcdonald@sun.com
Configuration
eBayISAPI.dll
Security
Logging
EJB™ Container
Integration Tier
Monolithic Layered
Proprietary Loosely coupled
Modular
Standards based
Sun™
Push
What yourIs
development
Needed… further Tech
Days
Web Server
No centralized access point
1. Request for presentation request handling
Common Request
Processing Logic?
Duplicate common
logic in Views
Client
??? View
View
2. Response
View
Sun™
Push your development
Service to Worker further Tech
Days
Command
Factory
3. Parse Request
5. Create
1. Request Front 4. Get cmd
Client Controller
6. Execute Command
2. Common logic Helper
8. Dispatch
10. Response 7. Business
View logic
Dispatcher
Servlet View
Helper
JSP Data
9. Get Data Bean
Java™ Objects
Sun™
Push
Useyour
andevelopment further
MVC Framework Tech
Days
Form Bean
Struts-config.xml
Browser
Action
Servlet
Session Entity
Bean(s) Bean(s)
Action
Bean
JSP
w/Struts Database
Java
Bean
Sun™
Push your development
Struts and Core further
J2EE Patterns Tech
Days
Client
Service
Locator
Uses
Response
Action Action
JSP View
Forward Form
Request
Intercepting Front Business Business
Command
Filter Controller Delegate Service
Client Service
Locator
Navigator Dispatcher
Client
independent from
ejb tier
Ejb details
hidden
Mock objects can
be used to test
client w/o ejb tier
Sun™
Push
Tipsyour
fordevelopment
Servlets further Tech
Days
View Items
View Items
Any User
Centralize
Request Hndlg
Item/Auction
specific
biz logic
Convert to
Biz Command
Assemble
Data
Use case
Biz logic
Retrieve
Data
Sun™
Push
View yourItems
development further
Design Tech
Days
Front Application
Controller Service
Transfer
Application Object Transfer
Controller Object
Assembler
FRONT
VIEW
CONTROLLER
DATA
MODEL Value List Handler ACCESS
OBJECT
COMMAND DATA
TRANSFER DATA
object TRANSFER
OBJECT
OBJECT
GetCity()
Network
boundary
GetCustomerInfo()
Create()
GetCity()
After Reduced network traffic
GetState()
with Data Transfer Object
GetZipCode()
Network
boundary
Sun™
Push
Valueyour development
List Handlerfurther Tech
Days
<<List>>
Client ValueListHandler ValueList ValueObject
DataAccessObject
Sun™
Push your development
Sequence further
Diagram Tech
Days
Client DataAccessObject
1: Create
ValueListHandler
ValueListiterator
2: Execute Search
2.1: Execute Search
2.1.1: Create ValueList
3: Get Next
3.1: Get Sub-list
4: Get Previous
4.1: Get Sub-list
4.2: Return Sub-list
5: Get Current
5.1: Get Current
5.2: Return Value Object
6: Get Size
6.1: Get Size
6.2: Return Size
Sun™
Push
Data yourAccess
development further
Object Tech
Days
creates/uses
obtains/modifies ValueObject
Sun™
Push your development
eBay.com: further
Business Tier Tech
Days
Dispatch Persistence
Application Domain
DAO Data
Controller Store
Source
Business
Command Context Logic/Data
Object
Application Business
Service Object
Transfer
Object
Transfer Value
Object List
Core J2EE
Assembler Handler
Pattern
Strategy
Sun™
Push your development
Session Facade further
pattern Tech
Days
Don’t:
Direct Bean Access
EJB
Client
Network
Do:
EJB
Network F
a
Client c
a
d
e
Sun™
Push your development
Session Facade further
pattern Tech
Days
3. process
Java™
Object
Network
Value Object
Exchanges data J2EE tiers
Service Locator
Holds results of JNDI lookups
Value List Handler
Handles larger result sets from database queries
Business Delegate
Simplifies the coupling between the J2EE Web &
EJB tiers
Session Facade
Provide business logic functionality
Data Access Object
Isolation layer for interfaces to a systems
resources
Etc.
www.sun.com/developer/blueprints/.
Sun™
Push your development further Tech
Days
Persistence
Options
Sun™
Push
Data yourAccess
development
infurther
J2EE Tech
Days
Database
EJB Container
1) Bean provider manages State and Data consistency
2) Bean provider handles relationships and OR Mapping
<<interface>>
java.io.Serializable
<<interface>>
javax.ejb.EnterpriseBean
<<interface>>
javax.ejb.EntityBean
Address
Order
Local Entity
1
Shipping Address
1 Local Entity
Client OrderBean Product
1 1
LineItems ProductOrdered
M M
OrderHome LineItem
Local Entity
EJB Tier
Sun™
Push your development
Accessors further and
for CMP CMR Tech
Days
for developer
Rich modeling capability on relationships
- container manages the relationships,
not you!
Referential integrity
Cardinality
Cascading delete
Freedom from maintaining interactions
with the data store
EJB™ Query Language (EJB QL)
Portable code
Sun™
Push your development further Tech
Days
CMP
Sun™
Push your development
Advantages of further
CMP 2.0 Tech
Days
for Container
Optimization is possible because
persistent fields are only accessible
via get and set methods
Lazy loading
Dirty checking
Optimistic locking
Optimization is possible in query
operation
Because Query is defined in deployment
descriptor via EJB QL
Sun™
Push
CMP your development further
Optimizations Tech
Days
Aggressive Loading
Loading fields relationships and fields of
children in the same query
Lazy Loading
Deferring loading of any data until it is accessed
Dirty Writes
Only update data which has been changed
in the database
Sun™
Push
CMP: yourStandard
development further
Vs. Tech
Days
Standard features
Declarative specification of:
Persistent attributes, abstract schema, relationships,
queries for finder/select methods(via EJBQL),
transactional attributes
Vendor specific
O/R mapping, concurrency and consistency
semantics, caching semantics, performance
and usability
Sun™
Push your development
Pessimistic further
Locking Tech
Days
C1 C2
Time State in
Database
1000 Begin Txn
1000
read initial
balance w/Lock Begin Txn
.. read initial
balance += 1000 balance
w/lock
.. (blocks ..)
2000 2000 Commit
2000
unblocks
Commit
“ Update-conflict” Detection
Concurrent Access to same Bean (same Primary Key)
C1 C2
Time State in
Database
1000 Begin Tx Begin Tx Retry
1000 1000
Select initial Select initial
balance balance
..
2000
..
balance += 1000 balance += 1000
update
2000 2000 ..
Commit update 3000
Exception
..
3000 Commit
Pessimistic Optimistic
Serialized access Concurrent
Recommended for access
beans where Large-scale
conflicts are bound deployment
to happen Requires collision
Scalability depends and exception
on DB and App handling
server locking Choices for
granularity conflict detection
Sun™
Push your
Data development
and Cachingfurther Tech
Days
Static data
Keep a local copy, hang on to it in memory,
don’t worry about being stale
Near static data
Keep a local copy, hang on to it in memory,
lazily check for updates
Dynamic data
Work on local copy, cache carefully, use
optimistic locking
Hot data
Pessimistic locking
Sun™
Push your development
Database further Modes
Isolation Tech
Days
Read Uncommitted
Dirty reads, non-repeatable reads and
phantom reads can occur
Read Committed
Dirty reads are prevented; non-
repeatable reads and phantom reads
can occur
Repeatable Read
Dirty reads and non-repeatable reads
are prevented; phantom reads can
occur
Serializable
Dirty reads, non-repeatable reads and
phantom reads are prevented
Sun™
Push your development
Entity Bean Cachingfurther Tech
Days
Commit Option A
At the end of the transaction, the instance stays
ready and the instance state is valid
Commit Option B
At the end of the transaction, the instance stays
ready but the instance state is NOT valid
Commit Option C
At the end of the transaction, neither the instance
nor its state is valid
Best Option: Check your app server
Sun™
Push your development
Transaction Do'sfurther Tech
Days
J2EE
Performance
Tips
Sun™
Push
Tune yourApp
development
Serverfurther Tech
Days
Session timeouts
Stateful session bean and entity bean
cache
Cache = EJB instances with state
Stateless session and entity bean pools
Pool = EJB instances with no assigned state
Transaction isolation level
Sun™
Push your development
Entity Bean further Tech
Days
pooled
ejbFind()
EJB
Instance
ejbCreate() ejbRemove()
ejbPostCreate()
ejbActivate() ejbPassivate()
ready
business method
Sun™
Push your development
Stateful Session further
Bean Tech
Days
1) newInstance() ejbRemove()
2) setSessioncontext()
3)ejbCreate() ejbPassivate()
Method-ready
1) newInstance()
2) setSessioncontext() EjbRemove()
3)ejbCreate()
method-ready
pool
Business method
EJB
Instance
Sun™
Push your development
Manage further
Expensive Resources Tech
Days
Session Facades
Service Locator
Value List Handler
Data Transfer Object
Sun™
Push your development further Tech
Days
Performance
Testing
Sun™
Push your developmentTips
Performance furtherSummary Tech
Days
JMS,
Push your development further Tech
Days
Messaging,
Web Services
J2EE Best
Practices
Sun™
Push
JMSyour development further Tech
Days
Queue
JMS JMS
Java™ Pet
Store
Sun™
Push your development
Publish further
and Subscribe Tech
Days
Topic
Price Change
Traders/Brokers
Sun™
Push your development further
Message-Driven Bean Tech
Days
Container
JMS Container
Provider
Desti MDB
Msg-
Consume MDB
Queue
n- Consumer driven
Instances
Instances
r
ation Bean
Msg-Driven
Bean Class
Sun™
Push
Useyour
JMSdevelopment
for further Tech
Days
Asynchronous Interaction
Concurrent processing
Broadcasting events (messages)
Reliable messaging
Messaging with Transaction Support
Scalability
Loose Coupling
Batch processing
Sun™
Push yourFacade
MDB development further
Pattern Tech
Days
Mailer MDB
Asynchronous
Message
EJB
Delivery LineItem Tier
Order Entity
Card
Approval 1:m
Entity
MDB Purchase
Order Entity
Address
Entity
Relationship
Reference
Sun™
Push
XML your development Facade
Message further Tech
Days
Managed Transactions
TRANSACTION
Purchase
JMS Topics
Order
<Entity EJB>
Queue
Publish/subscribe Order
Bean
Process
MessageDrivenBean Order
<Entity EJB>
Procure
Inventory
Inventory
Management
Bean
Mail
Sun™
Push
Useyour
JMSdevelopment
for further Tech
Days
Event-Driven Interactions
Join pattern
MDB collects different messages
Stores to same set of entity beans
Equipment Info
Reserve
Equipment Furnished Office
Setup
Office
Human Reserve
Resources NewHire Office
Assigned Office
Add to
Payroll
Paycheck Happy New Hire
Sun™
Push your development
Example Problem further
Tracking Tech
Days
Existing
Synchronous
EJB Tier Client
Access
Existing
Remote EJB Tier Synchronous
Help Desk Client
New Access
Problem Problem
Problem Solver
Handler
Problem
Report
Request Rep
Company
Report
Generator
Monthly
Report
Sun™
Push
JMSyour development
Do's further
& Don'ts Tech
Days
Processing layer
Process request
Apply business logic
Integrate with EIS
Interact with peers
Layered view helps to:
Clearly divide responsibilities
Decouple business logic completely
Expose a web service interface to existing
business logic
Sun™
Push
RPC your
– development further
Simple Client/Service Tech
Days
Request
Client Service
Response
Common approaches:
SOAP using JAX-RPC (WSDL)
Features:
Stateless and conversation-less
Industry examples:
Amazon, Fedex, eBay, credit check,
get Weather, get Stock price
Sun™
Push
RPC your development
Style Webfurther
Services Tech
Days
RDBMS
Web Business Domain EAI Resource
Container Services Objects Adapters
Data
JAX-RPC Base
Connector
Legacy
Systems
MDB
ERP
Sun™
Push your developmentB2B
Collaborative furtherWeb Services Tech
Days
Service Service
Business
Process
Service Service
Features:
Orchestration, Choreography, Collaboration
Business process defines Message sequence
Asynchronous document exchange
Industry examples:
OTA, Sabre, GM
Sun™
Push your development
Document Stylefurther
Web Services Tech
Days
MDB
ERP
Sun™
Push
JBIyour
anddevelopment
J2EE further Tech
Days
Web App.
EJB JBI BP Module
Module
Module (WS-BPEL and
(JSP/Servlet
(EJB API) WSDL APIs)
API)
208 “Machine”
SPI
208 “Binding”
SPI
Binding Framework
J2EE
EJB XML Proxy
Rule
MDB JMS Base
XSLT
Engine
Message
Broker
(XSLT)
Servlets Provider
XML/SOAP/JMS
Adapter
SOAP C++
Web Inventory
Service Data
Business Process Engine
Sun™
Push your development further Tech
Days
Carol McDonald
Technology Evangelist
carol.mcdonald@sun.com