7 Replies Latest reply on Feb 28, 2007 9:41 AM by weston.price

    Usage of LastResource Inteface leads to warning

    ypsilon

      Hello.

      Since I am kind of new to JTA and I have to implement it a at a fairly vital part (payment) of our system I'd like to ask you if I should pay more attention to the following warning

      "Prepare called on a local tx. Use of local transactions on a jta transaction with more than one branch may result in inconsistent data in some cases of failure."

      In short: This error occurs whenever I enlist an XAResource which implements the LastResource interface in the transaction. So the first question is:

      ------> Is this normal?

      (I did not find a way to avoid the message with the LastResource interface implemented, but from what I learned so far that's the way to use the Interface.)

      Since I am interested in any opinion / suggestion I can get here is a more in-depth description:

      There is an external service provider which handles our payments. In order to communicate with that provider the idea was to implement an XAResource which does the communication and thereby ensures that the payment is done when the database transaction is done. The protocol the ServiceProvider uses is somewhat limited when it comes down to error recovery. Because of that it seems to be pretty hard to implement a real, stable XAResource adapter. 1)

      Since I cannot implement a complete XAResource I wanted to implement the LastResource interface. By that I can do all the communication after all prepare() calls are done (in our case only the DB prepare so far.) My guess is that through this the risk of an incosistent state after the end of the transaction is minimized.

      So here comes the second question:

      Any opinions about this solution?

      ;-)

      Thanks in advance
      PeeR

      PS: If one of the developers is reading this here is a suggestion. Put the XID and or class of the resource in this warning. You have no clue how to identify which resource it is that causes the trouble...

      -----------------------------
      1) The protocol used is fairly simple: first step is to authorize a transaction, second step is to commit the transaction. Both is done via Http. In theory a cancellation request can be done afterwards - but only within a very small timeframe so using that is not really an option.
      Apart from that in some scenarios the first step has to be done outside the transaction.

        • 1. Re: Usage of LastResource Inteface leads to warning
          weston.price

          You do not need to implement the LastResource. This is done for you by JBossJCA for ResourceAdapters that only support LocalTransaction (ie non XA). This is done to support enlistment LocalTransaction adapters within the scope of a global transaction (XA).

          To clarify, are you implementing a ResourceAdapter? It sounds like you are doing far too much in your code as JCA takes care of most of this for you.




          • 2. Re: Usage of LastResource Inteface leads to warning
            ypsilon

            Hi.

            first of all thanks for your reply!

            "weston.price@jboss.com" wrote:
            To clarify, are you implementing a ResourceAdapter? It sounds like you are doing far too much in your code as JCA takes care of most of this for you.


            Actually no: I do not implement a ResourceAdapter. I implement an XAResource. As far as I read that should do the job. Eventhough I have to admit that with the described service it is not possible to create a full featured XAResource. I also have to admit that I am fairly new to the JTA topic. I've done some reading an my idea was (just to clarify the terms that) in my scenario we have:

            TransactionManager - as provided by JBoss AS
            ResourceManager - the external service provider which will deal with the payments.
            My XAResource - The interface used to make the TransactionManager work with the ResourceManager (i.e. the Service Provider)

            From my limited knowledge of JCA I cannot really say if it's a smaller efford to write a JCA ResourceAdapter to do my job. (Actually writing the XAResource was fairly simple as it does not do much)

            Am I missing a point here?

            Thanks in advance!

            Greetings
            PeeR


            • 3. Re: Usage of LastResource Inteface leads to warning
              weston.price

              Since you are implementing the XAResource interface, there is no reason to implement the LastResource interface as well. Again, this interface is used by JBossJCA internally to manage resources that are not XA aware but still need to participate in a global transaction. It is simply a marker interface.

              Your implementation of XAResource should be sufficient for your needs.

              • 4. Re: Usage of LastResource Inteface leads to warning
                ypsilon

                ok. just out of curiosity: Is the warning message I get if I implement the Interface (which I will not do anymore) normal? It seems to me that there is no way to use the interface without getting this message.

                Thanks again for your reply.

                Greetings
                PeeR

                • 5. Re: Usage of LastResource Inteface leads to warning
                  weston.price

                  The message is indeed *normal* in the sense that it is simply warning about the use of a LocalResource in the context of a Global transaction. While JBoss does indeed support this via the Last Resource gambit, it is never really a good idea to use this if the underlying ResourceManager provides an XA aware implementation being that recovery can be comprimised as a result.

                  Note, an excellent resource on Java and Transaction Processing in general is the book 'Java Transaction Processing' by Mark Little et al.

                  http://www.amazon.com/Java-Transaction-Processing-Implementation-Professional/dp/013035290X/sr=8-1/qid=1172671825/ref=pd_bbs_sr_1/105-0987687-3710018?ie=UTF8&s=books


                  • 6. Re: Usage of LastResource Inteface leads to warning
                    ypsilon

                     

                    "weston.price@jboss.com" wrote:
                    The message is indeed *normal* in the sense that it is simply warning about the use of a LocalResource in the context of a Global transaction. While JBoss does indeed support this via the Last Resource gambit, it is never really a good idea to use this if the underlying ResourceManager provides an XA aware implementation being that recovery can be comprimised as a result.


                    ok. So it means somehting like: "Watch out! What you are doing is not optimal but we will do the job for you."

                    "weston.price@jboss.com" wrote:

                    Note, an excellent resource on Java and Transaction Processing in general is the book 'Java Transaction Processing' by Mark Little et al.

                    http://www.amazon.com/Java-Transaction-Processing-Implementation-Professional/dp/013035290X/sr=8-1/qid=1172671825/ref=pd_bbs_sr_1/105-0987687-3710018?ie=UTF8&s=books


                    ;-) I read your recommendation on that earlier this day in some other thread. The order is already placed, so hopefully I have something more to dig in tomorrow!

                    Have a nice day...

                    PeeR

                    • 7. Re: Usage of LastResource Inteface leads to warning
                      weston.price

                       


                      ok. So it means somehting like: "Watch out! What you are doing is not optimal but we will do the job for you."


                      Exactly. Later versions JBoss will give a much *stronger* warning :-)

                      Enjoy the book!