Devoxx 2009 University session Jbpm4 In Action

2,719 views

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,719
On SlideShare
0
From Embeds
0
Number of Embeds
503
Actions
Shares
0
Downloads
202
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Devoxx 2009 University session Jbpm4 In Action

  1. 1. jBPM 4 in Action by Tom Baeyens & Joram Barrez
  2. 2. Speaker’s qualifications Founded jBPM in 2003 Project Lead of jBPM Passionate about BPM and Java Articles/international conferences JBoss jBPM core developer (06/09) Before: jBPM/BPM consultant 2
  3. 3. Agenda Part 1 Part 2 Very interesting Part 3 Part 4 REALLY interesting ! 3
  4. 4. jBPM is great for BPM *and* for developers 4
  5. 5. makes your work flow
  6. 6. Business process An (organized) way of 'doing things' ... with a certain goal 8
  7. 7. History lesson 1723-1790, Adam Smith: The pin factory – Labor division 1863-1947, Henry Ford: mass production – Assembly lines – Specialization 9
  8. 8. History lesson William E. Deming (1900-1993) 'Hero' of Japanese industry Manufacturing processes ++ – Quality Circle – SPC – Six-Sigma – ... 10
  9. 9. Processes are everywhere 11
  10. 10. Processes are everywhere
  11. 11. Conclusion Any company They all have Any product business processes Any service 14
  12. 12. Conclusion Any company They all have Any product business processes Any service Which means – 'Doing business' == executing some business process 15
  13. 13. 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 18
  14. 14. 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 19
  15. 15. BPM Systems ~BPM engine or workflow engine Executes the business processes – Diagram – – – – – <tech-details /> 20
  16. 16. Introducing jBPM Transactional state-machine Generic graph execution engine 21
  17. 17. Introducing jBPM Transactional state-machine Generic graph execution engine But most of all... – A kick-ass BPM engine 22
  18. 18. Main business advantages Diagram: no disconnection between – What business expects – What IT delivers Agile Visibility – Monitoring, CEP, KPI 23
  19. 19. Main technical advantages Solves scattered business logic problem – Clean separation between data/logic Audit/task mgmt/... capabilities for free Doesn't dictate your architecture – Embed with any java framework – Any transaction configuration – Any environment 24
  20. 20. jBPM history 4 Jan 2003 : 5, 4, 3, 2, 1 ... rrrrrrooooaaaaarrrrr ... and we have a lift off ! jBpm is present in sourceforge.net 25
  21. 21. jBPM history 4 Jan 2003 : 5, 4, 3, 2, 1 ... rrrrrrooooaaaaarrrrr ... and we have a lift off ! jBpm is present in sourceforge.net 26
  22. 22. jBPM history 18 Oct 2004 : released JBoss jBPM 2.0 27
  23. 23. jBPM history 28
  24. 24. 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. 29
  25. 25. jBPM history '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' They grow so fast... 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 30
  26. 26. jBPM history '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!' They grow so fast... 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 31
  27. 27. jBPM history 'This time I sticked to coding and left the paint job to the professionals. ' They grow so fast... 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 32
  28. 28. jBPM history July 2009: jBPM4 is out! 33
  29. 29. jBPM history November 2009 jBPM 4.2 released 34
  30. 30. Today
  31. 31. Today
  32. 32. 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' 37
  33. 33. JBPM v4: what's new? Clean & simplified – New API (incl. cool query mechanism) – Compact db schema – Native Spring integration Performance boost Improved tooling – Sexy GWT console – Signavio web modeling QA lab 38
  34. 34. jBPM3 jBPM4
  35. 35. JBPM v4: performance Designed with performance in mind – Scalability/clusterability – Improved inner workings Test method – 5 processes – Start --> end – 10K executions, 1-10 fixed threadpool 40
  36. 36. JBPM v4: performance jBPM 4.2 basic benchmark - MySQL 5 (10 000 executio ns) 14 12 Seq. exec. 10 2 fixedTP 3 fixedTP 4 fixedTP avg duration (ms) 8 5 fixedTP 6 fixedTP 7 fixedTP 6 8 fixedTP 9 fixedTP 10 fixedTP 4 2 0 proces s01 proces s 02 proces s 03 proces s 04 proces s 05 random Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HD DB and benchmark on same machine 41
  37. 37. JBPM v4: performance jBPM 4.2 basic benchmark - Postgresql 8.3 (10 000 executio ns) 12 10 Seq. exec. 2 fixedT P 8 3 fixedT P 4 fixedT P avg duration (ms) 5 fixedT P 6 fixedT P 6 7 fixedT P 8 fixedT P 9 fixedT P 4 10 fixedTP 2 0 process 01 proces s 02 proces s 03 proces s 04 proces s 05 random Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HD DB and benchmark on same machine 42
  38. 38. JBPM v4: performance jBPM 4.2 basic benchmark - Postgresql 8.3 (10 000 executio ns) 12 10 Seq. exec. 2 fixedT P 8 3 fixedT P 4 fixedT P avg duration (ms) 5 fixedT P 6 fixedT P 6 7 fixedT P 8 fixedT P 9 fixedT P 4 10 fixedTP 2 0 process 01 proces s 02 proces s 03 proces s 04 proces s 05 random Config: Ubuntu 9.04, AMD Phenom II X4 3.0Ghz, 8Gb Ram, 7200rpm HD DB and benchmark on same machine 43
  39. 39. 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? 44
  40. 40. Part 2: jB PM C oncepts
  41. 41. A Process
  42. 42. An Execution Execution
  43. 43. History HISTORY_PROCESS_INSTANCE ID PROCESS START END … 1 Order-1 09:38 10:04 HISTORY_ACTIVITY_INSTANCE ID HPI ACTIVITY START END … 1 1 Calculate Quote 09:38 09:39 2 1 Check Credit 09:39 09:42 3 1 Accept Quote 09:42 10:03 4 1 Charge Customer 10:03 10:04
  44. 44. History
  45. 45. Processes As Part Of Software Development Software Project Abstract Business Process Executable Business Process Non-tech Business Analyst <details /> Developer Java, XML, Buildscripts, Tests, … EAP jBPM Your SOA-P App JBoss Tomcat JDK 5 Oracle, MySQL, PostgreSQL
  46. 46. Signavio Simu BPM BAM BI Web lation Console Jopr Modeling Task Model UI Repository jBPM jPDL BPMN2 … SVN PVM Repository Maven Repository RepoService Repository Executions ExeService History HistService Tasks TaskService Identities •Users •Groups •Memberships
  47. 47. jPDL Av ail ab le no w! • BPM focussed • Graph based • Readable, editable XML • Direct Java integration • Extended task management • Community
  48. 48. B PMN 2.0 Co mi ng So on ! • BPM focussed • Graph based • Upcoming standard • Focus on modeling notation
  49. 49. B PEL 2.0 B Co uild mm ing un ity • Web Service focussed (WSDL) • Script new service as a function of other services • Block structured
  50. 50. jBPM Overview JDBC Repository jBPM.jar Your Executions RepositoryService Application History ExecutionService Tasks Identity HistoryService TaskService IdentityService JVM
  51. 51. jBPM API jbpm.cfg.xml Configuration cfg = new Configuration(); ProcessEngine processEngine = cfg.buildProcessEngine(); processEngine.getRepositoryService(); processEngine.getExecutionService(); processEngine.getHistoryService(); processEngine.getTaskService(); processEngine.getIdentityService();
  52. 52. 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>
  53. 53. Installer Ant Scripts • Install, start & stop – Hsqldb – JBoss – Tomcat • Create, upgrade & drop jBPM schema • Install jBPM into – JBoss (service archive) – Tomcat (libs+config)
  54. 54. Part 3: Demo Examples
  55. 55. 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 61
  56. 56. Demo process Ordering conference goodies 62
  57. 57. First steps Set up dev environment Using jBPM in embedded mode Work in iterations – Create basic process (start–task-end) – TDD our process 63
  58. 58. jBPM 4 Task Process execution waits Process state is persisted New task created in DB Functionality – 'Work list': assignee, candidate- groups/users, swimlane, handler, ... – notification/reminder mail – Timers 64
  59. 59. DEMO •First steps 65
  60. 60. jBPM 4 DIY: custom activity Business processes are business specific We have a set of common activities – And even more planned (jms, ejb, rules, calling your grandmother, ...) Custom activities will always be needed Pojo: <custom name="payout" class="com.devoxx.jbpm4.PayoutActivity"> <transition to="end1" /> </custom> 66
  61. 61. DEMO •DIY: custom activities 67
  62. 62. Decision Automatic choice of process flow – Process data – Business rule Actual decision – Expression – Custom DecisionHandler 68
  63. 63. 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) { ... } } 69
  64. 64. 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> 70
  65. 65. Decision - expression Expression language – Juel (2.2: +methods) – Groovy – ... Process variable <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> 71
  66. 66. DEMO • Decisions 72
  67. 67. 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 73
  68. 68. 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 74
  69. 69. DEMO • Switching to the real stuff 75
  70. 70. Part 4: Advanced C oncepts
  71. 71. Agenda • jBPM Architecture • Process Deployment • Execution and persistence • Transactional control flow • More core features
  72. 72. g raph execution + pers is tence = trans actional control flow
  73. 73. jBPM Architecture: POJO Core • POJO Classes representing – Process definitions – Runtime executions – History, tasks, identities,... • Behaviour in the domain model • Domain model persistable with hibernate
  74. 74. ClientProcessDefinition processDefinition = ProcessDefinitionBuilder.startProcess() inc ub .startActivity("creditRate?", new ati on 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();
  75. 75. jBPM Architecture: Services • Infrastructure around domain model – Embeddability – Persistence / transactions • Services • Interceptors • Environment • Commands
  76. 76. Services • Main API • Services expose methods • Each method 1 command • Commands passed down interceptor stack – Aka chain of command – Configurable interceptor stack
  77. 77. Services public class ExecutionServiceImpl { ... public ProcessInstance startProcessInstanceById(String procDefId) { return commandService.execute( new StartProcessInstanceCmd(procDefId,null,null) ); } ...
  78. 78. Configurable Interceptor Stacks • Standalone • JTA • Spring inc • Remote ub ati on • Async
  79. 79. 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
  80. 80. Commands • Invoke methods on POJO's • Persistence operations – Load – Save
  81. 81. Persistence submit web sale sales review fork send bill ship items wait for payment all shipped ? no yes join end
  82. 82. Persistence submit web sale Transaction sales review fork Execution send bill ship items wait for payment no 1. Load all shipped ? yes join end
  83. 83. Persistence submit web sale Transaction sales review 2. Update fork Execution send bill ship items wait for payment all shipped ? no yes join end
  84. 84. Persistence submit web sale Transaction sales review fork Execution send bill ship items wait for payment no 3. Save changes all shipped ? yes join end
  85. 85. How Does jBPM Do It? • Deployment • Automatic activities • Wait states • Process concurrency • Async Continuations • Timers
  86. 86. A Business Archive • Plain jar formatted file • .bar extension • Contents – Process files – Process image – Classes – Forms – Rules –…
  87. 87. Deployment
  88. 88. Deployment With API RepositoryService repositoryService = processEngine.getRepositoryService(); String deploymentId = repositoryService.createDeployment() .addResourcesFromZipInputStream( “order.bar”) .deploy();
  89. 89. 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" />
  90. 90. Deployment Pr • Deployment oc ve ess rsi – HashMap on clas ing s ! – Representing zip file – Named resources • Key – Entry name – String DEPLOYMENT “1” order.jpdl.xml 11111011… • Value order.jpg 01011100… – Blob com/pinokkio/Order.class 00100100… order.rules.drl 01110100… – byte[]
  91. 91. Deployers RepositoryCache • Scan deployments DEPLOYMENT 1 • Publish objects Order RuleBase • RepositoryCache Deployment ClassLoader DEPLOYMENT “1” order.jpdl.xml 11111011… Deployer order.jpg 01011100… JpdlDeployer com/pinokkio/Order.class 00100100… OrderStartForm.ftl 01110100…
  92. 92. Process Instance • All state related to 1 execution of a process definition • Potentially multiple pointers keeping track of concurrent paths of execution • Variables • Timers
  93. 93. Execution • 1 path of execution – 1 set of variables – 1 set of timers
  94. 94. Structure • 1 process instance is a tree of executions – Concurrency – Variable scoping – Competing events in 1 scope
  95. 95. Full Automatic Example
  96. 96. <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>
  97. 97. Starting ProcessInstance Tomcat Some Web Framework public void userClickedButtonEjbSessionCmt() { ... ProcessInstance processInstance = executionService .startProcessInstanceByKey("example") ... }
  98. 98. Inside startProcessInstanceByKey • New execution • Executes “print dots” • Execution ends (deleted) • History remains – Net result – Part of user TX
  99. 99. Demo: Automatic Activity
  100. 100. Observation • Automatic activities run in thread of the web app • Exceptions in process roll back webapp transaction • Error message to the user
  101. 101. 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
  102. 102. Persisting State • Current state – Position in process graph – Variables – Timers • Waiting means – Persisting state – Committing transaction
  103. 103. A Basic Wait State
  104. 104. <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>
  105. 105. 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,...
  106. 106. Wait State Persistence 1. executionService .s tartProces s Ins tanceB yK ey(...) 1. Creates new execution 2. Starts executing from start activity 3. Execution arrives in s tate 4. Execution state will be saved 5. Transaction will be committed 6. jBPM service method will return
  107. 107. Wait State Persistence 2. Time goes by – Execution state remains in the DB
  108. 108. Wait State Persistence 3. executionService .s ig nalExecutionB yId(...) 1. Loads the execution 2. Takes an outgoing transition 3. Continues execution till next wait state 4. Stores execution updates 5. Commit transaction 6. signalExecutionById returns
  109. 109. A Basic Wait State transaction // e.g. in the button click code ProcessInstance processInstance = executionService .startProcessInstanceByKey("WaitState"); assertFalse(processInstance.isEnded()); String pid = processInstance.getId(); transaction // much later. e.g in another request or MDB executionService.signalExecutionById(pid);
  110. 110. 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
  111. 111. Demo: Wait S tate Activity
  112. 112. Process Execution Timeline
  113. 113. Transactional Control Flow Auto State Auto Auto Auto State Auto 1. executionService.startProcessInstanceByKey(…) Java Object: execution SQL: INSERT INTO JBPM4_EXECUTION …
  114. 114. Transactional Control Flow Auto State Auto Auto Auto State Auto 2. executionService.signalExecutionById(…) Java Object: execution SQL: UPDATE JBPM4_EXECUTION …
  115. 115. Transactional Control Flow Auto State Auto Auto Auto State Auto 3. executionService.signalExecutionById(…) Java Object: execution SQL: DELETE JBPM4_EXECUTION …
  116. 116. Concurrency • Parallel execution of activities • E.g. Order – Shipping – Billing • E.g. Loan – Sending loan money – Archiving contracts
  117. 117. Execution Concurrency
  118. 118. EventListeners • Attach POJO java code to process execution event • Hidden from the graph – For technical aspects
  119. 119. <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>
  120. 120. public class DoHidden implements EventListener { public void notify(EventListenerExecution execution) { ... } }
  121. 121. Asynchronous Continuations • Automatic activities in sequence • One takes a long time – E.g. pdf generation • Don’t block the client thread Job • async=“true” Executor pdf-g Transaction 1 Transaction 2
  122. 122. Timers • Actions – Take Transition – Event listeners • Also handled by JobExecutor • Business Calendar – 15 minutes – 4 bus ines s hours
  123. 123. Variables • HashMap associated to execution • Configurable type system • Scoping
  124. 124. Other Important Features • SEAM integration • Spring integration • Instance migration • Automatic upgrades
  125. 125. Summary • Fits ins ide your architecture • S upports multiple proces s lang uag es • Facilitates collaboration • jB PM has real value for real developers – Model process – Play with transactions – Write POJO code
  126. 126. Getting started  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
  127. 127. Q&A makes your work flow http://jbpm.org http://proces s developments .blog s pot.com http://jorambarrez.be/blog

×