When you want some atomic tasks to be executed one after another following a specific workflow, and when you want those processed tasks to be cancelled if, at some point in the workflow, an unexpected error occurs, then this set of classes may help you.
Note : this project is very much inspired by jPos monetic framework's transaction manager concepts. It intends not to be an alternative nor a concurrent to the jPos transaction manager which works just fine. Rather, it provides some set of classes that are candidate to dependency injection through an IOC container (like for instance Spring).
Adding txnmgr to a Maven project
Add the following dependency section to your pom.xml : ``` com.github.dgrandemange txnmgr 1.0.0 ```Recipee
First, think about your workflow and what should be done from a business point of view. Doing so, you should be able to identify the different tasks you need. We will call theses tasks participants. A participant has to be an implementation of thefr.dgrandemange.txnmgr.service.IParticipant
interface.
In your workflow, there may be different ways for the job to be done, depending on the execution context. So, at some points in the workflow, some paths will be selected and some others won't.
So how is the selection done ?
Well, when a participant is processed (see method fr.dgrandemange.txnmgr.service.IParticipant.execute(IContextMgr contextMgr)
), it can returns a space delimited list of group names. A group is an ordered list of participants.
When a group is selected, its participants are executed one after another, following the order of their declaration in the group.
All groups must be registered in a fr.dgrandemange.txnmgr.model.ParticipantsGroupRegistry
and uniquely identified by a name.
The transaction is handled by a transaction manager. A basic implementation is provided with the fr.dgrandemange.txnmgr.service.support.TransactionMgrImpl
class.
See a sample usage in this unit test.
Related projects
The [txnmgr-springframework-ext](https://github.com/dgrandemange/txnmgr-springframework-ext) project provides a nice way to configure (definition and external dependencies injection) participants (and groups of) through a Spring XML application context configuration.The jPos Workflow Eclipse plugin project which provides a way to view a transaction workflow XML configuration as a directed graph under the Eclipse IDE.