Tuesday, December 9, 2014

Understanding Activiti BPM engine - DB ID Generator

How Activiti generates database ID for managed entities?

Activiti BPM engine maintains database having 24 tables. Most of the tables has ID as primary key to identify a particular row in a given table. Activiti BPM engine with the help of Database ID generator implementation, generates next id to be used for any row to be persisted on any given table. The new ID which is generated using database ID generator makes use of db property "next.dbid" as the seed data to start with. Activiti process engine also maintains another parameter called block size (default value of 2500). Block size is the difference between any two subsequently generated database identifiers.

Probably one who wants to understand this property in action should look out for table act_ge_property under activiti database/schema. I am using MySQL to understand Activiti process engine's database model. I have shown a snapshot of database below.


FIG 1: Database property showing seed data for next database ID.


When activiti BPM process engine wants to persist an entity say User entity, it generates the database identifier (ID) for the new user entity using database ID generator using the combination of property value (next.dbid) and block size (typically by default, it is 2500).

The generation functionality happens in an entirely new transaction propogation. The database transaction propogation is set to "REQUIRES_NEW". Database ID generator is quite important piece of Activiti database management in terms of using one generator for most of the primary key requirements.

Database ID generator is the default strategy to generate ID for most of the entities managed by Activiti process engine. As long as Activiti user does mention ID for a given entity say Group, Activiti process engine makes sure that it makes use of user provided value as primary key for given entity instance say Group instance.

The database ID generator strategy can be customized by providing our own implementation for interface, org.activiti.engine.impl.cfg.IdGenerator. The current default implementation extends this java interface, org.activiti.engine.impl.db.DbIdGenerator. The implementation is under the package org.activiti.engine.impl.*. As mentioned by core team of Activiti process engine, the classes inside impl package are not stable in a sense that they might change at any time in future.

The implementation for getNextId() is a synchronized method. It always returns String value as ID for any requesting entity.






Saturday, December 6, 2014

Activiti BPM workflow engine execution pattern


This would be my part of contribution towards spreading awareness on how Activiti BPM engine might work internally. Any corrections on this particular blog is much appreciated. With that, i will proceed.

As most of the Activiti BPM developers who access the engine API programmatic-ally should be knowing that it exposes services as APIs to interact with it. I have taken this below image from Activiti website.



    Courtesy of Activiti BPM Website


What is a ProcessEngine?

As most of you know that, Activiti Engine is called as "Process Engine" as shown in the above diagram. It takes a configuration file such as 'activiti.cfg.xml' and configures itself by default and presents an instance of fully configured BPM engine called "Process Engine".

As part of customization to plugin our own identity service into ProcessEngine, I have been studying the internal workings of it. I became bit curious to understand how it perform group creation, user creation etc,.

How Command Pattern is related to ProcessEngine?


From the API names, it was evident that most of the actions such as Create User, Delete User, Create Group, Get Group Details are executed using Command Pattern. You can read more about Command Pattern in in-detail Martin Fowler's blog, http://martinfowler.com/bliki/DecoratedCommand.html. Please do read, it is quite informative...  :)

Moving on, chaining of command interceptors


Consider a scenario where as a API developer, I would like to use IdentityService for creation of new group say, "sales". To achieve the same, IdentityServiceImpl Java Class makes use of preconstructed Command Executor instance which holds a chain of command interceptors such as log interceptor, transaction interceptor, command context interceptor and finally points to command invoker which actually performs create group operation.

NOTE: The default chaining of command interceptors and command invoker happens during ProcessEngine bootstrap.

All these services exposed as APIs are injected with this command executor which carries a set of pre-configured command interceptors such as log interceptor, transaction interceptor, command context interceptor and last but not least, the actual command invoker which happens to be the last one in the interceptor chain.

Observe for blocks marked in purple color showing the command interceptor chaining.








I will keep posting the details which would be helpful to understand the internal workings of Activiti Engine.




Please note that, Activiti user guide is quite informative even though internal implementation classes carry little or no java documentation. Please follow Activiti user guide for understand engine better, http://activiti.org/userguide/index.html



Tuesday, October 21, 2014

Standalone activiti modeler/editor

  • I have made good progress with respect to extracting the activiti-modeler  editor component out of activiti framework codebase.
  • I am able to host it as part of my sample web application.
  • I have taken the latest activiti-modeler component which is 5.17.0-SNAPSHOT. I built it locally after forking out the code base from GitHub.
  • The activiti-modeler editor requires valid model id to open the editor in the form of request parameter(/service/editor?id=<model-id>). It is done in that way. As a result, even activiti-explorer loads a demo-model definition by default to provide base linking between activiti-explorer and activiti-modeler. Model ID is bit different from BPMN process definition. Seems like there is bit of difference in representation. This is one area of investigation.
  • Activiti-modeler has REST layer written using Spring MVC and Spring REST modules.
  • Activiti-modeler has certain parts which are extracted from acitiviti-explorer-web-2 maven module.
  • I have tweaked and created REST resource which will load the sample model definition and proceed with loading the activiti modeler editor. I have attached below snapshot when the sample web application was running locally,








Defining/modifying/deploying the business processes using eclipse activiti designer as well as activiti modeler

1.       Eclipse designer plugin
a.       You can create your process definition using this plugin.
b.      The eclipse designer plugin will allow you(BPMN developer) to add activiti diagram via eclipse wizard.

c.       Eclipse designer plugin allows to create deployment artifacts(.bar –business archive) which can be deployed using activiti-explorer.

d.      Eclipse designer plugin stores the process definitions file in the form of .bpmn extension file.


2.       Activiti Modeler component
  • It accepts the process definition artifacts for deployment  in any of these formats - .bar, .zip, .bpmn or .bpmn20.xml
  • Developer or Non-technical person can edit/modify the  uploaded process definition using activiti-modeler
  • Once it is modified, process definition can be deployed or exported in .bpmn20.xml format.
  • Developer can also define new processes using Activiti-modeler.