Upload
joram-barrez
View
2.414
Download
1
Tags:
Embed Size (px)
Citation preview
jBPM 4 in ActionjBPM 4 in Actionby by
Tom Baeyens & Joram BarrezTom Baeyens & Joram Barrez
2
Speaker’s qualificationsFounded jBPM in 2003Project Lead of jBPMPassionate about BPM and JavaArticles/international conferences
JBoss jBPM core developer (06/09)Before: jBPM/BPM consultant
3
Agenda
Part 1Part 2Part 3
Part 4
Very interesting
REALLY interesting !
4
jBPM is great for BPM*and*
for developers
makes your work flow
8
Business process
An (organized) way of 'doing things'
... with a certain goal
9
History lesson1723-1790, Adam Smith: The pin factory
– Labor division
1863-1947, Henry Ford: mass production– Assembly lines– Specialization
10
History lessonWilliam E. Deming (1900-1993)
'Hero' of Japanese industryManufacturing processes ++
– Quality Circle– SPC– Six-Sigma– ...
11
Processes are everywhere
Processes are everywhere
14
Conclusion
Any company Any productAny service
They all have business processes
15
Conclusion
Any company Any productAny service
Which means– 'Doing business'
== executing some business process
They all have business processes
18
The M in BPM
Business processes are ubiquitous
But ... this doesn't mean that– People know they are part of one– Everybody is doing the same – They are controlled or guided
19
The M in BPM
Managing business processes means– Everybody knows the what/when– There is guidance or control– Measurement (KPI)
Not a matter of 'buying BPM'– Organisational changes– Discipline
20
BPM Systems
~BPM engine or workflow engineExecutes the business processes
– Diagram––––– <tech-details />
21
Introducing jBPM
Transactional state-machineGeneric graph execution engine
22
Introducing jBPM
Transactional state-machineGeneric graph execution engine
But most of all...– A kick-ass BPM engine
23
Main business advantages
Diagram: no disconnection between– What business expects– What IT delivers
AgileVisibility
– Monitoring, CEP, KPI
24
Main technical advantagesSolves scattered business logic problem
– Clean separation between data/logicAudit/task mgmt/... capabilities for freeDoesn't dictate your architecture
– Embed with any java framework– Any transaction configuration– Any environment
25
jBPM history
4 Jan 2003 : 5, 4, 3, 2, 1
... rrrrrrooooaaaaarrrrr ... and we have a lift off !
jBpm is present in sourceforge.net
26
jBPM history
4 Jan 2003 : 5, 4, 3, 2, 1
... rrrrrrooooaaaaarrrrr ... and we have a lift off !
jBpm is present in sourceforge.net
27
jBPM history
18 Oct 2004 : released JBoss jBPM 2.0
28
jBPM history
29
jBPM history
24 May 2005 : The team is proud to declare
the beta1 releases of JBoss jBPM 3.0 !
Check out the sourceforge download pages and have fun...
8 may 2006: We are happy to announce
the release of JBoss jBPM 3.1.1.
30
jBPM history
They grow so fast...
3.1.2 3.1.3 3.1.43.2.0 3.2.1 3.2.2 3.2.3
3.2.4 3.2.5 3.2.6
'Back in the days I had spent a full two hours with MS Paint to create the first logo for jBPM.'
'Now that my project even had a logo, I was in full confidence. Nothing could stop me now'
31
jBPM history
They grow so fast...
3.1.2 3.1.3 3.1.43.2.0 3.2.1 3.2.2 3.2.3
3.2.4 3.2.5 3.2.6
'Back in the days I had spent a full two hours with MS Paint to create the first logo for jBPM.'
'Now that my project even had a logo, I was in full confidence. Nothing could stop me now'
'So I went to the conference and immediately I got a lot of valuable feedback'
.'Hey Tom, you're project is great
but your logo sucks bigtime!'
32
jBPM history
They grow so fast...
3.1.2 3.1.3 3.1.43.2.0 3.2.1 3.2.2 3.2.3
3.2.4 3.2.5 3.2.6
'This time I sticked to coding and left the paint job to the professionals. '
33
jBPM history
July 2009:
jBPM4 is out!
34
jBPM history
November 2009
jBPM 4.2 released
Today
Today
37
JBPM v4: what's new?Core engine completely revised
– 2nd generation PVM– Designed for cluster & performance– Not losing what made jBPM3 great
Incorporated lessons learned – 6 years of usage in the wild– Corner cases and even edgier– Simplified 'getting started'
38
JBPM v4: what's new?Clean & simplified
– New API (incl. cool query mechanism)– Compact db schema– Native Spring integration
Performance boostImproved tooling
– Sexy GWT console – Signavio web modeling
QA lab
jBPM3 jBPM4
40
JBPM v4: performanceDesigned with performance in mind
– Scalability/clusterability– Improved inner workings
Test method– 5 processes– Start --> end– 10K executions, 1-10 fixed threadpool
41
JBPM v4: performance
process01 process02 process03 process04 process05 random0
2
4
6
8
10
12
14
jBPM 4.2 basic benchmark - MySQL 5(10 000 execut ions)
Seq. exec.2 fixedTP3 fixedTP4 fixedTP5 fixedTP6 fixedTP7 fixedTP8 fixedTP9 fixedTP10 fixedTPav
g du
ratio
n (m
s)
Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HDDB and benchmark on same machine
42
JBPM v4: performance
process01 process02 process03 process04 process05 random0
2
4
6
8
10
12
jBPM 4.2 basic benchmark - Postgresql 8.3(10 000 executions)
Seq. exec.2 fixedTP3 fixedTP4 fixedTP5 fixedTP6 fixedTP7 fixedTP8 fixedTP9 fixedTP10 fixedTPav
g du
ratio
n (m
s)
Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HDDB and benchmark on same machine
43
JBPM v4: performance
process01 process02 process03 process04 process05 random0
2
4
6
8
10
12
jBPM 4.2 basic benchmark - Postgresql 8.3(10 000 executions)
Seq. exec.2 fixedTP3 fixedTP4 fixedTP5 fixedTP6 fixedTP7 fixedTP8 fixedTP9 fixedTP10 fixedTPav
g du
ratio
n (m
s)
Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HDDB and benchmark on same machine
44
JBPM v4: performance
Avg process exec. time– 0.75ms – 2ms– 1.8 mil./hour– Yeah, that's fast
jBPM overhead == (extremely) minimal– So what are you waiting for?
Part 2: jBPM ConceptsPart 2: jBPM Concepts
A Process
An Execution
Execution
History
HISTORY_PROCESS_INSTANCE
ID START END …PROCESS
HISTORY_ACTIVITY_INSTANCE
ID START END …HPI ACTIVITY
2 09:391 Check Credit09:39
3 09:421 Accept Quote09:42
4 10:031 Charge Customer10:0310:04
10:041 09:38Order-1
1 09:381 Calculate Quote
History
Software ProjectExecutable Business Process
Processes As Part Of Software Development
Abstract Business Process
Non-techBusiness Analyst Developer<details />
Java, XML, Buildscripts,Tests, …
EAPSOA-PJBossTomcatJDK 5
Oracle, MySQL, PostgreSQL
jBPM YourApp
SignavioWeb
Modeling
BPM Console
Task UI
JoprBAM BISimu
lation
Model Repository
MavenRepository
SVN Repository
jBPM
PVM
Repository
Executions
History
Tasks
jPDL BPMN2
RepoService
ExeService
HistService
TaskService
Identities
•Users•Groups•Memberships
…
jPDL
• BPM focussed• Graph based• Readable, editable XML• Direct Java integration• Extended task management• Community
Available now!
BPMN 2.0• BPM focussed• Graph based• Upcoming standard• Focus on modeling notation
Coming Soon!
Building Community
BPEL 2.0• Web Service focussed (WSDL)• Script new service
as a function of other services• Block structured
jBPM Overview
Repository
JVM
jBPM.jar
JDBC
RepositoryServiceExecutions
History
Tasks
Identity
ExecutionServiceHistoryServiceTaskService
IdentityService
YourApplication
jBPM APIConfiguration cfg = new Configuration();
ProcessEngine processEngine = cfg.buildProcessEngine();
processEngine.getRepositoryService();processEngine.getExecutionService();processEngine.getHistoryService();processEngine.getTaskService();processEngine.getIdentityService();
jbpm.cfg.xml
jbpm.cfg.xml<jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.tx.hibernate.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.console.cfg.xml" /> <import resource="jbpm.jobexecutor.cfg.xml" /></jbpm-configuration>
Installer Ant Scripts• Install, start & stop
– Hsqldb– JBoss– Tomcat
• Create, upgrade & drop jBPM schema
• Install jBPM into– JBoss (service archive)– Tomcat (libs+config)
Part 3: Demo ExamplesPart 3: Demo Examples
61
Getting started demo
Working with processes– Can be overwhelming (at first)
Downloaded zip -> business process– Let's hope the demo gods aren't looking
Basically ... a free training!– Please don't tell our bosses
62
Demo process
Ordering conference goodies
63
First steps
Set up dev environmentUsing jBPM in embedded modeWork in iterations
– Create basic process (start–task-end)
– TDD our process
64
jBPM 4 Task
Process execution waitsProcess state is persistedNew task created in DBFunctionality
– 'Work list': assignee, candidate-groups/users, swimlane, handler, ...
– notification/reminder mail– Timers
65
DEMODEMO•First stepsFirst steps
66
jBPM 4 DIY: custom activity
Business processes are business specificWe have a set of common activities
– And even more planned (jms, ejb, rules, calling your grandmother, ...)
Custom activities will always be neededPojo:<custom name="payout" class="com.devoxx.jbpm4.PayoutActivity"> <transition to="end1" /></custom>
67
DEMODEMO•DIY: custom activitiesDIY: custom activities
68
Decision
Automatic choice of process flow– Process data– Business rule
Actual decision– Expression– Custom DecisionHandler
69
Decision - handler<decision name="evaluate document"> <handler class="org.jbpm.xx.ContentEvaluation" /> <transition name="good" to="submit document" /> <transition name="bad" to="try again" /> <transition name="ugly" to="give up" /></decision>
public class ContentEvaluation implements DecisionHandler { public String decide(OpenExecution execution) { ... }}
70
Decision - expression
Expression language– Juel (2.2: +methods)– Groovy– ...
<decision name="evaluate document" expr="#{content}" > <transition name="good" to="submit document" /> <transition name="bad" to="try again" /> <transition name="ugly" to="give up" /></decision>
71
Decision - expression
Expression language– Juel (2.2: +methods)– Groovy– ...
<decision name="checkPayment" > <transition name="expensive" to="pay less" > <condition expr=”#{order.amount > 999}” /> </transition> <transition name="cheap" to="pay more" /> <condition expr=”#{order.amount < 1000}” /> </transition></decision>
Process variable
72
DEMODEMO• DecisionsDecisions
73
Put it in 'staging'
Next steps– Switch to a real database– jBPM web console– Deploy process as part of build (dev)– Incorporate task forms for user IO
simulation
74
Task form
Part of deployment – deployment.addResourceFromClasspath(…./my_form.ftl);– <task form="com/devoxx/jbpm4/my_form.ftl"
Freemarker templates– ${processVar}– <input type=”text” name=”myVar” />– Css
75
DEMODEMO• Switching to the real stuffSwitching to the real stuff
Part 4: Advanced ConceptsPart 4: Advanced Concepts
Agenda• jBPM Architecture• Process Deployment• Execution and persistence• Transactional control flow• More core features
graph execution+
pers is tence=
transactional control flow
jBPM Architecture: POJO Core• POJO Classes representing
– Process definitions– Runtime executions– History, tasks, identities,...
• Behaviour in the domain model• Domain model persistable with hibernate
ClientProcessDefinition processDefinition = ProcessDefinitionBuilder.startProcess() .startActivity("creditRate?", new
AutomaticCreditRating()) .initial() .transition("priority delivery", "good") .transition("payment upfront", "bad") .endActivity() .startActivity("priority delivery", new WaitState()) .endActivity() .startActivity("payment upfront", new WaitState()) .endActivity() .endProcess();
ClientProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.setVariable("creditRate", 7);processInstance.start();
incubation
jBPM Architecture: Services• Infrastructure around domain model
– Embeddability– Persistence / transactions
• Services• Interceptors• Environment• Commands
Services• Main API• Services expose methods• Each method 1 command• Commands passed down interceptor stack
– Aka chain of command– Configurable interceptor stack
Servicespublic class ExecutionServiceImpl {
... public ProcessInstance startProcessInstanceById(String procDefId) {
return commandService.execute( new StartProcessInstanceCmd(procDefId,null,null)
); } ...
Configurable Interceptor Stacks• Standalone• JTA• Spring• Remote• Async
incubation
Environment• Decouples POJO model from environment• Interceptorstack responsible
for setting up the environment• Domain model looks up configurable
stuff from the environment• E.g. hibernate session
Commands• Invoke methods on POJO's• Persistence operations
– Load– Save
Persistence
no
submit web sale
sales review
fork
end
send bill
wait for payment
join
ship items
all shipped ?
yes
Persistence
no
submit web sale
sales review
fork
end
send bill
wait for payment
join
ship items
all shipped ?
yes
Execution
Transaction
1. Load
Persistence
no
submit web sale
sales review
fork
end
send bill
wait for payment
join
ship items
all shipped ?
yes
2. UpdateExecution
Transaction
Persistence
no
submit web sale
sales review
fork
end
send bill
wait for payment
join
ship items
all shipped ?
yes
3. Save changes
Execution
Transaction
How Does jBPM Do It?• Deployment• Automatic activities• Wait states• Process concurrency• Async Continuations• Timers
A Business Archive• Plain jar formatted file• .bar extension• Contents
– Process files– Process image– Classes– Forms– Rules– …
Deployment
Deployment With APIRepositoryService repositoryService =
processEngine.getRepositoryService();
String deploymentId =repositoryService.createDeployment() .addResourcesFromZipInputStream( “order.bar”) .deploy();
Deployment With Ant<jar destfile="order.bar"> ...</jar>
<taskdef name="jbpm-deploy" classname="org.jbpm.pvm.internal.ant.JbpmDeployTask" classpathref="jbpm.libs.and.cfg" />
<jbpm-deploy file="order.bar" />
Deployment• Deployment
– HashMap– Representing zip file– Named resources
• Key– Entry name– String
• Value– Blob– byte[]
order.jpdl.xml 11111011…order.jpg 01011100…com/pinokkio/Order.class 00100100…order.rules.drl 01110100…
DEPLOYMENT “1”
Process class
versioning !
Deployers• Scan deployments• Publish objects• RepositoryCache
RepositoryCache
OrderRuleBase
DeployerJpdlDeployerorder.jpdl.xml 11111011…order.jpg 01011100…com/pinokkio/Order.class 00100100…OrderStartForm.ftl 01110100…
DEPLOYMENT “1”
DEPLOYMENT 1
DeploymentClassLoader
Process Instance• All state related to 1 execution of a
process definition• Potentially multiple pointers
keeping track of concurrent paths of execution
• Variables• Timers
Execution• 1 path of execution
– 1 set of variables– 1 set of timers
Structure• 1 process instance is a tree of executions
– Concurrency– Variable
scoping– Competing
events in 1 scope
Full Automatic Example
<process name="Automatic">
<start> <transition to="print dots" /> </start>
<custom name="print dots" class="com.devoxx.jbpm.automatic.PrintDots"> <transition to="end" /> </custom> <end name="end"/>
</process>
Starting ProcessInstance
public void userClickedButtonEjbSessionCmt() { ... ProcessInstance processInstance = executionService
.startProcessInstanceByKey("example") ...}
SomeWeb
Framework
Tomcat
Inside startProcessInstanceByKey• New execution• Executes “print dots”• Execution ends (deleted)• History remains
– Net result– Part of user TX
Demo: Automatic ActivityDemo: Automatic Activity
Observation• Automatic activities
run in thread of the web app• Exceptions in process
roll back webapp transaction• Error message to the user
Waiting• Thread nor transaction should be
blocked for long periods– Not scalable
• Waiting for – A user completing a task– An message from an external system– Some other web request– Anything for which
you don’t want to block the thread/transaction
Persisting State• Current state
– Position in process graph– Variables– Timers
• Waiting means – Persisting state– Committing transaction
A Basic Wait State
<process name="WaitState">
<start> <transition to="print dots" /> </start>
<custom name="print dots" class="com.devoxx.jbpm.automatic.PrintDots"> <transition to="wait" /> </custom>
<state name="wait"> <transition to="end" /> </state>
<end name="end" />
</process>
A Wait State• Execution will wait• Until a signal is given• Typically
– EventListener on start of state activity
– External trigger continues process• MDB, DB trigger, file scanner,...
Wait State Persistence1. executionService
.s tartProcess InstanceByKey(...)1. Creates new execution2. Starts executing from start activity3. Execution arrives in s tate4. Execution state will be saved5. Transaction will be committed6. jBPM service method will return
Wait State Persistence2. Time goes by
– Execution state remains in the DB
Wait State Persistence3. executionService
.s ignalExecutionById(...)1. Loads the execution2. Takes an outgoing transition3. Continues execution till next wait state4. Stores execution updates5. Commit transaction6. signalExecutionById returns
A Basic Wait State
// e.g. in the button click codeProcessInstance processInstance = executionService .startProcessInstanceByKey("WaitState");assertFalse(processInstance.isEnded());String pid = processInstance.getId();
// much later. e.g in another request or MDB executionService.signalExecutionById(pid);
transaction
transaction
Testing• Process == software• Test == 1 scenario• Provide external triggers• Assert execution state• Support for
– Integration testing• Test process as is
– Unit testing• Process updates allow stubs
Demo: Wait S tate ActivityDemo: Wait S tate Activity
Process Execution Timeline
Transactional Control Flow
Auto State AutoAuto Auto State Auto
1. executionService.startProcessInstanceByKey(…)
Java Object:
SQL: INSERT INTO JBPM4_EXECUTION …
execution
Transactional Control Flow
Auto State AutoAuto Auto State Auto
2. executionService.signalExecutionById(…)
Java Object:
SQL: UPDATE JBPM4_EXECUTION …
execution
Transactional Control Flow
Auto State AutoAuto Auto State Auto
3. executionService.signalExecutionById(…)
Java Object:
SQL: DELETE JBPM4_EXECUTION …
execution
Concurrency• Parallel execution of activities• E.g. Order
– Shipping – Billing
• E.g. Loan– Sending loan money– Archiving contracts
Execution Concurrency
EventListeners• Attach POJO java code
to process execution event• Hidden from the graph
– For technical aspects
<process name="WaitState">
<start> <transition to="wait" /> </start>
<state name="wait"> <on event="start"> <event-listener event="com.devoxx.jbpm.DoHidden"> </on> <transition to="end" /> </state>
<end name="end" />
</process>
public class DoHidden implements EventListener {
public void notify(EventListenerExecution execution) {
... }}
Asynchronous Continuations• Automatic activities in sequence• One takes a long time
– E.g. pdf generation• Don’t block the client thread• async=“true”
pdf-g
Transaction 1 Transaction 2
JobExecutor
Timers• Actions
– Take Transition– Event listeners
• Also handled by JobExecutor• Business Calendar
– 15 minutes– 4 bus iness hours
Variables• HashMap associated to execution• Configurable type system• Scoping
Other Important Features• SEAM integration• Spring integration• Instance migration• Automatic upgrades
Summary
• Fits ins ide your architecture• S upports multiple process languages• Facilitates collaboration• jBPM has real value for real developers
– Model process– Play with transactions– Write POJO code
I just know you're excited to give it a try
You can do it tonight Just before you go to sleep Or even in your bed
Last demo movie
Getting started
http://jbpm.orghttp://processdevelopments.blogspot.comhttp://jorambarrez.be/blog
makes your work flowQ&AQ&A