/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.test.aop.bean;

import org.jboss.aspects.tx.Tx;
import org.jboss.aspects.txlock.TxSynchronized;
import org.jboss.aspects.tx.TxType;

/**
 * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
 * @version $Revision$
 */
public class AnnotatedTxLockedPOJO
{

   public AnnotatedTxLockedPOJO()
   {
      field = 0;
   }

   private int field;

   public int getField() { return field; }

   @Tx (TxType.REQUIRED)
   @TxSynchronized
   public void setField(int val)
   { 
      if (val == 6 && field == 0)
      {
         throw new RuntimeException("TxLock didn't work.  2nd thread got there first.");
      }
      if (val == 5)
      {
         // Sleep to test the lock
         try { Thread.sleep(5000); } catch (Exception ignored) { }
      }
      field = val;
   }

}

