6 Replies Latest reply on Nov 29, 2008 7:39 PM by mazz

    how to customize the TM for my EJB3 app?

    mazz

      I want to customize the default timeout behavior of the JBoss Transaction Manager in my EJB3 app (not the timeout value - but the actual behavior that occurs when the tx times out).

      The default is to abort transactions but let the threads active in that transaction continue to run. See my JBossTM forum question I posted related to this to see where this is defined in the documentation:

      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=146170

      I want to change that behavior. The JBossTM docs tell me to add my own CheckedAction implementation to the transaction. In that previous post I linked above, Mark tells me that I have to do this:

      In order to change the CheckedAction that is used by a transaction you need to grab the underlying transaction instance (BasicAction).


      Can someone here tell me how I can do this from WITHIN my EJB3 app (hence why I am posting this in the EJB3 forum).

      In other words, if I have this EJB3 SLSB method:

      @TransactionTimeout(60)
      public void mySLSBMethod() {...


      How do I inject my own CheckedAction implementation to the transaction this method is running in?

        • 1. Re: how to customize the TM for my EJB3 app?
          mazz

          BTW: the reason why I want to customize this behavior is described here:

          http://management-platform.blogspot.com/2008/11/transaction-timeouts-and-ejb3jpa.html

          In short, I don't want my SLSB method to continue when the transaction timeout expires - I want the thread running that method to be interrupted so the SLSB method stops wasting time continuing processing the request when the transaction is just getting rolled back anyway.

          • 2. Re: how to customize the TM for my EJB3 app?
            mazz

            I'm thinking I might be able to inject an interceptor in my EJB3 interceptor chain - write my own annotation like @InterruptOnTimeout - and when the method is called, the interceptor looks for the existance of this annotation on the method and if it finds it, it grabs the transaction and adds my own checked action to it (I am assuming the interceptor has the ability to call some APIs to do this).

            • 3. Re: how to customize the TM for my EJB3 app?
              mazz

              OK, I'll ask this in a different way...

              If I write my own EJB3 interceptor (using @AroundInvoke and defined with <interceptor-binding>), how can I get the transaction that is associated with the active thread that is executing the request?

              If I can get the transaction that the EJB3 invocation is running in , I think I can do what I want from there, but I have to be able to get the underlying Arjuna/JBossTM transaction object for this to work.

              • 4. Re: how to customize the TM for my EJB3 app?
                alrubinger

                If you get the TransactionManager from JNDI, then get the Thread's current Tx from there, that's not sufficient for you? It's some wrapper object and you need an underlying impl (much like EntityManager.getDelegate() provides)?

                S,
                ALR

                • 5. Re: how to customize the TM for my EJB3 app?
                  mazz

                  Ah...good suggestion. I just tried that (looked up the java:/TransactionManager from JNDI and executed the getTransaction() method from the object that lookup returned.

                  And, it turns out, it looks like I don't even have to do that much. I found that rather than going through JNDI, I can simply do this:

                  com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.getTransaction()


                  Turn out that static method call returns the exact same reference as would the call to getTransaction from the TransactionManager I looked up in JNDI.

                  Unfortunately, this doesn't get me what I want. I'm going to return this thread over to the JBossTM forum because this is no longer an EJB3 question - I see no way of me adding my own CheckedAction to the transaction through this API. I need a JBossTM API to do this.

                  But, if I DID have a JBossTM API to add my own CheckedAction, it would have been easy from the EJB3 standpoint:

                  <interceptor-binding>
                   <ejb-name>*</ejb-name>
                   <interceptor-class>org.abc.TransactionInterruptInterceptor</interceptor-class>
                  </interceptor-binding>


                  and my interceptor would install its CheckedAction in the JBossTM transaction where the CheckedAction would be something like:

                  public class TransactionInterruptCheckedAction extends CheckedAction {
                   @Override
                   public synchronized void check(boolean isCommit, Uid actUid, Hashtable list) {
                   for (...each thread in the list...) {
                   thread_from_list.interrupt();
                   }
                   super.check(isCommit, actUid, list);
                   }
                  }



                  • 6. Re: how to customize the TM for my EJB3 app?
                    mazz

                    For those interested, turns out, there is a very easy JBossTM API that I can use in my interceptor code to do what I want... this static method:

                    com.arjuna.ats.arjuna.coordinator.BasicAction.Current.setCheckedAction()


                    Mark Little already gave me the answer in that other thread, I just didn't understand at first what he was suggesting.