Hi Bill,

I'm glad you like the idea. It's very attractive for me to get code integrated
the right way, which I cannot do on my own (at least not on the first try).

Bill Burke wrote:
> Great fucking idea!  I shoulda thought of that.
> 
> 
>>-----Original Message-----
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED]]On Behalf Of
>>Michael Bartmann
>>Sent: Wednesday, September 11, 2002 4:07 PM
>>To: [EMAIL PROTECTED]
>>Subject: [JBoss-dev] Deadlock retry interceptor
>>
>>
>>Hi deadlock lovers,
>>
>>I just did a deadlock-retry-interceptor, which was more easy than
>>I thought.
>>There is a serverside variant and a client interceptor.
>>
> 
> 
> I don't think you need a client interceptor.  Only serverside.  The reason?
> You need to do the retry outside the transaction.  The transaction must be
> able to rollback before you can retry it.
> 

You are right, if the thing lives inside the TxInterceptor you don't need
it on the client side.
But i did not dare to touch that, and the client side is the best guess to
be outside of the tx to retry.

> 
>>The interesting (i.e. non-perfect) points are:
>>
>>- how to configure retry strategy (quite simple now)
>>- where to place the serverside thing in the chain (should be _outside_
>>   of the transaction which just rolled back due to the deadlock; this
>>   probably implies that it could have to be done inside the TxInterceptor
>>   when entering a new tx.
>>   When _not_ doing "RequiresNew" the interceptor works fine between the
>>   SecutiyInterceptor and the TxInterceptor (I tried this with SLSB).
> 
> 
> You can only do a retry if the Beans starts a transaction.  Required(if tx
> started) or RequiresNew.  I think this stuff should be in the TxInterceptor,
> and maybe only the Container Managed one.
>
> 
>>- what to do with MDB (they are supposed to catch everything, so nothing
>>   gets through to the interceptor. My best guess is to use a
>>UserTX inside
>>   the MDB, do the retry "manually" (w/o interceptor) and put all this in
>>   an AbstractDeadlockRetryMDB (I did this, it worked fine).
>>
> 
> 
> Can't you put it in the TxInterceptor for MDB?
>

I think you probably can. In my case there were some interactions with the
XAQueueSession. I didn't want to roll back the message consumption, which
was enlisted in the same context.
But this might be due to the fact that I used my own JMS Provider for which
I did a JBoss integration. The exact semantics of JBossMQ XARessource may vary...

> 
>>Is there any interest to put this into Branch_3_2?
>>
> 
> 
> Send it to me.  I'll get it in.  Its definately worth it.

I've attached everything. It's quite simple.

> 
> Bill
> 
> 
> 

Michael
/* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ejb.plugins; import java.rmi.*; import javax.ejb.*; import org.jboss.ejb.*; import org.jboss.ejb.plugins.lock.*; import org.jboss.invocation.*; import org.jboss.logging.*; /** * This interceptor retries when hitting an ApplicationDeadlockException. * * @author Michael Bartmann * @version $Revision:$ */ public class ADERetryInterceptor extends AbstractInterceptor { private static Logger log = Logger.getLogger(ADERetryInterceptor.class); // we could replace this with a more sophisticated strategy... private long retryMillis[] = new long[]{0,0,1,1,10,10,100,100,1000,1000,3000,3000,3000,3000,3000,3000}; /** * Detects if a Throwable is or contains an ApplicationDeadlockException. * The basic pattern is borrowed from the JBoss documentation and extended * to support TransactionRolledbackLocalException. * @param t the Throwable to test * @return true if the argument is or contains an ApplicationDeadlockException */ public static boolean isOrContainsADE(Throwable t) { while (t!=null) { if (t instanceof ApplicationDeadlockException) { return true; } else if (t instanceof RemoteException) { t = ((RemoteException)t).detail; } else if (t instanceof TransactionRolledbackLocalException) { t = ((TransactionRolledbackLocalException)t).getCausedByException(); } else { return false; } } return false; } private Container container; public void setContainer(Container container) { this.container = container; } public Container getContainer() { return container; } public Object invoke(Invocation invocation) throws Exception { int count = 0; do { try { return getNext().invoke(invocation); } catch (Exception ex) { if ((isOrContainsADE(ex))&&(countMichael Bartmann * @version $Revision:$ */ public class ADERetryClientInterceptor extends Interceptor { private static Logger log = Logger.getLogger(ADERetryClientInterceptor.class); // we could replace this with a more sophisticated strategy... private long retryMillis[] = new long[]{0,0,1,1,10,10,100,100,1000,1000,3000,3000,3000,3000,3000,3000}; /** * Detects if a Throwable is or contains an ApplicationDeadlockException. * The basic pattern is borrowed from the JBoss documentation and extended * to support TransactionRolledbackLocalException. * @param t the Throwable to test * @return true if the argument is or contains an ApplicationDeadlockException */ public static boolean isOrContainsADE(Throwable t) { while (t!=null) { if (t instanceof ApplicationDeadlockException) { return true; } else if (t instanceof RemoteException) { t = ((RemoteException)t).detail; } else if (t instanceof TransactionRolledbackLocalException) { t = ((TransactionRolledbackLocalException)t).getCausedByException(); } else { return false; } } return false; } public Object invoke(Invocation invocation) throws Throwable { int count = 0; do { try { return getNext().invoke(invocation); } catch (Exception ex) { if ((isOrContainsADE(ex))&&(count

Reply via email to