FileDocCategorySizeDatePackage
MutexedMethodAspect.javaAPI DocJBoss 4.2.12702Fri Jul 13 21:02:36 BST 2007org.jboss.aspects.concurrent

MutexedMethodAspect

public class MutexedMethodAspect extends Object
comment
author
Bill Burke

Fields Summary
protected ReentrantLock
lock
protected MutexedMethod
props
Constructors Summary
public MutexedMethodAspect(MutexedMethod m)

      props = m;
      lock = new ReentrantLock(m.isFair());
   
Methods Summary
public java.lang.Objectacquire(org.jboss.aop.joinpoint.Invocation invocation)

      if (props.timeout() == -1)
      {
            blockIndefinately();
      }
      else if (props.timeout() == 0)
      {
         tryLock();
      }
      else
      {
         tryLockWithTimeout();
      }

      try
      {
         return invocation.invokeNext();
      }
      finally
      {
         lock.unlock();
      }
   
protected voidblockIndefinately()

      try
      {
         lock.lockInterruptibly();
      }
      catch (InterruptedException e)
      {
         throw new LockAcquisitionFailureException("Failed to lock @MutexedMethod", e);
      }
   
protected voidtryLock()

      if (!lock.tryLock())
      {
         throw new LockAcquisitionFailureException("Failed to lock @MutexedMethod");
      }
   
protected voidtryLockWithTimeout()

      try
      {
         if (!lock.tryLock(props.timeout(), props.unit()))
         {
            throw new LockAcquisitionFailureException("Failed to lock @MutexedMethod.  Timeout reached.");
         }
      }
      catch (InterruptedException e)
      {
         throw new LockAcquisitionFailureException("Failed to lock @MutexedMethod", e);
      }