3 Replies Latest reply on Dec 10, 2008 12:03 PM by adinn

    WS-BA Compensation Order?

    elwood_j_blues

      I was successfully able to implement a WS-BA transaction (on JBoss 5.0.0 GA with JBossTS 4.4.0 GA) with participant completion that will either complete successfully, or, in the case of failure (which I generate by randomly throwing an exception in the services), it compensates.

      However, the compensation order is the same order in which the participants entered the transaction. That's okay, as long the order does not matter.

      However, what if we'd violate constraints? Say you have a bank account with no credit limit, holding 500 Dollars, then we add 500, then we reduce it by 1000 -- ending up with 0. This is compensated, which will first reduce the amount by 500... wait -- we are reaching -500, violating our credit line constraint -- in spite of us *wanting* to add another 1000 later, after which we'd end up with the 500 we started off with.

      So, can I define the compensation order, and if not, any suggestion how I would proceed in such a case? Thanks!

        • 1. Re: WS-BA Compensation Order?
          adinn

          The WS-BA spec does not define an order for complete, close and/or compensation notifications to be dispatched from the coordinator. It allows the implementation to do it how it likes, including parallel dispatch of a given notification to multiple participants. I believe we have a JIRA slated to implement the latter at some stage.

          Even if we provided some order guarantee for participant notifications in the JBoss implementation it would be unwise for your web services to depend on it. This would limit its ability to interoperate wiht other coordinator implementations.

          The specific case in question is interesting. Both your participants are trying to modify the same resource. Arguably, you should have one participant handling all web service requests in the same activity rather than one per request. If you choose to register a participant for each request then in order to make your web services safe you need at the very least to be locking and updated a shared record of the changes made to the resource by each participant. Your compensation actions could then refer to this shared resource. How you do that (including how you make it persistent between complete and close/compensate) will require some thinking through which I will leave as an exercise for the reader.

          • 2. Re: WS-BA Compensation Order?
            elwood_j_blues

            Thanks for confirming what I was already thinking: That I must not rely on a compensation order. I am, in fact, not manipulating the same resource from different services, but multiple calls to the same service, each one of which registers itself with the BA with participant completion. After all, after each distinct manipulation, the service says "my work here is done". It's only the client who decides if or if not to call the web service again after that.

            Maybe I need to use coordinator completion here: As it does not lie in the discretion of the service if it gets to modify the resource only once, or maybe 10 times, and they are incremental changes, this may be the only way for me to be able to compensate the whole batch in the right order.

            • 3. Re: WS-BA Compensation Order?
              adinn

               


              Maybe I need to use coordinator completion here: As it does not lie in the discretion of the service if it gets to modify the resource only once, or maybe 10 times, and they are incremental changes, this may be the only way for me to be able to compensate the whole batch in the right order.


              Yup, that's what I was hinting at. In fact if you do this your web service will keep a running total and write the whole set of credits/debits once at complete then either close or compensate them all at once depending upon the outcome.