5 Replies Latest reply on Jun 8, 2013 2:38 AM by ashpcs

    Simple state machine with transitions

    alfiekirkpatrick

      We have an existing (bespoke) workflow engine in our product and we are looking at options to bring it up-to-date using jBPM or similar.

       

      Each asset type in our system has a state machine that defines the lifecycle of the asset. For each state there are a number of transitions to other states (or back to the same state). These can be triggered by users of the system or through an API.

       

      It's important that the people doing the configuration for a project can easily define the state machine for a particular asset type. This is currently done through a non-graphical web form as a complex kind of table (not pretty but it works).

       

      Additionally, we can define which user roles can execute each transition and therefore control who can shift assets from one state to another. Since 'save' and 'view' are actually transitions internally, this provides a good level of access control.

       

      There's more functionality such as custom actions on transitions and transition parameters but you get the basic idea.

       

      I'm new to jBPM (I did some work on jBPM 4 but for a different scenario). It seems this scenario would typically be handled by a combination of user task (or manual task) and a gateway. The steps might be:

       

      - Define a task connected to a gateway

       

      - Before completing the task, set process variable to the path to follow, eg. transition="save"

       

      - Place a constraint on each outgoing flow on the gateway, eg. return "save".equals(transition)

       

      It seems the mapping of task output to variable could be handled in the BPMN also, though I've not looked at that in detail.

       

      The main issue I see is that this is tricky and error prone to set up for a complex scenario, so I am trying to think of ways to simplify it for projects.

       

      One idea would be to define a simpler XML format expressing the states/transitions involved and then transform it to BPMN for jBPM before loading.

       

      Another idea would be to add a new SemanticModule to the PackageBuilderConfiguration, to allow different elements in the process that give the "higher level" definition we're after.

       

      A third idea would be to give up on BPMN and use the underlying state machine in jBPM/Drools, ie. handle things at a lower level. It seems that the SemanticModule for BPMN ends up transforming to some lower level XML, and maybe this is where we should be looking.

       

      Sorry for the long post, but any general thoughts on which way to proceed, or areas to investigate much appreciated!

       

      Alfie.

        • 1. Re: Simple state machine with transitions
          alfiekirkpatrick

          Sorry I should add that one advantage of using BPMN is that for each transition a project may want to invoke a process, synchronously or async, and so having the power of BPMN for this dovetailed with the core state handling would be a bonus.

          • 2. Re: Simple state machine with transitions
            jsvitak

            Hello Alfie,

            I've read through your post and I think that jBPM is suitable for your scenarios.

            Several notes:

            - manual tasks in BPMN2 are more for documenting purposes of activity which is not executed in the engine, than real usage

            - you can use user tasks for user interaction

            - you can use own defined service tasks for any synchronous or asynchronous interactions with systems

            - as you say arbitrary flows and logic can be defined using gateways

            - BPMN2 and jBPM is able to map process variables to task inputs and task outputs to process variables

             

            You can decrease predisposition to errors for complex processes in multiple ways. For example you can use subprocesses to achieve better abstraction.

            Also you can always write unit tests for your processes to automatically check their expected behavior.

             

            My 2 cents.

            • 3. Re: Simple state machine with transitions
              ashpcs

              Hi Alfie,

               

              It would have been nice if you had provided sample lifecycle example.

               

              If you believe you have number of steps to be executed  such as human task or machine task (external services) you should be able to use BPMN engine to model it.

              It is up to you to provide Designer or create the BPMN programatically.

              JBPM provides you the programatica way of adding task, conditions and other BPMN constructs which will gerenate BPMN. This can be used with your current UI  as well where you already know the steps and conditions.

               


              • 4. Re: Simple state machine with transitions
                alfiekirkpatrick

                Thanks both for your replies. I got a bit further today and have uploaded a very basic working example to github here: https://github.com/jugglingcats/tjbpm.

                https://raw.github.com/jugglingcats/tjbpm/master/diagram.png

                This works fine, but it's a really simple workflow and already quite cumbersome. Applying unit tests isn't really an option, because projects can configure workflows on the fly.

                 

                Ashish, is there documentation anywhere on programatically creating tasks, etc? Maybe this is ultimately the way to go, but it seems to me that a lot of work has gone into the SemanticModule implementations such as ProcessSemanticModule and BPMNSemanticModule and that these are (or should be) extensible with higher level semantics - but there is a fair amount of complexity in these implementations so hard to see where to start. What I'm after is a way to roll together the saved and saveTransitions (and outgoing sequence flow constraints) into a single construct, eg:

                 

                <myns:state id="x" name="saved">

                  <myns:transition name="reject" to="review"/>

                  <myns:transition name="approve" to="published"/>

                </myns:state>

                 

                The idea of using (or even extending) existing visual editors with this type of extension is probably unrealistic...

                 

                Am suffering from wanting to make common scenarios in our environment really simple but still allow the power of BPMN when needed.

                 

                Regards, Alfie.

                • 5. Re: Simple state machine with transitions
                  ashpcs

                  Hi Alfie,

                   

                   

                  Please refer http://docs.jboss.org/jbpm/v5.4/userguide/ch.core-basics.html#d0e1307

                  section 6.1.3. Defining Processes Using the Process API.

                  This will become complex based on the requirement but is very useful if you have your own UI for creating process and can not use JBPM designer.

                   

                   

                   

                   

                  Thanks,

                  Ashish