134
jBPM 4 in Action jBPM 4 in Action by by Tom Baeyens & Joram Barrez Tom Baeyens & Joram Barrez

Devoxx 2009 University session Jbpm4 In Action

Embed Size (px)

Citation preview

Page 1: Devoxx 2009 University session Jbpm4 In Action

jBPM 4 in ActionjBPM 4 in Actionby by

Tom Baeyens & Joram BarrezTom Baeyens & Joram Barrez

Page 2: Devoxx 2009 University session Jbpm4 In Action

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

Page 3: Devoxx 2009 University session Jbpm4 In Action

3

Agenda

Part 1Part 2Part 3

Part 4

Very interesting

REALLY interesting !

Page 4: Devoxx 2009 University session Jbpm4 In Action

4

jBPM is great for BPM*and*

for developers

Page 5: Devoxx 2009 University session Jbpm4 In Action

makes your work flow

Page 6: Devoxx 2009 University session Jbpm4 In Action
Page 7: Devoxx 2009 University session Jbpm4 In Action
Page 8: Devoxx 2009 University session Jbpm4 In Action

8

Business process

An (organized) way of 'doing things'

... with a certain goal

Page 9: Devoxx 2009 University session Jbpm4 In Action

9

History lesson1723-1790, Adam Smith: The pin factory

– Labor division

1863-1947, Henry Ford: mass production– Assembly lines– Specialization

Page 10: Devoxx 2009 University session Jbpm4 In Action

10

History lessonWilliam E. Deming (1900-1993)

'Hero' of Japanese industryManufacturing processes ++

– Quality Circle– SPC– Six-Sigma– ...

Page 11: Devoxx 2009 University session Jbpm4 In Action

11

Processes are everywhere

Page 12: Devoxx 2009 University session Jbpm4 In Action

Processes are everywhere

Page 13: Devoxx 2009 University session Jbpm4 In Action
Page 14: Devoxx 2009 University session Jbpm4 In Action

14

Conclusion

Any company Any productAny service

They all have business processes

Page 15: Devoxx 2009 University session Jbpm4 In Action

15

Conclusion

Any company Any productAny service

Which means– 'Doing business'

== executing some business process

They all have business processes

Page 16: Devoxx 2009 University session Jbpm4 In Action
Page 17: Devoxx 2009 University session Jbpm4 In Action
Page 18: Devoxx 2009 University session Jbpm4 In Action

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

Page 19: Devoxx 2009 University session Jbpm4 In Action

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

Page 20: Devoxx 2009 University session Jbpm4 In Action

20

BPM Systems

~BPM engine or workflow engineExecutes the business processes

– Diagram––––– <tech-details />

Page 21: Devoxx 2009 University session Jbpm4 In Action

21

Introducing jBPM

Transactional state-machineGeneric graph execution engine

Page 22: Devoxx 2009 University session Jbpm4 In Action

22

Introducing jBPM

Transactional state-machineGeneric graph execution engine

But most of all...– A kick-ass BPM engine

Page 23: Devoxx 2009 University session Jbpm4 In Action

23

Main business advantages

Diagram: no disconnection between– What business expects– What IT delivers

AgileVisibility

– Monitoring, CEP, KPI

Page 24: Devoxx 2009 University session Jbpm4 In Action

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

Page 25: Devoxx 2009 University session Jbpm4 In Action

25

jBPM history

4 Jan 2003 : 5, 4, 3, 2, 1

... rrrrrrooooaaaaarrrrr ... and we have a lift off !

jBpm is present in sourceforge.net

Page 26: Devoxx 2009 University session Jbpm4 In Action

26

jBPM history

4 Jan 2003 : 5, 4, 3, 2, 1

... rrrrrrooooaaaaarrrrr ... and we have a lift off !

jBpm is present in sourceforge.net

Page 27: Devoxx 2009 University session Jbpm4 In Action

27

jBPM history

18 Oct 2004 : released JBoss jBPM 2.0

Page 28: Devoxx 2009 University session Jbpm4 In Action

28

jBPM history

Page 29: Devoxx 2009 University session Jbpm4 In Action

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.

Page 30: Devoxx 2009 University session Jbpm4 In Action

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'

Page 31: Devoxx 2009 University session Jbpm4 In Action

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

Page 32: Devoxx 2009 University session Jbpm4 In Action

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

Page 33: Devoxx 2009 University session Jbpm4 In Action

33

jBPM history

July 2009:

jBPM4 is out!

Page 34: Devoxx 2009 University session Jbpm4 In Action

34

jBPM history

November 2009

jBPM 4.2 released

Page 35: Devoxx 2009 University session Jbpm4 In Action

Today

Page 36: Devoxx 2009 University session Jbpm4 In Action

Today

Page 37: Devoxx 2009 University session Jbpm4 In Action

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'

Page 38: Devoxx 2009 University session Jbpm4 In Action

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

Page 39: Devoxx 2009 University session Jbpm4 In Action

jBPM3 jBPM4

Page 40: Devoxx 2009 University session Jbpm4 In Action

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

Page 41: Devoxx 2009 University session Jbpm4 In Action

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

Page 42: Devoxx 2009 University session Jbpm4 In Action

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

Page 43: Devoxx 2009 University session Jbpm4 In Action

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

Page 44: Devoxx 2009 University session Jbpm4 In Action

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?

Page 45: Devoxx 2009 University session Jbpm4 In Action

Part 2: jBPM ConceptsPart 2: jBPM Concepts

Page 46: Devoxx 2009 University session Jbpm4 In Action

A Process

Page 47: Devoxx 2009 University session Jbpm4 In Action

An Execution

Execution

Page 48: Devoxx 2009 University session Jbpm4 In Action

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

Page 49: Devoxx 2009 University session Jbpm4 In Action

History

Page 50: Devoxx 2009 University session Jbpm4 In Action

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

Page 51: Devoxx 2009 University session Jbpm4 In Action

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

Page 52: Devoxx 2009 University session Jbpm4 In Action
Page 53: Devoxx 2009 University session Jbpm4 In Action

jPDL

• BPM focussed• Graph based• Readable, editable XML• Direct Java integration• Extended task management• Community

Available now!

Page 54: Devoxx 2009 University session Jbpm4 In Action

BPMN 2.0• BPM focussed• Graph based• Upcoming standard• Focus on modeling notation

Coming Soon!

Page 55: Devoxx 2009 University session Jbpm4 In Action

Building Community

BPEL 2.0• Web Service focussed (WSDL)• Script new service

as a function of other services• Block structured

Page 56: Devoxx 2009 University session Jbpm4 In Action

jBPM Overview

Repository

JVM

jBPM.jar

JDBC

RepositoryServiceExecutions

History

Tasks

Identity

ExecutionServiceHistoryServiceTaskService

IdentityService

YourApplication

Page 57: Devoxx 2009 University session Jbpm4 In Action

jBPM APIConfiguration cfg = new Configuration();

ProcessEngine processEngine = cfg.buildProcessEngine();

processEngine.getRepositoryService();processEngine.getExecutionService();processEngine.getHistoryService();processEngine.getTaskService();processEngine.getIdentityService();

jbpm.cfg.xml

Page 58: Devoxx 2009 University session Jbpm4 In Action

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>

Page 59: Devoxx 2009 University session Jbpm4 In Action

Installer Ant Scripts• Install, start & stop

– Hsqldb– JBoss– Tomcat

• Create, upgrade & drop jBPM schema

• Install jBPM into– JBoss (service archive)– Tomcat (libs+config)

Page 60: Devoxx 2009 University session Jbpm4 In Action

Part 3: Demo ExamplesPart 3: Demo Examples

Page 61: Devoxx 2009 University session Jbpm4 In Action

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

Page 62: Devoxx 2009 University session Jbpm4 In Action

62

Demo process

Ordering conference goodies

Page 63: Devoxx 2009 University session Jbpm4 In Action

63

First steps

Set up dev environmentUsing jBPM in embedded modeWork in iterations

– Create basic process (start–task-end)

– TDD our process

Page 64: Devoxx 2009 University session Jbpm4 In Action

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

Page 65: Devoxx 2009 University session Jbpm4 In Action

65

DEMODEMO•First stepsFirst steps

Page 66: Devoxx 2009 University session Jbpm4 In Action

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>

Page 67: Devoxx 2009 University session Jbpm4 In Action

67

DEMODEMO•DIY: custom activitiesDIY: custom activities

Page 68: Devoxx 2009 University session Jbpm4 In Action

68

Decision

Automatic choice of process flow– Process data– Business rule

Actual decision– Expression– Custom DecisionHandler

Page 69: Devoxx 2009 University session Jbpm4 In Action

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) { ... }}

Page 70: Devoxx 2009 University session Jbpm4 In Action

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>

Page 71: Devoxx 2009 University session Jbpm4 In Action

71

Decision - expression

Expression language– Juel (2.2: +methods)– Groovy– ...

<decision name="checkPayment" > <transition name="expensive" to="pay less" > <condition expr=”#{order.amount &gt; 999}” /> </transition> <transition name="cheap" to="pay more" /> <condition expr=”#{order.amount &lt; 1000}” /> </transition></decision>

Process variable

Page 72: Devoxx 2009 University session Jbpm4 In Action

72

DEMODEMO• DecisionsDecisions

Page 73: Devoxx 2009 University session Jbpm4 In Action

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

Page 74: Devoxx 2009 University session Jbpm4 In Action

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

Page 75: Devoxx 2009 University session Jbpm4 In Action

75

DEMODEMO• Switching to the real stuffSwitching to the real stuff

Page 76: Devoxx 2009 University session Jbpm4 In Action

Part 4: Advanced ConceptsPart 4: Advanced Concepts

Page 77: Devoxx 2009 University session Jbpm4 In Action

Agenda• jBPM Architecture• Process Deployment• Execution and persistence• Transactional control flow• More core features

Page 78: Devoxx 2009 University session Jbpm4 In Action

graph execution+

pers is tence=

transactional control flow

Page 79: Devoxx 2009 University session Jbpm4 In Action

jBPM Architecture: POJO Core• POJO Classes representing

– Process definitions– Runtime executions– History, tasks, identities,...

• Behaviour in the domain model• Domain model persistable with hibernate

Page 80: Devoxx 2009 University session Jbpm4 In Action

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

Page 81: Devoxx 2009 University session Jbpm4 In Action

jBPM Architecture: Services• Infrastructure around domain model

– Embeddability– Persistence / transactions

• Services• Interceptors• Environment• Commands

Page 82: Devoxx 2009 University session Jbpm4 In Action

Services• Main API• Services expose methods• Each method 1 command• Commands passed down interceptor stack

– Aka chain of command– Configurable interceptor stack

Page 83: Devoxx 2009 University session Jbpm4 In Action

Servicespublic class ExecutionServiceImpl {

... public ProcessInstance startProcessInstanceById(String procDefId) {

return commandService.execute( new StartProcessInstanceCmd(procDefId,null,null)

); } ...

Page 84: Devoxx 2009 University session Jbpm4 In Action

Configurable Interceptor Stacks• Standalone• JTA• Spring• Remote• Async

incubation

Page 85: Devoxx 2009 University session Jbpm4 In Action

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

Page 86: Devoxx 2009 University session Jbpm4 In Action

Commands• Invoke methods on POJO's• Persistence operations

– Load– Save

Page 87: Devoxx 2009 University session Jbpm4 In Action
Page 88: Devoxx 2009 University session Jbpm4 In Action

Persistence

no

submit web sale

sales review

fork

end

send bill

wait for payment

join

ship items

all shipped ?

yes

Page 89: Devoxx 2009 University session Jbpm4 In Action

Persistence

no

submit web sale

sales review

fork

end

send bill

wait for payment

join

ship items

all shipped ?

yes

Execution

Transaction

1. Load

Page 90: Devoxx 2009 University session Jbpm4 In Action

Persistence

no

submit web sale

sales review

fork

end

send bill

wait for payment

join

ship items

all shipped ?

yes

2. UpdateExecution

Transaction

Page 91: Devoxx 2009 University session Jbpm4 In Action

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

Page 92: Devoxx 2009 University session Jbpm4 In Action

How Does jBPM Do It?• Deployment• Automatic activities• Wait states• Process concurrency• Async Continuations• Timers

Page 93: Devoxx 2009 University session Jbpm4 In Action

A Business Archive• Plain jar formatted file• .bar extension• Contents

– Process files– Process image– Classes– Forms– Rules– …

Page 94: Devoxx 2009 University session Jbpm4 In Action

Deployment

Page 95: Devoxx 2009 University session Jbpm4 In Action

Deployment With APIRepositoryService repositoryService =

processEngine.getRepositoryService();

String deploymentId =repositoryService.createDeployment() .addResourcesFromZipInputStream( “order.bar”) .deploy();

Page 96: Devoxx 2009 University session Jbpm4 In Action

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

Page 97: Devoxx 2009 University session Jbpm4 In Action

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 !

Page 98: Devoxx 2009 University session Jbpm4 In Action

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

Page 99: Devoxx 2009 University session Jbpm4 In Action

Process Instance• All state related to 1 execution of a

process definition• Potentially multiple pointers

keeping track of concurrent paths of execution

• Variables• Timers

Page 100: Devoxx 2009 University session Jbpm4 In Action

Execution• 1 path of execution

– 1 set of variables– 1 set of timers

Page 101: Devoxx 2009 University session Jbpm4 In Action

Structure• 1 process instance is a tree of executions

– Concurrency– Variable

scoping– Competing

events in 1 scope

Page 102: Devoxx 2009 University session Jbpm4 In Action

Full Automatic Example

Page 103: Devoxx 2009 University session Jbpm4 In Action

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

Page 104: Devoxx 2009 University session Jbpm4 In Action

Starting ProcessInstance

public void userClickedButtonEjbSessionCmt() { ... ProcessInstance processInstance = executionService

.startProcessInstanceByKey("example") ...}

SomeWeb

Framework

Tomcat

Page 105: Devoxx 2009 University session Jbpm4 In Action

Inside startProcessInstanceByKey• New execution• Executes “print dots”• Execution ends (deleted)• History remains

– Net result– Part of user TX

Page 106: Devoxx 2009 University session Jbpm4 In Action

Demo: Automatic ActivityDemo: Automatic Activity

Page 107: Devoxx 2009 University session Jbpm4 In Action

Observation• Automatic activities

run in thread of the web app• Exceptions in process

roll back webapp transaction• Error message to the user

Page 108: Devoxx 2009 University session Jbpm4 In Action

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

Page 109: Devoxx 2009 University session Jbpm4 In Action

Persisting State• Current state

– Position in process graph– Variables– Timers

• Waiting means – Persisting state– Committing transaction

Page 110: Devoxx 2009 University session Jbpm4 In Action

A Basic Wait State

Page 111: Devoxx 2009 University session Jbpm4 In Action

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

Page 112: Devoxx 2009 University session Jbpm4 In Action

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

Page 113: Devoxx 2009 University session Jbpm4 In Action

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

Page 114: Devoxx 2009 University session Jbpm4 In Action

Wait State Persistence2. Time goes by

– Execution state remains in the DB

Page 115: Devoxx 2009 University session Jbpm4 In Action

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

Page 116: Devoxx 2009 University session Jbpm4 In Action

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

Page 117: Devoxx 2009 University session Jbpm4 In Action

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

Page 118: Devoxx 2009 University session Jbpm4 In Action

Demo: Wait S tate ActivityDemo: Wait S tate Activity

Page 119: Devoxx 2009 University session Jbpm4 In Action

Process Execution Timeline

Page 120: Devoxx 2009 University session Jbpm4 In Action

Transactional Control Flow

Auto State AutoAuto Auto State Auto

1. executionService.startProcessInstanceByKey(…)

Java Object:

SQL: INSERT INTO JBPM4_EXECUTION …

execution

Page 121: Devoxx 2009 University session Jbpm4 In Action

Transactional Control Flow

Auto State AutoAuto Auto State Auto

2. executionService.signalExecutionById(…)

Java Object:

SQL: UPDATE JBPM4_EXECUTION …

execution

Page 122: Devoxx 2009 University session Jbpm4 In Action

Transactional Control Flow

Auto State AutoAuto Auto State Auto

3. executionService.signalExecutionById(…)

Java Object:

SQL: DELETE JBPM4_EXECUTION …

execution

Page 123: Devoxx 2009 University session Jbpm4 In Action

Concurrency• Parallel execution of activities• E.g. Order

– Shipping – Billing

• E.g. Loan– Sending loan money– Archiving contracts

Page 124: Devoxx 2009 University session Jbpm4 In Action

Execution Concurrency

Page 125: Devoxx 2009 University session Jbpm4 In Action

EventListeners• Attach POJO java code

to process execution event• Hidden from the graph

– For technical aspects

Page 126: Devoxx 2009 University session Jbpm4 In Action

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

Page 127: Devoxx 2009 University session Jbpm4 In Action

public class DoHidden implements EventListener {

public void notify(EventListenerExecution execution) {

... }}

Page 128: Devoxx 2009 University session Jbpm4 In Action

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

Page 129: Devoxx 2009 University session Jbpm4 In Action

Timers• Actions

– Take Transition– Event listeners

• Also handled by JobExecutor• Business Calendar

– 15 minutes– 4 bus iness hours

Page 130: Devoxx 2009 University session Jbpm4 In Action

Variables• HashMap associated to execution• Configurable type system• Scoping

Page 131: Devoxx 2009 University session Jbpm4 In Action

Other Important Features• SEAM integration• Spring integration• Instance migration• Automatic upgrades

Page 132: Devoxx 2009 University session Jbpm4 In Action

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

Page 133: Devoxx 2009 University session Jbpm4 In Action

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