6 Replies Latest reply on Dec 2, 2005 6:07 PM by Rainer Alfoeldi

    getting jBPM to save state at all times

    Sean Newbie

      I would like jBPM to save its state in the database as anything changes (new node entered/left/etc). I've tried turning on autocommit both in hibernate and in the code by getting the connection and turning autocommit on, but it doesn't seem to work.

      The persistence doc does explain how to resolve this:
      http://docs.jboss.com/jbpm/v3/userguide/persistence.html

      The only way I've been able to save data to the database is by starting a transaction and eventually committing it. I don't think I should have to manage this. If there is parallel processing going on, this would get nightmarish.

      I noticed this problem when I started running a query to check the status of the process as it was running to find that NOTHING was in the database because the commit was after the initial signal.

      code snippet:

      // start transaction
      jbpmSession.beginTransaction();

      // run entire process
      // > if this runs for an hour, I can't see what is going on
      rootToken.signal();

      // commit entire process (yuck!)
      jbpmSession.commitTransaction();

      meanwhile, the entire process (n signals) has run within the initial signal and I can't monitor it from the database because nothing will go into it until the commit. If the VM would go down in the middle of the transaction, things could get even worse because I don't know what was done and what wasn't.

      Even if I wanted to manage this within each node, I don't think I can get a handle to the transaction (and I wouldn't want to because two asynch threads could do bad things to the transaction out of order: thread 1 commits, thread 2 tries to commit before thread 1 can begin a new transaction)

      Status query for reference:
      select
      def.id_ as def_id,
      def.name_ as def_name,
      def.version_ as def_version,
      instance.id_ as instance_id,
      instance.start_ as instance_start,
      instance.end_ as instance_end,
      token.id_ as token_id,
      token.nodeenter_ as token_enter,
      node.id_ as node_id,
      node.name_ as node_name,
      node.class_ as name_class,
      var.name_ as var_name,
      var.stringvalue_ as var_value
      from
      jbpm_processinstance instance,
      jbpm_processdefinition def,
      jbpm_token token
      left outer join jbpm_variableinstance var
      on token.id_ = var.token_,
      jbpm_node node
      where
      instance.end_ is null
      and instance.processdefinition_ = def.id_
      and instance.roottoken_ = token.id_
      and token.node_ = node.id_

        • 1. Re: getting jBPM to save state at all times
          Rainer Alfoeldi Novice

          Well, the 'proper' way to do things would be to only use transacted resources in your nodes. If the resources don't support transactions (e.g. smtp) you would have to 'wrap' them in ones that do, e.g. send a JMS Message that would only get sent if the whole transaction gets commited.

          That way if your JVM crashes you're back to where you started, no harm done.

          Setting everything to auto-commit won't help you. Just image your JVM crashes the ms after you have executed something but have not yet saved the new state. You still don't have 100% data integrity, you're only "a litte bit" better off, which effectively means its just as bad as before.

          If I remember correctly hibernate will turn off any auto-commit setting, for good reason.

          If you want to implement 'checkpoints' and break the transaction up into smaller bits, put in wait states. That stops the workflow and gives jBPM a chance to save state. If you want a continuous workflow with 'checkpoints' build a asynch mech with JMS that signals() the Token you just sent to sleep. (or wait for the asynch feature in jBPM).

          If you realy want to fine tune your transactions call Token.signal() from behind a SLSB with bean managed transactions, get a UserTransaction, save that as a transient variable or ThreadLocal and go... its all yours then.

          The concurrency issue isn't all that hard to solve. Either lock on the ProcessInstance or if that is to global for you (as it is for me) wait until I've found and posted the answer to my question http://www.jboss.com/index.html?module=bb&op=viewtopic&t=73332. Sometime during the coming week. (The jBPM Team didn't even read the post :-( )

          This probably isn't what you wanted to here, but there are no easy ways with data consistency and concurrency.

          Have a nice wekend.

          Rainer

          P.S.: All this only applies in a managed environment.

          • 2. Re: getting jBPM to save state at all times
            Sean Newbie

            Thanks for your quick reply. I will think about it over the weekend.

            I am running jBPM inside jetty (jPBM called by quartz, other processes via URL) to keep it lightweight. I have a base class for all my nodes, so I will figure out how to weave it together.

            Thanks,

            Sean

            • 3. Re: getting jBPM to save state at all times
              Koen Aers Master

              Rainer,

              We do sometimes miss posts here. After all, this is the free support area ;-)
              Anyway, I read it now and posted a respone...

              Cheers,
              Koen

              • 4. Re: getting jBPM to save state at all times
                Rainer Alfoeldi Novice

                PEACE!

                I did't "up" the post. I just used my reply in this thread to get a little attention for the other thread. :-)

                I have no way of express it repsect I have for the patience you guys have with us and our questions. I'm serious.

                (Well... sometimes Ronald does have a little edge... in a humourous way.)

                Rainer

                • 5. Re: getting jBPM to save state at all times
                  Koen Aers Master

                   

                  sometimes Ronald does have a little edge

                  Yeah but you have to understand. He likes blonde girls with D cups, wearing orange bathing suits and living in California... And he only got a bunch of geeks talking about a state machine ;-)

                  Cheers,
                  Koen

                  • 6. Re: getting jBPM to save state at all times
                    Rainer Alfoeldi Novice

                    LOL

                    we all have our dreams.... :-)))))))))))))