adf worst practices (ukoug tech2013)

71
Worst Practices for Developing an ADF Application UKOUG ADF EMG Version 12.1.2.3.4.0.0b Build WORST_PRACTICES_12.1.2.3.4.0.0b_UKOUG_2013 ADF EMG S

Upload: wilfred-van-der-deijl

Post on 05-Dec-2014

3.576 views

Category:

Technology


2 download

DESCRIPTION

Presentation from UKOUG Tech13 conference on Worst Practices for Developing an ADF Application. This is a collection of worst practices and lessons to be learned collected by Steven Davelaar and Wilfred van der Deijl

TRANSCRIPT

Page 1: ADF Worst Practices (UKOUG Tech2013)

Worst Practices for Developing an ADF

ApplicationUKOUG ADF EMG Version 12.1.2.3.4.0.0b

Build WORST_PRACTICES_12.1.2.3.4.0.0b_UKOUG_2013 ADF EMG

S

Page 2: ADF Worst Practices (UKOUG Tech2013)

Paco van der LindenAMISwww.adfplus.com@pavadeli

Wilfred van der DeijlThe Future Groupwww.redheap.com@wilfreddeijl

About us

S

Page 3: ADF Worst Practices (UKOUG Tech2013)

Steven DavelaarOracleateam-oracle.com@stevendavelaar

Wilfred van der DeijlThe Future Groupwww.redheap.com@wilfreddeijl

About us

S

Page 4: ADF Worst Practices (UKOUG Tech2013)

Ideal project

● 1 developer

That’s you of course!

S

Page 5: ADF Worst Practices (UKOUG Tech2013)

Threats to a healthy ADF project

● Customer / Business / Functional designer

● Architect

● Project manager

S

Page 6: ADF Worst Practices (UKOUG Tech2013)

Threats to a healthy ADF project

● Customer / Business / Functional designer

● Architect

● Project manager

● Other developers

● Graphic designer

S

Page 7: ADF Worst Practices (UKOUG Tech2013)

Other Developers…Are not a member of ADF EMG

S

Page 8: ADF Worst Practices (UKOUG Tech2013)

Other Developers…Do not use ADF EMG Taskflow Tester

S

Page 9: ADF Worst Practices (UKOUG Tech2013)

ADF EMG Taskflow Tester - Wiki

S

Page 10: ADF Worst Practices (UKOUG Tech2013)

ADF EMG Taskflow Tester

S

Page 11: ADF Worst Practices (UKOUG Tech2013)

Other Developers… Don’t add ADF Source code library

● How to get ADF Source○ Go to support.oracle.com○ Log Service Request for JDeveloper/ADF○ “ADF Source Code Request” as problem type○ Sign agreement and upload to SR○ Get access to ZIP, typically within one day○ New versions don’t need new agreement

● Allows debugging of ADF framework

S

Page 12: ADF Worst Practices (UKOUG Tech2013)

Other Developers… Don’t add ADF Source code library

S

Page 13: ADF Worst Practices (UKOUG Tech2013)

Other Developers… Don’t adhere to ADF Code Guidelines

S

Page 14: ADF Worst Practices (UKOUG Tech2013)

ADF Code Guidelines

● 38 pages of excellent content by ADF guru’s● Topics include:

○ General Code Guidelines○ ADF Business Components○ ADF Faces○ ADF TaskFlows○ ADF Binding Layer○ Security○ High Availability○ … and more

S

Page 15: ADF Worst Practices (UKOUG Tech2013)

Other developers

● Don’t adhere to your project specific coding guidelines

● Other developers need your help○ Reserve time to review each other’s version control

commits○ You might learn from their code as well!!

● Reserve time to perform QA checks○ Against ADF coding guidelines and project specific

guidelines○ ...or automate this

■ come back tomorrow 10:15 - Exchange 6“Quality Assurance with JDev Auditing Framework”

S

Page 16: ADF Worst Practices (UKOUG Tech2013)

Threats to a healthy ADF project

● Customer / Business / Functional designer

● Architect

● Project manager

● Other developers

● Graphic designer

W

Page 17: ADF Worst Practices (UKOUG Tech2013)

W

Page 18: ADF Worst Practices (UKOUG Tech2013)

W

Page 19: ADF Worst Practices (UKOUG Tech2013)

W

Page 20: ADF Worst Practices (UKOUG Tech2013)

W

Page 21: ADF Worst Practices (UKOUG Tech2013)

W

Page 22: ADF Worst Practices (UKOUG Tech2013)

W

Page 23: ADF Worst Practices (UKOUG Tech2013)

Graphic designer - Pitfalls

● Website ≠ Application

● “HTML is for semantics, CSS is for layout…”○ ADF Fragment ≠ HTML, ADF skin ≠ CSS○ ADF Skin → primarily colours,

ADF Fragment → the rest

● Bad practice: CSS for layout management

W

Page 24: ADF Worst Practices (UKOUG Tech2013)

ADF Skinning Tips

● Use stand-alone Skin Editor

● Use ADF component selectors○ don’t look at the generated HTML○ use ADF Faces Skin Selectors Tag Reference

● Choice○ UI Designer to learn ADF skinning (preferred choice)○ ADF developer to learn CSS

W

Page 25: ADF Worst Practices (UKOUG Tech2013)

How to Write Code

W

Page 26: ADF Worst Practices (UKOUG Tech2013)

Logging

● Bad practice: System.err.println()● Best practice: ADFLogger

○ Configure at Runtime without restart○ Analyze Log for Performance○ Time your own code○ Better insight into ADF Framework internals

W

Page 27: ADF Worst Practices (UKOUG Tech2013)

ADFLogger - Runtime Configuration

W

Page 28: ADF Worst Practices (UKOUG Tech2013)

ADFLogger - Runtime Configuration

W

Page 29: ADF Worst Practices (UKOUG Tech2013)

ADFLogger - Log Analyzer

W

...or open log file from other (production) server

Page 30: ADF Worst Practices (UKOUG Tech2013)

bit.ly/adflogger

Time custom code withADFLogger::begin andADFLogger::end

W

Page 31: ADF Worst Practices (UKOUG Tech2013)

Understanding ADF Layers

● Bad: code ADF applications like open source frameworks

● What do we mean by that?○ All application state is kept in ViewController:○ Lots of data queried from ADF BC and stored in JSF

managed beans or entries in JSF memory scope maps

○ State passed back to ADF BC on subsequent requests: AM methods with lots of arguments

● Good: leverage ADF BC Active Data Model○ Easy access to previously entered data○ Row Currency management

S

Page 32: ADF Worst Practices (UKOUG Tech2013)

Understanding ADF Layers

● Signs of ViewController doing ADF BC work○ import oracle.jbo…○ Iterating RowSets○ Storing lots of data in memory scopes or managed

beans. Should only contain true UI state○ Calling ApplicationModule methods with lots of

arguments even when using binding layer● Project Audits often show 50-80% of

ViewController code is unnecessary○ Either completely redundant○ ...or should be moved to ADF BC layer

S

Page 33: ADF Worst Practices (UKOUG Tech2013)

ADF Facesa.k.a. the ViewController project

S

Page 34: ADF Worst Practices (UKOUG Tech2013)

ADF Lifecycle - Immediate property

● Bad: I run into issues, let’s try immediate=true● Big difference: immediate on input component

vs input on command component● Almost always wrong in input components● Make sure you understand both JSF lifecycle

and ADF Optimized Lifecycle

● Steven Davelaar’s 18 Lessons○ also available as ADF Insider Video

bit.ly/jsf-lifecycle

S

Page 35: ADF Worst Practices (UKOUG Tech2013)

Know your ADF Memory Scopes

● Bad: Overuse of SessionScope & PageFlowScope

● Can have significant impact on mem usage● Good: The smaller, the better● Do not cache shorter living objects

○ Should be cheap to request each time when needed○ Can have disastrous consequences, for example

caching binding objects

S

Page 36: ADF Worst Practices (UKOUG Tech2013)

S

Extreme Disastrous Caching

Page 37: ADF Worst Practices (UKOUG Tech2013)

S

Extreme Disastrous Caching

Page 38: ADF Worst Practices (UKOUG Tech2013)

Memory Scopes Guidelines

● SessionScope○ only use for user context○ often (UTF) PageFlowScope is better

■ Two browser tabs share SessionScope but have independent UTF PageFlowScope

● RequestScope○ often BackingBeanScope is better○ each ADF Region or Declarative Component has own

BackingBeanScope but share RequestScope● Bad: Accessing SessionScope beans from BTF

○ BTF should be reusable and not rely on SessionScope○ taskflow parameters are there for a reason○ Use ADF EMG TaskFlow Tester to ensure

independence

S

Page 39: ADF Worst Practices (UKOUG Tech2013)

“My ADF application is memory hungry”

We might have a (small) part of the solution

W

Page 40: ADF Worst Practices (UKOUG Tech2013)

JSF Component BindingJDeveloper Generated Code

<af:inputText binding=”#{pageFlowScope.MyBean.lastName}”/>

W

Page 41: ADF Worst Practices (UKOUG Tech2013)

JSF Component Binding

● First ask yourself if it is really needed● binding=”#{pageFlowScope.MyBean.lastName}”

references UIComponent in PageFlow bean● UIComponents should be released after each

request● But Managed Bean might require

PageFlowScope for its functionality

W

Page 42: ADF Worst Practices (UKOUG Tech2013)

JSF Component BindingComponentReference

W

Enhancement Request logged

Page 43: ADF Worst Practices (UKOUG Tech2013)

“My JSF Component seems to travel around”

W

Page 44: ADF Worst Practices (UKOUG Tech2013)

Building Component Tree

bit.ly/compbind

binding attribute

create component

call getter

call setter

create component

use component

No

Yes

Not Null

Null

W

Page 45: ADF Worst Practices (UKOUG Tech2013)

a.k.a. the Model project

ADF Business Components

W

Page 46: ADF Worst Practices (UKOUG Tech2013)

ADF BC Data Model - Master DetailBeware of excessive querying

Navigate row here...

Requery(if populated)

S

Page 47: ADF Worst Practices (UKOUG Tech2013)

ADF BC Data Model - Master DetailPrevent excessive querying

● Use top level ViewObject instances with bind variables

● or reset detail ViewObject on master row navigation

S

bit.ly/masterdetail

Page 48: ADF Worst Practices (UKOUG Tech2013)

ADF BC Data Model - Master DetailPrevent excessive querying

S

Page 49: ADF Worst Practices (UKOUG Tech2013)

“I encountered a dramatic ADF bug!!!Sometimes users lose entered data when the

application is under heavy load.”

W

Page 50: ADF Worst Practices (UKOUG Tech2013)

Disable Application Module Pooling

W

Page 51: ADF Worst Practices (UKOUG Tech2013)

Don’t Simply passivate all!

W

Page 52: ADF Worst Practices (UKOUG Tech2013)

“ADF has huge performance problems!!!When under heavy load requests can take

several minutes.”

“Besides, what is this PS_TXN table for? It is eating up our tablespace.”

W

Page 53: ADF Worst Practices (UKOUG Tech2013)

Don’t Simply Passivate All

● Every ViewRow with transient atts is persisted

● During activation all state is applied

W

Page 54: ADF Worst Practices (UKOUG Tech2013)

Simply passivate all?

○ Every ViewRow with transient atts is persisted

○ During activation all state is applied

No!

W

Page 55: ADF Worst Practices (UKOUG Tech2013)

What is passivated?

○ Set logger:oracle.jbo.server.Serializer

○ To:

S

Page 56: ADF Worst Practices (UKOUG Tech2013)

What is passivated?

○ Set logger:oracle.jbo.server.Serializer

○ To:

W

Page 57: ADF Worst Practices (UKOUG Tech2013)

“My ADF application is hacked!!!Sometimes users see data from other

sessions.”

“By the way, I did test the application with AM pooling off.”

W

Page 58: ADF Worst Practices (UKOUG Tech2013)

Application Module RecyclingNot Losing, but Leaking state

● AM Instances Recycled for other users under load

● Not detected by disabling AM pooling!

W

Page 59: ADF Worst Practices (UKOUG Tech2013)

Detecting State Leakage

W

Page 60: ADF Worst Practices (UKOUG Tech2013)

Default AM Pool Tuning

W

Page 61: ADF Worst Practices (UKOUG Tech2013)

Default ViewObject TuningW

Page 62: ADF Worst Practices (UKOUG Tech2013)

Eclipse Memory Analyzer Tool

bit.ly/eclipsemat

W

Page 63: ADF Worst Practices (UKOUG Tech2013)

Eclipse Memory Analyzer Tool (MAT)

● Make heap dump of running serverJDK_HOME/bin/jmap -dump:file=path jvm_process_id

● Download and run standalone Eclipse MAT● Inspect all objects in heap● Query Heap Objects● Predefined Reports and Tools

bit.ly/eclipsemat

W

Page 64: ADF Worst Practices (UKOUG Tech2013)

Java Mission Control

bit.ly/miscontrol

W

Page 65: ADF Worst Practices (UKOUG Tech2013)

Java Mission Control

● Any version of JRockit● Hotspot (aka Sun JVM) since 1.7.0_40● Record a period of time● Analyze

○ CPU performance○ Memory Usage○ Garbage Collection○ Thread Concurrency○ etcetera

W

Page 66: ADF Worst Practices (UKOUG Tech2013)

Miscellaneous

W

Page 67: ADF Worst Practices (UKOUG Tech2013)

Password management

● Bad: Credentials in clear text (eg. web.xml)● Worse: Override with deployment plans

bit.ly/secure-adf

W

Page 68: ADF Worst Practices (UKOUG Tech2013)

Reading Credential Store

bit.ly/secure-adf

W

Page 69: ADF Worst Practices (UKOUG Tech2013)

Load/Stress Testing

● 5 developers on a Friday afternoon:“Ready…. Set…. Go”

● Every ADF project initially has performance issues

● Consider ○ JMeter - Free open source, not optimized for ADF○ Oracle Application Testing Suite - ADF aware

● Requires○ Production like testing environment○ Good knowledge of chosen test tool○ 10 days setup (assuming test tool experience)

S

Page 70: ADF Worst Practices (UKOUG Tech2013)

Further Reading● bit.ly/adflogger

○ ADFLogger Custom Timings● bit.ly/secure-adf

○ FMW Credential Store● bit.ly/eclipsemat

○ Memory Analyzer Tool● bit.ly/miscontrol

○ Java Mission Control● bit.ly/jsf-lifecycle

○ Steven Davelaar’s JSF Lifecycle Lessons● bit.ly/compbind

○ JSF Component Bindings● bit.ly/masterdetail

○ Lazy Master Detail Query

S

Page 71: ADF Worst Practices (UKOUG Tech2013)

That’s all folks!

S