jBPM 4 in Action
           by
Tom Baeyens & Joram Barrez
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
Agenda
 Part 1
 Part 2   Very interesting

 Part 3

 Part 4   REALLY interesting !




                                 3
jBPM is great for BPM
        *and*
   for developers




                        4
makes   your work flow
Business process
 An (organized) way
   of 'doing things'
 ... with a certain goal




                           8
History lesson
 1723-1790, Adam Smith: The pin factory
     – Labor division

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




                                          9
History lesson
 William E. Deming (1900-1993)

   'Hero' of Japanese industry
   Manufacturing processes ++
     – Quality Circle
     – SPC
     – Six-Sigma
     – ...




                                 10
Processes are everywhere




                           11
Processes are everywhere
Conclusion
 Any company
               They all have
 Any product
               business processes
 Any service




                                14
Conclusion
 Any company
                    They all have
 Any product
                    business processes
 Any service

 Which means
    – 'Doing business'
      == executing some business process


                                           15
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
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
BPM Systems
 ~BPM engine or workflow engine
 Executes the business processes
    – Diagram
    –
    –
    –
    –
    – <tech-details />

                                   20
Introducing jBPM
 Transactional state-machine
 Generic graph execution engine




                                  21
Introducing jBPM
 Transactional state-machine
 Generic graph execution engine

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




                                  22
Main business advantages
 Diagram: no disconnection between
     – What business expects
     – What IT delivers
 Agile
 Visibility
     – Monitoring, CEP, KPI




                                     23
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
jBPM history

             4 Jan 2003 :
              5, 4, 3, 2, 1
    ... rrrrrrooooaaaaarrrrr ...
      and we have a lift off !

jBpm is present in sourceforge.net




                                     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



     18 Oct 2004 :
released JBoss jBPM 2.0




                          27
jBPM history




               28
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
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
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
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
jBPM history

     July 2009:

  jBPM4 is out!




                  33
jBPM history




                November 2009


               jBPM 4.2 released




                                   34
Today
Today
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
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
jBPM3   jBPM4
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
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
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
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
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
Part 2: jB PM C oncepts
A Process
An Execution




               Execution
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
History
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
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
jPDL         Av
                                  ail
                                     ab
                                       le
                                          no
                                            w!

•   BPM focussed
•   Graph based
•   Readable, editable XML
•   Direct Java integration
•   Extended task management
•   Community
B PMN 2.0        Co
                                   mi
                                     ng
                                        So
                                           on
                                             !
•   BPM focussed
•   Graph based
•   Upcoming standard
•   Focus on modeling notation
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
jBPM Overview
               JDBC


Repository        jBPM.jar                Your
Executions
                  RepositoryService     Application
 History
                  ExecutionService
  Tasks
 Identity             HistoryService

                       TaskService

                      IdentityService




                                 JVM
jBPM API          jbpm.cfg.xml

Configuration cfg = new Configuration();

ProcessEngine processEngine =
  cfg.buildProcessEngine();

processEngine.getRepositoryService();
processEngine.getExecutionService();
processEngine.getHistoryService();
processEngine.getTaskService();
processEngine.getIdentityService();
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 Examples
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
Demo process
 Ordering conference goodies




                               62
First steps
  Set up dev environment
  Using jBPM in embedded mode
  Work in iterations
      – Create basic process
        (start–task-end)
      – TDD our process




                                63
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
DEMO
•First steps


               65
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
DEMO
•DIY: custom activities


                          67
Decision
 Automatic choice of process flow
     – Process data
     – Business rule
 Actual decision
     – Expression
     – Custom DecisionHandler




                                    68
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
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
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
DEMO
• Decisions


              72
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
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
DEMO
• Switching to the real stuff


                                75
Part 4: Advanced C oncepts
Agenda
•   jBPM Architecture
•   Process Deployment
•   Execution and persistence
•   Transactional control flow
•   More core features
g raph execution
              +
        pers is tence
              =
trans actional 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()        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();
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
Services
public class ExecutionServiceImpl {

...
public ProcessInstance
    startProcessInstanceById(String procDefId) {

   return commandService.execute(
    new StartProcessInstanceCmd(procDefId,null,null)
   );
}
...
Configurable Interceptor Stacks
•   Standalone
•   JTA
•   Spring
                 inc
•   Remote           ub
                       ati
                          on

•   Async
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
                submit web sale


                    sales review


                        fork

        send bill                  ship items


        wait for
        payment                all shipped ?    no

                                    yes
                        join

                        end
Persistence
                                       submit web sale
    Transaction
                                           sales review


                                               fork
           Execution
                               send bill                  ship items


                               wait for
                               payment                                 no
1. Load                                               all shipped ?

                                                           yes
                                               join

                                               end
Persistence
                                         submit web sale
Transaction
                                             sales review

                     2. Update                   fork
       Execution
                                 send bill                  ship items


                                 wait for
                                 payment                all shipped ?    no

                                                             yes
                                                 join

                                                 end
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
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 API
RepositoryService 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
                                                 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[]
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…
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
                         Tomcat
                                        Some
                                         Web
                                      Framework


public void userClickedButtonEjbSessionCmt() {
  ...
    ProcessInstance processInstance =
      executionService
        .startProcessInstanceByKey("example")
    ...
}
Inside startProcessInstanceByKey
•   New execution
•   Executes “print dots”
•   Execution ends (deleted)
•   History remains
     – Net result
     – Part of user TX
Demo: 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 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
Wait State Persistence
2.       Time goes by
     –     Execution state remains in the DB
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
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);
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 Activity
Process Execution Timeline
Transactional
                         Control Flow
     Auto       State    Auto    Auto      Auto    State   Auto




1. executionService.startProcessInstanceByKey(…)
 Java Object:
                    execution



 SQL: INSERT INTO JBPM4_EXECUTION …
Transactional
                         Control Flow
     Auto       State    Auto     Auto       Auto   State   Auto




2. executionService.signalExecutionById(…)
 Java Object:
                    execution



 SQL: UPDATE JBPM4_EXECUTION …
Transactional
                         Control Flow
     Auto       State    Auto     Auto       Auto   State   Auto




3. executionService.signalExecutionById(…)
 Java Object:
                    execution



 SQL: DELETE JBPM4_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
                                                     Job
• async=“true”                                     Executor




                                           pdf-g


                        Transaction 1   Transaction 2
Timers
• Actions
  – Take Transition
  – Event listeners
• Also handled by JobExecutor
• Business Calendar
  – 15 minutes
  – 4 bus ines s 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 proces s lang uag es
•   Facilitates collaboration
•   jB PM has real value for real developers
    – Model process
    – Play with transactions
    – Write POJO code
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
Q&A
     makes    your work flow
http://jbpm.org
http://proces s developments .blog s pot.com
http://jorambarrez.be/blog

Devoxx 2009 University session Jbpm4 In Action

  • 1.
    jBPM 4 inAction by Tom Baeyens & Joram Barrez
  • 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.
    Agenda Part 1 Part 2 Very interesting Part 3 Part 4 REALLY interesting ! 3
  • 4.
    jBPM is greatfor BPM *and* for developers 4
  • 5.
    makes your work flow
  • 8.
    Business process An(organized) way of 'doing things' ... with a certain goal 8
  • 9.
    History lesson 1723-1790,Adam Smith: The pin factory – Labor division 1863-1947, Henry Ford: mass production – Assembly lines – Specialization 9
  • 10.
    History lesson WilliamE. Deming (1900-1993) 'Hero' of Japanese industry Manufacturing processes ++ – Quality Circle – SPC – Six-Sigma – ... 10
  • 11.
  • 12.
  • 14.
    Conclusion Any company They all have Any product business processes Any service 14
  • 15.
    Conclusion Any company They all have Any product business processes Any service Which means – 'Doing business' == executing some business process 15
  • 18.
    The M inBPM 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
  • 19.
    The M inBPM 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
  • 20.
    BPM Systems ~BPMengine or workflow engine Executes the business processes – Diagram – – – – – <tech-details /> 20
  • 21.
    Introducing jBPM Transactionalstate-machine Generic graph execution engine 21
  • 22.
    Introducing jBPM Transactionalstate-machine Generic graph execution engine But most of all... – A kick-ass BPM engine 22
  • 23.
    Main business advantages Diagram: no disconnection between – What business expects – What IT delivers Agile Visibility – Monitoring, CEP, KPI 23
  • 24.
    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
  • 25.
    jBPM history 4 Jan 2003 : 5, 4, 3, 2, 1 ... rrrrrrooooaaaaarrrrr ... and we have a lift off ! jBpm is present in sourceforge.net 25
  • 26.
    jBPM history 4 Jan 2003 : 5, 4, 3, 2, 1 ... rrrrrrooooaaaaarrrrr ... and we have a lift off ! jBpm is present in sourceforge.net 26
  • 27.
    jBPM history 18 Oct 2004 : released JBoss jBPM 2.0 27
  • 28.
  • 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. 29
  • 30.
    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
  • 31.
    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
  • 32.
    jBPM history 'This timeI 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
  • 33.
    jBPM history July 2009: jBPM4 is out! 33
  • 34.
    jBPM history November 2009 jBPM 4.2 released 34
  • 35.
  • 36.
  • 37.
    JBPM v4: what'snew? 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
  • 38.
    JBPM v4: what'snew? 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
  • 39.
    jBPM3 jBPM4
  • 40.
    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
  • 41.
    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
  • 42.
    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
  • 43.
    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
  • 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? 44
  • 45.
    Part 2: jBPM C oncepts
  • 46.
  • 47.
    An Execution Execution
  • 48.
    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
  • 49.
  • 50.
    Processes As PartOf 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
  • 51.
    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
  • 53.
    jPDL Av ail ab le no w! • BPM focussed • Graph based • Readable, editable XML • Direct Java integration • Extended task management • Community
  • 54.
    B PMN 2.0 Co mi ng So on ! • BPM focussed • Graph based • Upcoming standard • Focus on modeling notation
  • 55.
    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
  • 56.
    jBPM Overview JDBC Repository jBPM.jar Your Executions RepositoryService Application History ExecutionService Tasks Identity HistoryService TaskService IdentityService JVM
  • 57.
    jBPM API jbpm.cfg.xml Configuration cfg = new Configuration(); ProcessEngine processEngine = cfg.buildProcessEngine(); processEngine.getRepositoryService(); processEngine.getExecutionService(); processEngine.getHistoryService(); processEngine.getTaskService(); processEngine.getIdentityService();
  • 58.
    jbpm.cfg.xml <jbpm-configuration> <importresource="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>
  • 59.
    Installer Ant Scripts •Install, start & stop – Hsqldb – JBoss – Tomcat • Create, upgrade & drop jBPM schema • Install jBPM into – JBoss (service archive) – Tomcat (libs+config)
  • 60.
    Part 3: DemoExamples
  • 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 61
  • 62.
    Demo process Orderingconference goodies 62
  • 63.
    First steps Set up dev environment Using jBPM in embedded mode Work in iterations – Create basic process (start–task-end) – TDD our process 63
  • 64.
    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
  • 65.
  • 66.
    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
  • 67.
  • 68.
    Decision Automatic choiceof process flow – Process data – Business rule Actual decision – Expression – Custom DecisionHandler 68
  • 69.
    Decision - handler <decisionname="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
  • 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> 70
  • 71.
    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
  • 72.
  • 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 73
  • 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 74
  • 75.
    DEMO • Switching tothe real stuff 75
  • 76.
  • 77.
    Agenda • jBPM Architecture • Process Deployment • Execution and persistence • Transactional control flow • More core features
  • 78.
    g raph execution + pers is tence = trans actional control flow
  • 79.
    jBPM Architecture: POJOCore • POJO Classes representing – Process definitions – Runtime executions – History, tasks, identities,... • Behaviour in the domain model • Domain model persistable with hibernate
  • 80.
    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();
  • 81.
    jBPM Architecture: Services •Infrastructure around domain model – Embeddability – Persistence / transactions • Services • Interceptors • Environment • Commands
  • 82.
    Services • Main API • Services expose methods • Each method 1 command • Commands passed down interceptor stack – Aka chain of command – Configurable interceptor stack
  • 83.
    Services public class ExecutionServiceImpl{ ... public ProcessInstance startProcessInstanceById(String procDefId) { return commandService.execute( new StartProcessInstanceCmd(procDefId,null,null) ); } ...
  • 84.
    Configurable Interceptor Stacks • Standalone • JTA • Spring inc • Remote ub ati on • Async
  • 85.
    Environment • Decouples POJOmodel from environment • Interceptorstack responsible for setting up the environment • Domain model looks up configurable stuff from the environment • E.g. hibernate session
  • 86.
    Commands • Invoke methodson POJO's • Persistence operations – Load – Save
  • 88.
    Persistence submit web sale sales review fork send bill ship items wait for payment all shipped ? no yes join end
  • 89.
    Persistence submit web sale Transaction sales review fork Execution send bill ship items wait for payment no 1. Load all shipped ? yes join end
  • 90.
    Persistence submit web sale Transaction sales review 2. Update fork Execution send bill ship items wait for payment all shipped ? no yes join end
  • 91.
    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
  • 92.
    How Does jBPMDo It? • Deployment • Automatic activities • Wait states • Process concurrency • Async Continuations • Timers
  • 93.
    A Business Archive •Plain jar formatted file • .bar extension • Contents – Process files – Process image – Classes – Forms – Rules –…
  • 94.
  • 95.
    Deployment With API RepositoryServicerepositoryService = processEngine.getRepositoryService(); String deploymentId = repositoryService.createDeployment() .addResourcesFromZipInputStream( “order.bar”) .deploy();
  • 96.
    Deployment With Ant <jardestfile="order.bar"> ... </jar> <taskdef name="jbpm-deploy" classname="org.jbpm.pvm.internal.ant.JbpmDeployTask" classpathref="jbpm.libs.and.cfg" /> <jbpm-deploy file="order.bar" />
  • 97.
    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[]
  • 98.
    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…
  • 99.
    Process Instance • Allstate related to 1 execution of a process definition • Potentially multiple pointers keeping track of concurrent paths of execution • Variables • Timers
  • 100.
    Execution • 1 pathof execution – 1 set of variables – 1 set of timers
  • 101.
    Structure • 1 processinstance is a tree of executions – Concurrency – Variable scoping – Competing events in 1 scope
  • 102.
  • 103.
    <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>
  • 104.
    Starting ProcessInstance Tomcat Some Web Framework public void userClickedButtonEjbSessionCmt() { ... ProcessInstance processInstance = executionService .startProcessInstanceByKey("example") ... }
  • 105.
    Inside startProcessInstanceByKey • New execution • Executes “print dots” • Execution ends (deleted) • History remains – Net result – Part of user TX
  • 106.
  • 107.
    Observation • Automatic activities run in thread of the web app • Exceptions in process roll back webapp transaction • Error message to the user
  • 108.
    Waiting • Thread nortransaction 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
  • 109.
    Persisting State • Currentstate – Position in process graph – Variables – Timers • Waiting means – Persisting state – Committing transaction
  • 110.
  • 111.
    <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>
  • 112.
    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,...
  • 113.
    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
  • 114.
    Wait State Persistence 2. Time goes by – Execution state remains in the DB
  • 115.
    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
  • 116.
    A Basic WaitState 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);
  • 117.
    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
  • 118.
    Demo: Wait State Activity
  • 119.
  • 120.
    Transactional Control Flow Auto State Auto Auto Auto State Auto 1. executionService.startProcessInstanceByKey(…) Java Object: execution SQL: INSERT INTO JBPM4_EXECUTION …
  • 121.
    Transactional Control Flow Auto State Auto Auto Auto State Auto 2. executionService.signalExecutionById(…) Java Object: execution SQL: UPDATE JBPM4_EXECUTION …
  • 122.
    Transactional Control Flow Auto State Auto Auto Auto State Auto 3. executionService.signalExecutionById(…) Java Object: execution SQL: DELETE JBPM4_EXECUTION …
  • 123.
    Concurrency • Parallel executionof activities • E.g. Order – Shipping – Billing • E.g. Loan – Sending loan money – Archiving contracts
  • 124.
  • 125.
    EventListeners • Attach POJOjava code to process execution event • Hidden from the graph – For technical aspects
  • 126.
    <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>
  • 127.
    public class DoHiddenimplements EventListener { public void notify(EventListenerExecution execution) { ... } }
  • 128.
    Asynchronous Continuations • Automaticactivities 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
  • 129.
    Timers • Actions – Take Transition – Event listeners • Also handled by JobExecutor • Business Calendar – 15 minutes – 4 bus ines s hours
  • 130.
    Variables • HashMap associatedto execution • Configurable type system • Scoping
  • 131.
    Other Important Features • SEAM integration • Spring integration • Instance migration • Automatic upgrades
  • 132.
    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
  • 133.
    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
  • 134.
    Q&A makes your work flow http://jbpm.org http://proces s developments .blog s pot.com http://jorambarrez.be/blog