0% found this document useful (0 votes)
58 views50 pages

03 Part 2 Dist Obj Design

The document discusses best practices for modeling requirements for distributed object design in J2EE applications. It provides examples of modeling business processes and application flows using state diagrams and class diagrams to capture functional and non-functional requirements.

Uploaded by

api-3706715
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views50 pages

03 Part 2 Dist Obj Design

The document discusses best practices for modeling requirements for distributed object design in J2EE applications. It provides examples of modeling business processes and application flows using state diagrams and class diagrams to capture functional and non-functional requirements.

Uploaded by

api-3706715
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

IBM Software Services for WebSphere

Part 2: Distributed object design


considerations

Geoff Hambrick
Senior Technical Staff Memeber
IBM Software Services for WebSphere

Best practices for developing J2EE applications

November 18-20, 2003 | Bangalore © 2003 IBM Corporationn

03_Part_2_Dist_Obj_Design.PRZ 1 of 50
IBM Software Services for WebSphere

Requirements analysis best practices


Requirements to capture in a model:
business process and application flow
dynamic and static aspects
functional and non functional
Dynamic Static
Models (state, transition) (entity, relation)
Business Process Units of work Persistent data
(contract) (throughput) (number of records)

Application Flow User initiated events Visible data


(user role) (response time) (style)

Notations to consider:
textual (state tables, templates)
graphical (state transition and class relationship diagrams)
whatever works for you and your customer
October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 2 of 50
IBM Software Services for WebSphere

An example business process dynamic model


On line order fullfillment business process model
lifecycle of an order showing interaction of various roles
transitions represent units of work (described later)

add line item


(product,
create() quantity) Customer assign() Packer
Marketing
ship (shipper)
Entry submit() [all items
Fulfillment shipped]
modify line Completed purge
item cancel()
(product, [not all items
quantity)
pack line item shipped]
(product, quantity)

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 3 of 50
IBM Software Services for WebSphere

An example business process static model


Order Entry static object model
shows possible state of persistent data during order entry
units of work in dynamic model will be in terms of these

Product Customer
@sku @customerID
description

openOrder

@product 0..n 0..1 customer


Line Item Order
0..n
quantity @orderID
status

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 4 of 50
IBM Software Services for WebSphere

An example application flow dynamic model


Customer's application flow dynamic model
high level requirements captured in a STD of a customer
transitions may trigger events on the underlying BPM
Customer
Home Order
Status
(order) open

{create
Product (order) order} ok
Catalog Order Confirm
cancel Details Open
add to order (order)
{add item edit line item submit
(order)
(product, quantity)} Confirm {modify item
Cancel (product, Confirm
ok quantity)} Submit
{cancel order} ok
{submit order}
Action
Result

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 5 of 50
IBM Software Services for WebSphere

An example application flow static model


Customer application flow static model
one "entry point" object per state
attributes and relationships show dynamic content
Product Order Order Customer
Catalog Details Status Home
customerID customerID
orderID
status

products items orders

0..n 0..n 0..n

Product Line Item Order Action Confirm


Result Action
productID productID orderID message orderID
description description status action
quantity

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 6 of 50
IBM Software Services for WebSphere

Model Integrity Checks {create


(order) order} ok Confirm
Order
Details Open
Transitions in Application
Flow Dynamic Model
supported by Operations in Customer

Business Process Dynamic create()


Entry
Model

Order
Status Customer
customerID
@customerID
"View" Data in Application Flow Static
orders Model can be produced by Business openOrder
0..n Process Dynamic Model from data
0..n 0..1 customer
Order available in Business Process Static Order
orderID Model @orderID
status
status

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 7 of 50
IBM Software Services for WebSphere

Architecture best practices

The architecture
describes physical and logical "tiers" where application
components will be hosted
drives the programming model used in detailed design
Remember the four approaches:
web enabled client-server
distributed object based
web services based
web enabled distributed object based

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 8 of 50
IBM Software Services for WebSphere

Three-tier web based application architecture


Web Application Enterprise Logic
Browser Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home (product,
(order) open

???
customerID customerID
create() sku customerID
quantity)

HTTP
orderID Customer Shipping description
status Marketing
{create
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item item product 0..n 0..1 customer
[qty < 0] cancel()
Product Line Item Order Action Confirm Confirm (product,
Result Action [qty = 0] Cancel {modify item Confirm
Submit quantity)
[not all items Line Item Order
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action (product, quantity)} (product, quantity) quantity orderID
quantity {cancel order}
quantity)} ok status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

Pros:
browsers are everywhere
client tier needs install nothing specific (maintenance)
middle tier has direct access to back end data (performance)
Cons:
cost of remote connection to middle tier (performance)
must install enterprise clients on middle tier (maintenance)
business logic executes in middle tier (security)
Best application:
web enabling the front end of a business process (the "edge")

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 9 of 50
IBM Software Services for WebSphere

Distributed object based application architecture


Client Application Distributed Enterprise Logic
Object Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home (product,

IIOP
(order) open

???
customerID customerID
create() sku customerID
orderID quantity) Shipping
Customer description
status Marketing
{create
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item item product 0..n 0..1 customer
[qty < 0] cancel()
Product Line Item Order Action Confirm Confirm (product,
Result Action [qty = 0] Cancel {modify item Confirm
Submit quantity)
[not all items Line Item Order
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action (product, quantity)} (product, quantity) quantity orderID
quantity {cancel order}
quantity)} ok status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

Pros:
really snappy user interface (performance)
client does not need enterprise access
business logic separated from client (security, maintenance)
can load balance business logic (scalability)
Cons:
must install application on client (maintenance)
extra pathlength to access enterprise (performance)
ORBs are not yet ubiquitous (maintenance)
Best application:
intranet applications needing high function a GUI

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 10 of 50
IBM Software Services for WebSphere

Web Services based application architecture


Client Application Web Services Enterprise Logic
Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home (product,

HTTP
(order) open

???
customerID customerID
create() sku customerID
orderID
quantity) Shipping
Customer description
status
{create
Marketing
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item [qty < 0] item product 0..n 0..1 customer
Action Confirm Confirm cancel()
Product Line Item Order (product,
Result Action [qty = 0] Cancel {modify item Confirm
Submit quantity)
[not all items Line Item Order
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action (product, quantity)} (product, quantity) quantity orderID
quantity {cancel order}
quantity)} ok status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

Pros (same as distributed objects except):


language and platform neutrality (flexibility)
no ORB required on client (maintenance)
other protocols supported, like JMS/MQ
Cons (same as distributed objects except):
SOAP/HTTP does not have all the features of IIOP (reliability)
XML takes extra time to transfer/process (performance)
transactions not supported across calls yet
Best application:
extranet/internet applications needing high function GUIs or EDI

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 11 of 50
IBM Software Services for WebSphere

Web enabled distributed object application architecture


Browser Web Application Distributed Enterprise Logic
Server Object Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home (product,

HTTP IIOP
(order) open

???
customerID customerID create() sku customerID
orderID
quantity) Shipping
Customer description
status
{create
Marketing
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item [qty < 0] item product 0..n 0..1 customer
Action Confirm Confirm cancel()
Product Line Item Order (product,
Result Action [qty = 0] Cancel {modify item Confirm
Submit quantity)
[not all items Line Item Order
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action (product, quantity)} (product, quantity) quantity orderID
quantity {cancel order}
quantity)} ok status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

Pros:
client tier needs install nothing specific (maintenance)
middle tier does not need enterprise clients (maintenance)
business logic separated from application server (security)
can load balance application & object servers (scalability)
Cons:
remote method pathlength (performance)
Best application:
web enabling any phase of a business process

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 12 of 50
IBM Software Services for WebSphere

Programming model best practices

Aspects of the programming model for a given tier to consider:


components that you develop hosted on that tier
mechanisms used to flow control between components
sources used to flow data between components

Component Control Flow Data Source


HTML, XML, HTTP requests, URL Query String,
Browser Framesets, Applets JavaScript, Java POST Data, Cookies
Application Servlets, Java Server sendRedirect(), Request, Session,
Server Pages, Java Beans forward(), include() Servlet Context
Distributed Session EJB, Entity
RMI/IIOP JNDI, JDBC, others
Object Server EJB, Java Beans
Enterprise BMP Entity EJB, beforeXXX(),
JNDI, JDBC, others
Server SessionSynch EJB afterXXX(), ejbXXX()

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 13 of 50
IBM Software Services for WebSphere

Java client design considerations


In this section we will discuss techniques useful in the design of
any Java client application, including HttpServlets, and whether
distributed objects are used or not
Browser Web Application Distributed Enterprise Logic
Server Object Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home

HTTP
(product,

IIOP
(order) open

???
customerID customerID create() sku customerID
orderID
quantity) Shipping
Customer description
status Marketing
{create
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item [qty < 0] item product 0..n 0..1 customer
Action Confirm Confirm cancel()
Product Line Item Order (product,
Result Action [qty = 0] Cancel {modify item Confirm [not all items Line Item Order
Submit quantity)
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action quantity)} (product, quantity) quantity orderID
(product, {cancel order}
quantity ok
quantity)} status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 14 of 50
IBM Software Services for WebSphere

Java client design approaches


In part one we thought about the problems associated with having
the business logic coded in the client application components...
Customer
problem 1: increases Home Order problem 5:
code complexity Status reduces
(order) open opportunities
for reuse
{create
Product (order) order} ok
Catalog Order Confirm
cancel Details Open
add to order (order)
{add item edit line item submit problem 4: reduces
(order)
(product, quantity)} Confirm {modify item opportunities for parallel
Cancel (product, Confirm
Submit development
ok quantity)}
{cancel order} ok
{submit order}
Action
Result problem 3: makes
problem 2: makes testing maintenance more difficult
and debugging harder

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 15 of 50
IBM Software Services for WebSphere

A top down approach to the data flow contract


We also saw previously that you can drive the flow from View
Beans accessible within the application flow (top down)
Product Order Order Customer
Catalog Details Status Home
customerID customerID
orderID
status

0..n 0..n 0..n

Product Line Item Order Action Confirm


Result Action
productID productID orderID message action
description description status
quantity

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 16 of 50
IBM Software Services for WebSphere

Business logic access beans - bottoms up approach


Another approach is to develop a business logic access bean
for each state in the business process model
what about methods to
retrieve data required?
add line item
(product,
create() quantity)
Customer Packer
Marketing
ship (shipper)
Entry submit() [all items
Fulfillment shipped]
modify line Completed purge
item cancel()
(product, [not all items
quantity)
pack line item shipped]
(product, quantity)
tradeoff: stateless access
beans must add role and regardless of access bean type, role
order to signatures would need to be added to create

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 17 of 50
IBM Software Services for WebSphere

A bottom up approach to business logic access beans


And you can add methods to retrieve data accessible
within the business process state (bottom up)...

Product Customer
sku customerID
description

openOrder

product 0..n 0..1 customer


Line Item Order
0..n
quantity orderID
status

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 18 of 50
IBM Software Services for WebSphere

Basic Java client design approaches summary


Use a Java Bean to wrapper units of work into "access beans"
this is the general concept of an access bean independent from
those generated by VAJ
separate business logic from application flow logic in client
can independently evolve the underlying technology used
Granularity approaches trade the ability to do parallel
development for fewer system management entities:
one wrapper per unit of work
one per application flow model state (use for web up)
one per business process model state (use for enterprise out)
Programming model approaches trade number of calls for
simplicity of method signatures
stateless: one call with all parameters passed in and returned
stateful: multiple calls across access lifecycle more closely map
to business process model
In any event, throw structured exceptions rather than strings
October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 19 of 50
IBM Software Services for WebSphere

Business logic access beans end-to-end flow


Using a business logic access bean to wrapper units of work
needed by the application
Web Order Order Order
Application Details Details Entry
Server Servlet Data Access
doGet(req, res) problem: creates
{get order parm} unnecessary garbage
advantage 2: new()
doXXX() method OrderEntryAccess
only handles getOrderDetails("1000")
application control {get details for
and data flow order 1000}
1 n
advantage 3: can use new(v , ..., v )
1 1 n n
access bean in different [p =v , ..., p =v ]
client paradigms req.setAttribute( OrderDetailsData
"OrderDetails",OrderDetailsData) OrderDetailsData
[OrderDetails = advantage 1: can
OrderDetailsData] develop & modify
{forward to business process
OrderDetailsJSP} logic separately

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 20 of 50
IBM Software Services for WebSphere

Access Bean static singleton() end-to-end flow


Remember to use a static singleton() method on a stateless
Access Bean class instead of new() to minimize garbage
Web Order Order Order
Application Details Details Entry
Server Servlet Data Access
doGet(req, res)
{get order parm} singleton()
advantage 1: only [static instance=null]
one instance per new()
class loader [static instance =
OrderEntryAccess]
advantage 2: can cache OrderEntryAccess
variables that are getOrderDetails("1000")
shared across clients
{get details for
in the same JVM order
1 n 1000}
problem: still new(v , ..., v )
1 1 n n
haven't addressed [p =v , ..., p =v ]
the details of the OrderDetailsData
busines logic OrderDetailsData
{set request attribute and forward to the OrderDetailsJSP}

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 21 of 50
IBM Software Services for WebSphere

Where does this leave us?


With a well architected client-server application but a poorly
designed business logic access bean
Order Order
Details Entry
Servlet Access
singleton()
[static instance=null]
new() {get connection}
[con = Connection]
[static instance = OrderEntryAccess]
OrderEntryAccess
getOpenOrder(1111)
methods [OrderDetailsData.customerID = 1111]
mix up {get open order for customer 1111 from CUSTOMER table}
business [OrderDetailsData.orderID = 1000]
logic with {get status for order 1000 from ORDER table}
persistence [OrderDetailsData.status = "Opened"]
logic
{get items for order 1000 from LINEITEM table}
[OrderDetailsData.items = LineItem[]]
OrderDetailsData

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 22 of 50
IBM Software Services for WebSphere

Business Object Access Beans


Use business object access beans in business logic access
beans to isolate persistence logic
Order Order Customer Order LineItem
Details Entry Access Access Access
Servlet Access
getOpenOrder(1111)
advantage 2: facilitates
[OrderDetailsData.customerID = 1111] evolution to new technologies
getOpenOrder(1111)
{get open order for customer 1111 from CUSTOMER table}
1000
[OrderDetailsData.orderID = 1000]
advantage 1: simplifies getStatus(1000)
business logic {get status for order 1000 from ORDER table}
"Opened"
[OrderDetailsData.status = "Opened"]
getLineItems(1000)
{get items for order 1000
from LINEITEM table}
LineItem[]
[OrderDetailsData.items = LineItem[]]
OrderDetailsData

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 23 of 50
IBM Software Services for WebSphere

Business object access beans bottoms up approach


Consider a business object access bean for each domain object
in the static model with an associated key and data object

Product Customer
sku customerID
description

openOrder

product 0..n 0..1 customer


Line Item Order
0..n
quantity orderID
status

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 24 of 50
IBM Software Services for WebSphere

Business object access beans data flow considerations

Also consider flowing View Beans in and out of the


business object access beans (more on this later)
Product Order Order Customer
Catalog Details Status Home
customerID customerID
orderID
status

0..n 0..n 0..n

Product Line Item Order Action Confirm


Result Action
productID productID orderID message action
description description status
quantity

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 25 of 50
IBM Software Services for WebSphere

Access Bean caching


And don't forget to defer caching to business logic or business object
access bean methods to simplify client application flow logic
Order Order Order Order
Entry Details Entry Details
Client Data Access Hashtable
[cache = Order [table = []]
getOrderDetails("1000") Details Hashtable]
advantage 1: get("1000")
application clients null
simply invoke the {get details for order 1000} advantage 2: minimizes
1 n
appropriate new(v , ..., v ) server accesses across
business logic 1 1 n n whole JVM
access bean [p =v , ..., p =v ] put("1000",
methods OrderDetailsData OrderDetailsHashtable)
[table = [
OrderDetailsData (1000, OrderDetailsData)]]
tradeoff: complexity
{...}
required to maintain cache
getOrderDetails("1000")
get("1000") and cluster consistency
OrderDetailsData

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 26 of 50
IBM Software Services for WebSphere

Summary for advanced Java client design

1. Business logic access beans encapsulate units of work


2. Data structure Java Beans to encapsulate data flow
3. Throw meaningful structured exceptions (nested if needed)
4. Use singleton or pooling patterns to minimize garbage
5. Business object access beans encapsulate static model
components
6. Design business object methods to minimize number of calls
required per unit of work in business logic access bean
7. Separate unit of work into validation and update methods
when validation is likely to change or update is expensive
8. Defer caching to either the business logic or business object
access bean to simplify the client

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 27 of 50
IBM Software Services for WebSphere

Basic EJB design


In this section we will discuss techniques for designing
Enterprise Java Beans that provide the benefits of distributed
objects to any client application type

Browser Web Application Distributed Enterprise Logic


Server Object Server & Data Server
Customer
Home Order
Product Order Order Customer Status add line item Product Customer
Catalog Details Status Home

HTTP
(product,

IIOP
(order) open

???
customerID customerID create() sku customerID
orderID
quantity) Shipping
Customer description
status Marketing
{create
Product order} ok ship (shipper)
Catalog Order Confirm [all items
products items orders Details Open Entry submit() openOrder
cancel Fulfillment shipped]
add to submit modify line
0..n 0..n 0..n order Completed purge
edit line item [qty < 0] item product 0..n 0..1 customer
Action Confirm Confirm cancel()
Product Line Item Order (product,
Result Action [qty = 0] Cancel {modify item Confirm [not all items Line Item Order
Submit quantity)
productID productID orderID message orderID {add item ok
(product, pack line item shipped] 0..n
description description status action quantity)} (product, quantity) quantity orderID
(product, {cancel order}
quantity ok
quantity)} status
Action {submit order}
Result

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 28 of 50
IBM Software Services for WebSphere

Distributed object considerations


Think about the problems associated with having the
business logic run in the client, whether wrappered or not...
problem 1: no problem 2: proprietary problem 3:
application isolation logic runs in client transactions must be
add line item explicitly managed
(product,
create() quantity)
Customer Packer
Marketing
ship (shipper)
Entry submit() [all items
Fulfillment shipped]
modify line Completed purge
item cancel()
(product, [not all items
quantity)
pack line item shipped]
problem 4: cannot (product, quantity) problem 6: can't
separately load easily trace and
balance business problem 5: require all enterprise monitor code
process code access code to be installed on client separately

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 29 of 50
IBM Software Services for WebSphere

Stateless session EJB

Remote - or not; deployment time decision.


Manageable - pooled, monitored ...
Isolated - separate classloaders
Workload Managed
Declarative Transactions - no client code
Container managed authorisation - no server code
Well-defined packaging

Session Bean Facade - widely adopted pattern

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 30 of 50
IBM Software Services for WebSphere

Stateful Session EJB


Per-client - affinity is managed by container
Could be used to cache commonly used session data
minimizes calls to the back end
cache data that can be recreated in event of failure
probably not best for WIP data because ...
Timeout and failover become issues
update methods write non transient data to backing store
custom creates use a parameter to load data from store
some go as far as to use session synchronization (discussed later)
in either case, cache and cluster consistency become issues
Tends to defeat the purpose of a stateful session EJB as a
simple shared cache
starts sounding a lot like an entity EJB

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 31 of 50
IBM Software Services for WebSphere

Session Enterprise Java beans top down approach


Consider a session Enterprise Java bean patterned after
each business logic access bean to implement logic

add line item


(product,
create() quantity)
Customer Packer
Marketing
ship (shipper)
Entry submit() [all items
Fulfillment shipped]
modify line Completed purge
item cancel()
(product, [not all items
quantity)
pack line item shipped]
(product, quantity)

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 32 of 50
IBM Software Services for WebSphere

Session Enterprise Java Beans end-to-end flow


Use a session EJB in a business logic access bean when
required for scalability or isolation
Order Order Order Order JNDI
Details Entry Entry Entry Initial
Servlet Access (Session) Home Context
singleton()
[static instance=null] tradeoff: remote method call overhead
lookup("OrderEntry").narrow()
new()
OrderEntryHome
[home = OrderEntryHome] advantage 2: can use
[static instance = OrderEntryAccess] caching to minimize
OrderEntryAccess home lookups
getOpenOrder(1111) home.create()
OrderEntry
advantage 1: no
business logic in getOpenOrder(1111)
web application {get open order for customer 1111}
server OrderDetailsData issue: business object
remove() access beans must deal with
OrderDetailsData
persistence and transactions

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 33 of 50
IBM Software Services for WebSphere

Entity EJB
Data with indentity - primary key
Relationships to other entities - Employee/Department
If CMP then all persistence handled by container.

What we said about Session Beans applies - mostly ...

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 34 of 50
IBM Software Services for WebSphere

Entity EJB - other benefits over plain Java


Remote - or not; deployment time decision
but by policy choose always to access locally ...
... from the Session Bean layer
Manageable - pooled, monitored ...
Isolated - separate classloaders (from client)
Workload Managed
in conjunction with wrapping Session Beans
Declarative Transactions
Typically inherits from Session bean
Container managed authorisation - no server code
Well-defined packaging

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 35 of 50
IBM Software Services for WebSphere

Entity Enterprise Java Beans top down approach


Consider an entity EJB patterned after each business
object access bean to implement persistence layer

Product Customer
sku customerID
description

openOrder

product 0..n 0..1 customer


Line Item Order
0..n
quantity orderID
status

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 36 of 50
IBM Software Services for WebSphere

Entity Enterprise Java Beans end-to-end flow


Use entity EJBs in business object access beans to handle
persistence and transaction logic transparently
Order Order Order Order JNDI
Entry Access (Entity) Home Initial
(Session) Context
singleton()
new().lookup("OrderHome").narrow()
new() OrderHome
[home = OrderHome] advantage: persistence logic
OrderAccess provided by EJB container
getOrderDetails(1000) home.findByPrimaryKey(1000)
{find Order Entity EJB and load CMP fields}
Order
{new OrderDetailsData}
i
getP ()
i problem: multiple
{repeat} v remotable gets and
i
{set v into OrderDetailsData} sets
OrderDetailsData tradeoff: remotable method call overhead
(usually co-deployed)

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 37 of 50
IBM Software Services for WebSphere

Entity EJB custom method considerations

Method signatures trade the number and size of calls with


simplicity and reusability:
one property at a time
all properties needed for a given unit of work
query by example
all properties associated with entity
Various types are needed to support the entity lifecycle:
creates and finders (on the Home interface)
gets, sets, validations and updates (on the Remote interface)
In general you should make only one call after a find
remove after some kind of function is one exception
when validation is separated from update is another

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 38 of 50
IBM Software Services for WebSphere

Entity EJB custom methods


Use custom methods on an entity EJB to set/get groups of
properties in a single remoteable call
Order Order Order Order Order
Entry Access Details Home (Entity)
(Session) Data
getOrderDetails(1000)

[home =
OrderHome]
home.findByPrimaryKey(1000)
advantage 2: {find Order Entity EJB and
simplifies client load CMP fields}
code Order
getOrderDetails()
1 n
advantage 1: new(v , ..., v )
minimizes 1 1 n n
remoteable calls [p =v , ..., p =v ]
OrderDetailsData
OrderDetailsData

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 39 of 50
IBM Software Services for WebSphere

Summary for basic EJB design

1. Consider session EJBs in business logic access bean to get


benefits of distribution
2. Use stateless session EJB s wherever possible to maximize
scalability characteristics of application
3. Only use stateful session EJBs when timeout and failover of
cache are not issues, otherwise choose entity EJBs
4. Consider entity EJBs in business object access beans to
separate business logic from persistence logic
5. Use custom creates, finds, gets, sets and updates in entities
to minimize number of remotable calls
6. Treat all entity EJBs as CMPs when programming for
functional requirements

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 40 of 50
IBM Software Services for WebSphere

Summary of requirements to J2EE mapping

Customer
Home Order
Product Customer
Product Order Order Customer Status add line item
Catalog Details Status Home (order) open (product, sku customerID
customerID create()
customerID quantity) description
orderID Customer Shipping
status {create Marketing
Product order} ok ship (shipper)
Catalog Order Confirm
products items orders Details Open Entry submit() [all items openOrder
add to cancel submit Fulfillment shipped]
0..n order modify line
0..n 0..n edit line item Completed purge
Confirm
[qty < 0] item cancel() product 0..n 0..1 customer
Product Line Item Order Action Confirm Cancel Confirm (product,
Result Action [qty = 0] {modify item [not all items
productID {add item (product,
Submit quantity)
pack line item shipped] Line Item Order
productID orderID message orderID ok quantity)}
description description status action (product, {cancel order} (product, quantity) 0..n
quantity quantity)} ok quantity
Action {submit order}
orderID
Result status

Application flow Application flow Business process Business process


static model dynamic model dynamic model static model

Data structure Superclass Business logic Business object


JavaBean: servlet: access bean: access bean:
<Object>Data <Role>Servlet <State>Access <Object>Access
doGet
Java Server doPost
Session EJB: Data structure
Page: include,...
<State>Home JavaBean:
<State>.jsp <State> <Object>Data
DTD, XSL Application flow <State>Bean <Object>Key
servlet: Entity EJB:
<Object>.dtd
<State>Servlet
<State>.xsl <Object>Home
doGet<Role> custom creates
doPost<Role> custom finders
<Object>
<Object>Bean
custom gets, sets,
updates, validates

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 41 of 50
IBM Software Services for WebSphere

WebSphere 5.0 & EJB 2.0 Features


placeOrder(stock, quantity, customer)
{
Wine
// Check available stock WineId Customer
CustomerId
Chateau
// Calculate order value Name 1
1
// Update available stock
// Save Order *
} *
Stock
StockId 1
* Order
Vintage OrderId
Read Stock for key ... Price
QuantityInStock
Cost

public class Stock {


Update Stock Record
Integer getVintage() { /*... */ }
Integer getPrice() { /* ... */ }

Integer getQuantityInStock() { /* ... */ }

void setQuantityInStock(int q) { /* ... */ }

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 42 of 50
IBM Software Services for WebSphere

CMP - the code we don't write


Bean(Implementation)
public abstract class StockBean
implements javax.ejb.EntityBean { Local Interface (Local Client view)
public interface StockLocal extends
public abstract Integer getYear();
javax.ejb.EJBLocalObject {

public abstract void public java.lang.Integer getYear();


setYear(Integer newYear); public void setYear(Integer newYear);
}
EJB LifeCycle Methods
}

Local Home(factory)
public interface StockLocalHome extends Deployment Descriptor
javax.ejb.EJBLocalHome { <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar id="ejb-jar_ID">
<display-name>DemoEJB</display-name>

public ubs.wine.entity.StockLocal
<enterprise-beans>
<session id="Cellar">
<ejb-name>Cellar</ejb-name>
<home>ubs.wine.session.CellarHome</home>
<remote>ubs.wine.session.Cellar</remote>
<ejb-class>ubs.wine.session.CellarBean</ejb-class>

create(Integer sid) throws CreateException;


<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>

public ubs.wine.entity.StockLocal Database Mapping


findByPrimaryKey( StockKey primaryKey)
throws FinderException; Attribute 1 <==> Column 3
Attribute 2 <==> Column 6
}

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 43 of 50
IBM Software Services for WebSphere

Code we do write - no persistence logic, just object code


Bean(Implementation)
public class CellarBean implements Wine
javax.ejb.SessionBean { WineId Customer
CustomerId
Chateau
public String getStockDetails(StockKey stockid) { Name 1
// ... 1

StockLocal stock =
*
stockHome.findByPrimaryKey(stockid); *
Stock
StockId 1
* Order
StockCB stockDetails = new StockCB(); Vintage OrderId
Price Cost
stockDetails.populate(stock); QuantityInStock
return
// ... stockDetails.toString();
} public class StockCB implements Serializable {
} public void populate(StockLocal stockEntity) { Cargo
setYear( stockEntity.getYear() );
setPrice( stockEntity.getPrice());
population
setQuantityInStock( stockEntity.getCases() );
setChateau( stockEntity.getWineforstock().getChateau() );
setWineName( stockEntity.getWineforstock().getName() );

} October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 44 of 50
IBM Software Services for WebSphere

When the Container controls it can ...

Monitor
Performance monitoring hooks
Optimise
By Caching
By improving Data Access

Improve Application
Performance Without
Code Change

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 45 of 50
IBM Software Services for WebSphere

Example 1: Entity EJB - Relationship Navigation

stockHome.findByPrimaryKey(stockid);

setYear( stockEntity.getYear() );
setPrice( stockEntity.getPrice());
setQuantityInStock( stockEntity.getCases() );

setChateau( stockEntity.getWineforstock().getChateau() );
setWineName( stockEntity.getWineforstock().getName() );

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 46 of 50
IBM Software Services for WebSphere

Example 1: Entity EJB - Relationship Navigation


// Transaction already established

stockEntity == findByPrimaryKey(stockid)
stockEntity findByPrimaryKey(stockid)

stockEntity.getYear()
stockEntity.getPrice() wine

stockEntity.getWineforstock().getChateau()
stockEntity.getWineforstock().getChateau()
stockEntity.getWineforstock().getName()

Select * from Wine


stock where id = stock.wid
StockHome
Wine
WineId
Chateau
Name

Select * from Stock


where id = ?
Stock
StockId
Vintage
Price
QuantityInStock

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 47 of 50
IBM Software Services for WebSphere

Example 2: Entity EJB - Declare Access Intent


// Transaction already established

stockEntity == findByPrimaryKey(stockid)
findByPrimaryKey(stockid) Use a ReadAhead hint to say
stockEntity
When you findByPrimaryKey also
stockEntity.getYear()
prefetch the associated Wine
stockEntity.getPrice()

stockEntity.getWineforstock().getChateau()
stockEntity.getWineforstock().getName()
stock wine

StockHome
Select * from Stock, Wine Wine
WineId
where stockId = ? Chateau
Name

and wineId = stock.wid

Stock
StockId
Vintage
Price
QuantityInStock

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 48 of 50
IBM Software Services for WebSphere

Development role perspective


Application Business Operational
Page Layout
Concern Flow Logic Environment
and Content
(Controller) (Model) (Application)
(View)

Role
Page Producer Application Assembler Bean Builder Deployer

Components Java Server Data Beans, EJB


HTTP Servlets,
Pages, HTML, Access Beans, container
Produced MIME types
View Beans, Tags
EJBs methods

Components View Beans, Data Beans, Data Beans, EJBs,


Used Tags JSPs Access Beans, Data Beans
EJBs
Programming Little
Pure Pure Java, SQL,
Skills or
Java Java CICS, ...
None
Required
WYSIWYG OOAD, OOAD, Specialized
Tools Editors Java IDE Java IDE Wizards
Best practice: "Let the right expert do the work."
October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 49 of 50
IBM Software Services for WebSphere

Meeting the challenges

What qualities does this best practices architecture exhibit?


functional? - yes, an end to end architecture is detailed
reliable? - yes, addresses common application problems
usable? - yes, if you consider the UI model to be usable
efficient? - yes, tradeoffs are clearly identified
maintainable? - yes, there is a high degree of separation
portable? - yes, everything is vanilla Java or EJB methods
What about the development process it supports?
repeatable? - yes, given a STD describing the business process
measurable? - yes, the expected results are well defined
toolable? - yes, can use IDE, WYSIWYG editor, and Wizards
predictable? - more or less, since the code maps to the STD
scalable? - yes, separates flow, layout, business logic
flexible? - yes, can build down from or up to the AccessBean

October 28-29, 2003 | Sydney © 2003 IBM Corporation

03_Part_2_Dist_Obj_Design.PRZ 50 of 50

You might also like