Sei sulla pagina 1di 102

Sun™

Push
J2EE your development
Best furtherusing
Practices Tech
Days

Real-life Examples.
Carol McDonald
Technology Evangelist
carol.mcdonald@sun.com

Sun™ Tech Days


Sun™
Push
eBay yourArchitecture:
development further How to Go… Tech
Days

From there… … to here?


Microsoft IIS J2EE™ Container
Web Container Services
Presentation Tier

Configuration
eBayISAPI.dll

Security
Logging
EJB™ Container

MSXML Business Tier

Integration Tier

 Monolithic  Layered
 Proprietary  Loosely coupled
 Modular
 Standards based
Sun™
Push
What yourIs
development
Needed… further Tech
Days

 Learning the technology is


not enough
 Industry best practices
 Proven solutions
 How to avoid bad practices?
 Experience and expertise
Sun™

Push your development further
Core J2EE Patterns Tech
Days

 Platform Patterns for J2EE™ architecture


 Based on our experience
 Collection of best practices for J2EE™
platform
 J2EE™ architecture refactorings
and bad practices
 Create a common vocabulary
 Proven solutions
 Reuse design
 Robust and scalable architecture
 Improve quality
 Flexibility and maintainability
Sun™
Push your development further Tech
Days

Some Web Tier


Best Practices
and Patterns
Sun™
Push your development further
Layering Tech
Days

Client Application Presentation Layer

Data Transfer Objects


Network i.e. Managed Entity Values

EJB Session Beans Business Logic Layer


Service Layer

Managed Domain Layer


Entities Managed Entities
Sun™
Push your development
Rationale further
for Layers Tech
Days

 More flexible, extensible:


 Presentation Layers
 Frequent changes, designed to be flexible
 Business Services
 Implement “use-cases”
 Public interface, resource access
 Should remain valid for changes in presentation
and data store
 Data Layers
 Fewer changes, designed to optimize data access
Sun™
Push your development
Layered further
View (cont.) Tech
Days

 Layered View helps to:


 Clearly divide responsibilities
 Decouple business logic completely
 Provide a common “place” for pre-
processing and post-processing of
requests and responses (like logging,
translations, transformations, etc.)
 Expose a web service interface to
existing business logic
Sun™
Push your development
Model further
View Controller Tech
Days

 Model = business data and rules


 View = view of model, presents the user interface
 Controller mediates their interactions

Thin Browser Client

HTTP Request HTML Page

Presentation Layer Controller View

Model Layer Problem Domain Services

Persistence Layer Enterprise Resources


Sun™
Push
Web your development
Tier: further
Problem 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

 Faster, easier development of


 Request processing
 Response generation
 Use Struts, JSF, Sun ONE ... application framework
Sun™
Push your development
Struts Framework further Tech
Days

View Controller Model

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

Front Controller Command Model


Service
Interface
Request Action
Action Business Business
Mapping Action
Servlet Delegate Service
(xml)

Client
Service
Locator
Uses

Response

Action Action
JSP View
Forward Form

View Dispatcher View Helper


Sun™
Push your development
Ebay.com: further
Presentation Tier Tech
Days

Request Handler Service Interface

Request
Intercepting Front Business Business
Command
Filter Controller Delegate Service

Navigation and Dispatch

Client Service
Locator
Navigator Dispatcher

View Processor XML

Intercepting View Transformer Core J2EE


Filter Processor Helper XSL
Response Pattern
Strategy
Sun™
Push
Cacheyour development further
for Performance Tech
Days

 Some things can be cached and shared (singleton):


 InitialContext object
 Anything retrieved from JNDI, EJB Home interfaces
 Repeated lookups can be expensive! Use Service Locator
Pattern
 Some things are cached by individual clients
(session):
 Cache search results when you are only displaying a few
at a time (non-transactional data)
 JDBC™ CachedRowSet
 Value List Pattern
Sun™
Push your development
Service Locator further
Pattern Tech
Days

Repeated lookups can be expensive!


Use the Service Locator Pattern to
Cache references obtained by JNDI lookups
(ejb references, datasources, jms)
Sun™
Business Delegate
Push your development further Tech
Days

 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

 Servlets are Multithreaded


 Avoid use of shared modified class variables
 Synchronize only small blocks in code
 Remove servlet sessions when they
are no longer needed:
 In logoff call session.invalidate()
 On client side, don’t access your EJBs
directly, use service locator with
business delegate
Sun™
Push your development
Servlet Tips further Tech
Days

 DO use high performance J2EE


design patterns
 MVC, Service Locator
 DON’T hold resources – explicitly
free them
 DON’T intensively process
immutable objects.
Sun™
Push
Tipsyour
fordevelopment
JSPs further Tech
Days

 Avoid scriptlets in JSP


 Use JSTL (JSP 2.0 Standard Tag Libraries):
 <c:forEach var="item" values="${cart}">
 Pass data to JSP in Servlet request not
session
 If JSP does not use the HTTP session
 Use <%page session="false"%> to prevent
HTTP Sessions from being automatically created
Sun™
Push your development further Tech
Days

Some EJB Tier


Best Practices
and Patterns
Sun™
Push
Do your
youdevelopment further
need EJBs? Tech
Days

 Do you need declarative


transactional support?
 Do you need to distribute your
business logic?
 Do you need JMS, JAX-RPC, RMI?
 Do you need to support multiple
client types?
 Do you need method-level security
on your objects?
 Do you need a standards-based
architecture?
Sun™
Push your development
Architecting further
Applications Tech
Days

 Functional requirements captured


via use-cases
 Use-cases implemented using MVC &
Command design patterns
 Implement Business Logic as a Service
Sun™
Push
Useyour development
case further
realization Tech
Days

View Items

View Items

Any User

Any user can view any items


available for bidding or sale
Sun™
Push
View yourItems
development further Requirements
Design Tech
Days

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

Business Session Value List


Delegate Facade Handler

Service Data Access


Locator Object
Sun™
Push yourApplication
Core development further
Design Patterns Tech
Days

Presentation Business Logic & Data Integration


Messaging Fabric & Persistence

Request Response BUSINESS


SERVICE
FACADE

FRONT
VIEW
CONTROLLER

DATA
MODEL Value List Handler ACCESS
OBJECT

COMMAND DATA
TRANSFER DATA
object TRANSFER
OBJECT
OBJECT

WEB Tier SessionEJB

Servlet Java™ Objects


JSP Session EJB
Sun™
Push
Data your developmentObject
Transfer further Tech
Days

Client Customer CustomerInfo


Object EntityBean EntityBean
GetCustomerInfo()
Create()

GetCity()

Before GetState() A lot of network traffic


GetZipCode()

Network
boundary

Client CustomerInfo Customer


Object EntityBean EntityBean

GetCustomerInfo()

Create()
GetCity()
After Reduced network traffic
GetState()
with Data Transfer Object
GetZipCode()

Network
boundary
Sun™
Push
Valueyour development
List Handlerfurther Tech
Days

 For querying, filtering, and


Interface
ValueListiterator displaying large amounts
+GetSize():int
of data:
+getCurrentElement():Object
+getPreviousElements(count:int):List
 Value List Handler handles
+getNextElements(count:int):List the search, caches results
+resetIndex():void and provides a filterable
and traversable result set

<<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

2.1.2: Return Value List

3: Get Next
3.1: Get Sub-list

3.2: Return 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

BusinessObject DataAccessObject DataSource


Uses Encapsulates

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

Direct Entity Bean access results in excessive network overhead


and multiple transactions

Do:
EJB
Network F
a
Client c
a
d
e
Sun™
Push your development
Session Facade further
pattern Tech
Days

Session Bean Entity


Bean 1
Entity Bean
Plain Java™ Object 2. getData() 2. getData()
Data
Entity
Access
Bean 2
Object 1
Client Session
1. doThis(...) Facade
Session Data
Bean Access
Object 2

3. process
Java™
Object

 Use the Session Facade:


 To reduce network overhead
 To group related updates into transactions
Sun™
Push your development
Container further
Managed Transactions Tech
Days
Sun™
Push
Localyour vs.
development
Remote further
Interfaces Tech
Days

Remote Interfaces Local Interfaces

EJB EJB EJB EJB


client Object client Object

Network

Pass by Value: Pass by Reference:


Serialize/deserialize Better performance
method parameters
Sun™
Push your development
Session EJB tips further Tech
Days

 Do use session beans as a service facade


 With local interfaces: Faster than remote
 Container managed transactions: calls to
entity beans within one transaction!
 DO design fine-grained components
as Java™ classes
 DO minimize the number of service calls
with a large-grained component design
Sun™
Push your development
Session EJB tips further Tech
Days

 Stateless session beans give best


performance, watch use of stateful
 Remove stateful session beans to
reduce unnecessary passivation
 Bean.remove()
 Limit size of objects stored in session
beans (performance for passivation)
Sun™
Push your development
Service Tier DON'Tfurther s Tech
Days

 DO NOT store large amount of data


in Stateful SessionEJB
 DO NOT access entity EJBs remotely
 DO NOT implement fine-grained
components as remote EJBs
Sun™
Push your development
Design Patterns further
Summary Tech
Days

 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

 Formal object-oriented model


 EJB container managed persistence
 Great choice for representing existing databases
 JDO
 Tabular access
 Plain JDBC
 JDBC RowSets
 Good choice for ease of development
 Non-relational, non-object data access
 Use J2EE Connectors
Sun™
Push
BMP yourvs.
development
CMP further Tech
Days

BMP JDBC JDBC SQL Bean


Bean SQLJ Driver State

Database
EJB Container
1) Bean provider manages State and Data consistency
2) Bean provider handles relationships and OR Mapping

CMP JDBC JDBC SQL Bean


Bean SQLJ Driver State
Persistence Database
EJB Container Manager

1) Container manages State and Data consistency


2) Container/PM provides concurrency, relationships and OR Mapping
Sun™
Push
Useyour
BMPdevelopment
or DAO further
for Tech
Days

 Dealing with legacy database and/or


other persistence store
 Previously written complex application
 Connector driven data stores, EIS
 Efficient execution of complicated queries
 Bulk updates
 Complex joins
 Aggregates
Sun™
Push your development
Entity Bean Tips further Tech
Days

 Do not use EJB entity beans for batch


loading or queries that return large result
sets. Use Data Access Objets
encapsulating JDBC
 Use CMP rather than BMP entity bean
when possible
 Do not call EJB entity bean get & set
methods from client
 Wrap with session beans to provide course
grain access and single transaction context
Sun™
Push
JDBC your development
Tips further Tech
Days

 Select a certified, high performance


type 2 JDBC driver
 Tune connection pool size
 Close resources as soon as you’re done
with them (in finally)
 E.g. Statements, Connections, ResultSets…
 Use JDBC’s PreparedStatement instead
of Statement when possible
 Turn off Auto-Commit
 Group updates into a transaction
Sun™
Push
JDBC your development
Tips further Tech
Days

 JDBC Supports a number of high


performance optimization techniques
 Typically you can optimize JDBC
performance by:
 Using CachedRowSets
 Using setDefaultRowPrefetch
 Using statically bound column types
 Using update batching
 Using statement caching
Sun™
Push your development
Database further
Performance Tech
Days

 Common performance bottleneck


 Typical problems:
 Inefficient queries - sending SQL data
that asks the database to do more work
than necessary
 Excessive querying - efficient queries
called too frequently
 Large Data Sets - processing large sets
of data in ResultSets
Sun™
Push
CMP your2.0
development
Entity further
Beans Tech
Days

Entity Bean is now an abstract class, container extends it

<<interface>>
java.io.Serializable

<<interface>>
javax.ejb.EnterpriseBean

<<interface>>
javax.ejb.EntityBean

CMP Entity Bean abstract class You (bean provider)


(Contains data handling logic) write this code.

CMP Entity Bean subclass Container provides


(Contains persistence logic) this class.
Sun™
Push your development
Container further
Managed Relationships Tech
Days

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

public abstract class OrderBean implements EntityBean {

private EntityContext context;

//access methods for cmp fields

public abstract String getOrderID(); //primary key


public abstract void setOrderID(String id);
. . .
//access methods for cmr fields

public abstract Collection getLineItems();


public abstract void setLineItems(Collection lineItems);
Sun™
Push
CMP your2.0
development further
Relationship Handling Tech
Days

 In CMP 2.0, you declare fields and


relationships in deployment descriptor
 Container generates all the necessary code
<ejb-jar>
<enterprise-beans>
... define your enterprise beans ...
<cmp-field> elements represent container-managed
persistent fields
</enterprise-beans>
<relationships>
... define EJB relationships ...
</relationships>
Sun™
Push
EJB™ your development
QL Example further Tech
Days

Find orders for a specific product:


SELECT OBJECT(o)
FROM Orders o, IN (o.lineItems) l
WHERE l.product.name = ?1
 XML:
<query>
<query-method>
<method-name>findByProduct</method-name>
<method-intf>LocalHome</method-intf>
</query-method>
<ejb-ql>SELECT OBJECT(o) FROM Order o,IN (o.lineItems) l
WHERE I.product.name= ?1</ejbql>
</query>
Sun™
Push your development
Advantages of further
CMP 2.0 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

Vendor Specific Features

 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

3000 3000 balance +=


1000

Commit

The row is locked for the duration of the transaction


Sun™
Push your development
Optimistic furtherWith
Locking Tech
Days

“ 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

Concurrent Access to same Bean (same Primary Key)


Lock obtained at update time, possible conflict detection with version id column
Sun™
Push
Usageyour development
Guidelines further Tech
Days

 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

 Do use READ_COMMITTED with


Optimistic locking as much as possible
 Do use Optimistic locking only and
SERIALIZABLE if required.
Sun™
Push your development
Transaction further
Don'ts Tech
Days

 Don't use SERIALIZABLE if it


can be avoided
 Don't use pessimistic locks if it
can be avoided
Sun™
Push
EJB your development further
Summary Tech
Days

 EJB Container Services – use appropriately for:


 Distributed transaction management
 Robust security service
 Resource management (threads, sockets, database connections)
 Container persistence
 Remote accessibility
 Dispatch and life-cycle management.
 Use EJB 2.0 local interfaces for performance
improvements
 When running in same JVM.
Sun™
Push your development further Tech
Days

J2EE
Performance
Tips
Sun™
Push
Tune yourApp
development
Serverfurther Tech
Days

 Execute threads that requests run on


 JDBC connection pools
 JDBC prepared statement cache size
 Correct settings depend on application
Sun™
Push
Tune yourKey
development further
Container Parameters 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

Bean pool size EjbActivate()

Bean cache size Does


not exist
NewInstance()
setEntityContext() unsetEntityContext()

pooled
ejbFind()
EJB
Instance
ejbCreate() ejbRemove()
ejbPostCreate()
ejbActivate() ejbPassivate()

ready

ejbLoad() EJB EJB ejbStore()


Object Instance

business method
Sun™
Push your development
Stateful Session further
Bean Tech
Days

Bean cache size


Session time out
does not
exist

1) newInstance() ejbRemove()

2) setSessioncontext()

3)ejbCreate() ejbPassivate()

Method-ready

EJB EJB passive


Object Instance

business method EjbActivate()


Sun™
Stateless
Push Session
Bean
your development further Tech
Days

and Message Driven Bean

Bean pool size


does not
exist

1) newInstance()

2) setSessioncontext() EjbRemove()

3)ejbCreate()

method-ready
pool
Business method
EJB
Instance
Sun™
Push your development
Manage further
Expensive Resources Tech
Days

 Cache “EJB homes”


 Cache data sources
 Minimize use of HTTP sessions
 Release database connections
 Remove unused stateful session beans
 Use local Interfaces
Sun™
Push your development
Design Patterns further
can Tech
Days

Significantly Help Performance

 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

 Tips for better performance


 Tune app server and infrastructure
 Leverage proven design patterns
 Design coarse grain EJB interfaces: Value Object
 Reduce JNDI look-ups: service locator
 Use session bean wrappers: session facade
 Database access
 Use JDBC for:
 Batch loading: session bean or message bean
 Large result sets: value list handler
 Use CMP rather than BMP Entity Beans
 Use right isolation level and database
transactional control (locking)
Sun™

JMS,
Push your development further Tech
Days

Messaging,
Web Services
J2EE Best
Practices
Sun™
Push
JMSyour development further Tech
Days

 Use JMS for loosely coupled


applications that need reliable,
scalable document oriented
message exchange
 Including Message-Driven
Beans and JMS in your J2EE™
application can greatly increase
performance, robustness, and
efficiency
Sun™
Push your development further
Point-to-Point Tech
Days

Example: Order and Fulfillment

Queue

JMS JMS

Java™ Pet
Store
Sun™
Push your development
Publish further
and Subscribe Tech
Days

Example: Stock Price Changes

Topic

Price Change

Traders/Brokers
Sun™
Push your development further
Message-Driven Bean Tech
Days

Concurrent Asynchronous Processing


 High Scalability, High Throughput
 MDB instances are pooled by the container
 Allow for asynchronous concurrent message consumption
from the same destination

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

EJB Architectural Pattern


Entity
XML Bean
XML Messaging Facade Java™
Value Value
Objects Objects Stateless
JMS Message Entity
Client Driven Session Bean
Queues Bean EJB
Entity
Asynchronous Synchronous Bean

Example implementation of XML interaction model


on top of Java™ interaction model
Sun™
MDBs
Push Container
your development 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

 Designing for event-driven interactions:


 Not interface-driven
 Loose coupling among participants
 Asynchronous communication model
 Reliable communication or many to many
communication model
 Serves as an asynchronous facade to a
subsystem or an application
Sun™
Push
MDB yourJoin
development further
Pattern Tech
Days

 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

 A Session EJB provides the Problem


business logic for the Customers Solver
or help desk to synchronously
enter Problem data, or search for
similar problems Problem
 Entity EJBs provide the business
logic for accessing/updating the Rep
domain Data objects
Company
Sun™
Push your development
Extension further
Solution Internal View Tech
Days

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

 Do watch message size


 Do only use XML when necessary
(lower performance)
 Do only use reliable messaging when
necessary (lower performance)
Sun™
Push
Tips your
fordevelopment further
XML messaging Tech
Days

 Inside your Application don’t overuse XML


 Parsing and processing can cause a performance
hit
 Use XML for messages between
systems…
 Within a system just use data objects
 Convert the data from XML into a Java™
class as soon as possible
 Can use JAXB for this
 Use XML mainly for transmission
Sun™
Push
Keyyour
Webdevelopment
Servicefurther
Guidelines Tech
Days

 Structure application in two layers


 Interaction layer and processing layer
 Interaction layer
 Interface to clients Service
Client
 Receive requests and perform
required translations and
transformations
 Delegate request to processing Interaction
layer for processing Layer

 Respond to clients Processing


Layer
Sun™
Push your development
Layered View further 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

Web Stateless Entity DAO


Component Session EJB
EJB

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

Soap Message Business Domain EAI Resource RDBMS


Handler Services Services Objects Adapters
Soap Data
Base
Msg
Service MDB Session Entity DAO
Handler EJB EJB

Entity Connector Legacy


Business
MDB Session Systems
Document EJB EJB

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

Normalized Message “Bus”

208 “Binding”
SPI
Binding Framework

WS-I JMS JCA EDI VAN

SOAP MQ EIS resource AS1/AS2


Sun™
Push
Sunyour
ONEdevelopment
BPM,further
Messaging & J2EE Tech
Days

J2EE
EJB XML Proxy

Rule
MDB JMS Base
XSLT
Engine
Message
Broker
(XSLT)
Servlets Provider
XML/SOAP/JMS

Rule XSLT Message


Base Engine Broker
(XSLT)

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

Sun™ Tech Days

Potrebbero piacerti anche