| JBPM best practices |
|
|
|
| Written by F.Marchioni | |||||||||||||||||||||||||||||
| Tuesday, 11 November 2008 15:42 | |||||||||||||||||||||||||||||
|
There's no perfect rule to model your workflow, it depends on the needs of your process, on the actors involved, and so on. Anyway I wanted to share with you some rules of thumb on which developers usually agree. Give me your feedback if you agree or you want to propose alternatives.
1) Keep your JBPM executionContext tidyIn the very first JBPM projects I have seen, I realized dwevelopers sometimes use the executionContext to feed lots of variables to the process. Adding variables to the execution Context is fundamental in order to control execution flow, anyway don't be tempted to put everything inside it !
@Stateful
@Name("TicketingSystem")
public class TicketBean implements TicketBeanItf {
@PersistenceContext(type=PersistenceContextType.EXTENDED)
EntityManager em;
@In(create = true)
@Out
private Ticket ticket;
// We make this available to the business process
@Out(scope=ScopeType.BUSINESS_PROCESS, required=false)
long ticketId;
@CreateProcess(definition="TroubleTicketing")
public void createTicket() {
em.persist(ticket);
// Keep a reference to the ticketId in your biz process
ticketId = ticket.getTicketId();
}
}
Remember that adding domain variables in the execution Context besides being a bad design choice, it will badly ontribute to slow down your process.
2) Use Exception handler only to set variables or to notify errorsJBPM has a built-in exception handler which can be applied to single nodes or to the overall process <exception-handler exception-class="java.lang.Exception"> <action class="com.sample.handlers.BPMExceptionHandler"></action> </exception-handler>You may be tempted to use exception handling in JBPM to decide execution flow: don't try it ! The mechanism of jBPM is not completely similar to the java exception handling. In java, a caught exception can have an influence on the control flow. In the case of jBPM, control flow cannot be changed by the jBPM exception handling mechanism. The exception is either caught or uncaught. Uncaught exceptions are thrown to the client (e.g. the client that called the token.signal()) or the exception is caught by a jBPM exception-handler. For caught exceptions, the graph execution continues as if no exception has occurred.
3) Want JBPM failover ? Wrap JBPM calls in a clustered SLSB !jBPM is a state machine: process descriptions and runtime status are persisted to a database but in a cluster they are not automatically failed-over. If a cluster node fails while executing some external trigger (ui, timer, jms, whatever) execution will stop and have to be started again. Depending on the transaction context you're in this could be done automatically (redelivered jms, re-executed timer) or require ui interaction (error message for user if cluster node goes down requesting repeat). Therefore, while the process description is persistent, workflow failover must be performed manually. jBPM can be used to build a fully failsafe, clusterable hotfailover worklfow solution, but it doesn't come out of the box. So what's the easiest way to add these features to your workflow ? for most cases the best solution would be to encapsulate the jBPM API calls that you need in your application in a stateless session bean and cluster this last one.
4) Use superstates wherever possibleA Superstate is a group of nodes: its' a convenient way to group nodes into related sets, denoting for instance phases in a process. For example, one application could be to group all the nodes of a process in phases. Actions can be associated with superstate events. A consequence is that a token can be in multiple nested nodes at a given time. This can be convenient to check wether a process execution is e.g. in the start-up phase. So it's a good design choice to split your process into superstates when every state represents a phase of the process, but there's one more reason why I advocate the use of superstates: JBPM is a state machine and as such doesn't deliver a built-in graphical environment. There's actually an Eclipse plugin which let you write graphically your process but it's not the best BPM front-end on the market: icons are too large, too ugly and you can't define custom icons for different type of nodes (at least as it comes out of the Box). If you have ever drawn a 100 nodes process with JBPM you probably did what I did: I designed by myself a new front-end layer from JBPM, because the picture of the process was huge and completely a mess. 5) Extend JBPM Api rather then messing with complex process modellingSometimes developers (me too!) don't look for the simpler solution: maybe modelling your process with jbpm built-in nodes leads to an unnecessarily complex process. Take the org.jbpm.taskmgmt.def.Task.java and add the following fields/methods: private String taskLocation; Now update the hibernate config file for Task.java which is Task.hbm.xml <property name="taskLocation" column="TASKLOCATION_" ></property> Finally modify JpdlXmlReader.java so that this new property is injected into the Task class when
String taskLocation = taskElement.attributeValue("taskLocation"); Another example of customization can be applied to your queries: supposing you want to filter your Tasks using lots of criteria : think about a TaskList rendered with JSF and a Task Filter window where you can filter Task on priority, date, Actor, Task name and so on. One way to do it, without making things too complex is adding filters to the TaskInstance: simply open TaskInstance hibernate file and add some hibernate filters there: <filter name="filterPriority" condition=":paramPriority = PRIORITY_"/> then when you're populating your Datatable, enable the filters selected: String sql = "from org.jbpm.taskmgmt.exe.TaskInstance"; Query queryParent = session.createQuery(sql); Iterator iter = list.iterator();
6) Hire a Drool developer if you have complex rulesA workflow engine (or Graph Oriented Programming in general) is about specifying a graph that represents an execution. The nodes can represent wait states. How complex are my Java Action Handlers ? if you just need to read some data from a database, but not much more, it is probably best not to use a rule engine. However, where there is even a moderate amount of processing implemented in Java, it is worthwhile to consider the use of Drools when implementing your JBPM Handlers. This is because most applications develop complexity over time, and Drools will let you cope easily with this, especially if the lifetime of your application is medium or long. Furthermore Drools helps you cope with future changes by specifying the business rule in one or more easy-to-configure XML files. One more score for drools is that Drools "guides" developers to write code correctly do "the right thing." and at the same time rules are much easier to read then code so also your staff will be more comfortable with it. 7) To BPEL or not to BPELBPEL is an XML language which describes long running web service interactions. It is used mainly to orchestrate message exchanges centrally and as such is a key ingredient in SOA.
JPDL reflects organizational procedures with simple meaning
BPEL is document oriented and as such is mainly used in company boundaries
BPEL delegates interaction with people to partner services
JBoss.org Search
Custom Search
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||||||||||||||||||||||||||
| Last Updated ( Wednesday, 12 November 2008 09:06 ) | |||||||||||||||||||||||||||||




